forked from halfgaar/FlashMQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriftcounter.h
27 lines (23 loc) · 833 Bytes
/
driftcounter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef DRIFTCOUNTER_H
#define DRIFTCOUNTER_H
#include <chrono>
#include <array>
/**
* @brief The DriftCounter class allows measuring drift in threads.
*
* There is no thread syncing / mutexes. Values can be retrieved from other threads, but some values may
* not be super accurate, which is fine.
*/
class DriftCounter
{
std::chrono::time_point<std::chrono::steady_clock> last_update = std::chrono::steady_clock::now();
std::chrono::milliseconds last_drift = std::chrono::milliseconds(0);
std::array<std::chrono::milliseconds, 16> many_drifts;
unsigned int many_index = 0;
public:
DriftCounter();
void update(std::chrono::time_point<std::chrono::steady_clock> call_time);
std::chrono::milliseconds getDrift() const;
std::chrono::milliseconds getAvgDrift() const;
};
#endif // DRIFTCOUNTER_H