roo_monitoring
API Documentation for roo_monitoring
Loading...
Searching...
No Matches
resolution.h
Go to the documentation of this file.
1#pragma once
2
3#include <inttypes.h>
4
5namespace roo_monitoring {
6
7/// Time resolution used for log and vault files.
9 kResolution_1_ms = 0, // 1 ms
10 kResolution_4_ms = 1, // 4 ms
11 kResolution_16_ms = 2, // 16 ms
12 kResolution_64_ms = 3, // 64 ms
13 kResolution_256_ms = 4, // 256 s
14 kResolution_1024_ms = 5, // ~ 1 s
15 kResolution_4096_ms = 6, // ~ 4 s
16 kResolution_16384_ms = 7, // ~ 16 s
17 kResolution_65536_ms = 8, // ~ 1.09 min
18 kResolution_262144_ms = 9, // ~ 4.37 min
19 kResolution_1048576_ms = 10, // ~ 17.47 min
20 kResolution_4194304_ms = 11, // ~ 70 min
21 kResolution_16777216_ms = 12, // ~ 4.66 h
22 kResolution_67108864_ms = 13, // ~ 18.64 h
23 kResolution_268435456_ms = 14, // ~ 3.1 days
24 kResolution_1073741824_ms = 15, // ~ 12.4 days
25 kResolution_4294967296_ms = 16, // ~ 49.7 days
26 kResolution_17179869184_ms = 17, // ~ 199 days
27 kResolution_68719476736_ms = 18, // ~ 2.18 years
28};
29
30/// Maximum supported resolution.
32
33/// Rounds the timestamp down to the specified resolution bucket.
34inline constexpr static int64_t timestamp_ms_floor(int64_t timestamp_ms,
35 Resolution resolution) {
36 // Resolution is the exponent with base 4, so we need to multiply
37 // by 2 when converting to base 2. Then, using shift to generate
38 // the required number of zeros in the mask.
39 return timestamp_ms & (0xFFFFFFFFFFFFFFFFLL << (resolution << 1));
40}
41
42/// Rounds the timestamp up to the specified resolution bucket.
43inline constexpr static int64_t timestamp_ms_ceil(int64_t timestamp_ms,
44 Resolution resolution) {
45 // Like the above, but mask is negated (so it has the requested count
46 // of trailing 1s) and ORed with the timestamp.
47 return timestamp_ms | ~(0xFFFFFFFFFFFFFFFFLL << (resolution << 1));
48}
49
50/// Returns the timestamp delta for the given number of resolution steps.
51inline constexpr static int64_t timestamp_increment(int64_t steps,
52 Resolution resolution) {
53 return steps << (resolution << 1);
54}
55
56} // namespace roo_monitoring
Umbrella header for the roo_monitoring module.
static constexpr int64_t timestamp_ms_floor(int64_t timestamp_ms, Resolution resolution)
Rounds the timestamp down to the specified resolution bucket.
Definition resolution.h:34
static const Resolution kMaxResolution
Maximum supported resolution.
Definition resolution.h:31
Resolution
Time resolution used for log and vault files.
Definition resolution.h:8
@ kResolution_68719476736_ms
Definition resolution.h:27
@ kResolution_1073741824_ms
Definition resolution.h:24
@ kResolution_4294967296_ms
Definition resolution.h:25
@ kResolution_17179869184_ms
Definition resolution.h:26
@ kResolution_268435456_ms
Definition resolution.h:23
@ kResolution_67108864_ms
Definition resolution.h:22
@ kResolution_16777216_ms
Definition resolution.h:21
static constexpr int64_t timestamp_increment(int64_t steps, Resolution resolution)
Returns the timestamp delta for the given number of resolution steps.
Definition resolution.h:51
static constexpr int64_t timestamp_ms_ceil(int64_t timestamp_ms, Resolution resolution)
Rounds the timestamp up to the specified resolution bucket.
Definition resolution.h:43