forked from Soreepeong/XivAlexander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericStatisticsTracker.h
47 lines (38 loc) · 1.41 KB
/
NumericStatisticsTracker.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <deque>
#include "XivAlexanderCommon/Utils/Utils.h"
namespace Utils {
class NumericStatisticsTracker {
const size_t m_trackCount;
const int64_t m_emptyValue;
const int64_t m_maxAgeUs;
struct Entry {
const int64_t Value;
const int64_t TimestampUs;
const int64_t ExpiryUs;
Entry(int64_t value, int64_t maxAgeUs);
};
mutable std::mutex m_mtx;
mutable std::deque<Entry> m_values;
public:
NumericStatisticsTracker(size_t trackCount, int64_t emptyValue, int64_t maxAgeUs = INT64_MAX);
~NumericStatisticsTracker();
void AddValue(int64_t);
void Clear() { m_values.clear(); };
bool Empty() const { return m_values.empty(); }
private:
[[nodiscard]] const std::deque<Entry>& RemoveExpired(int64_t nowUs = Utils::QpcUs()) const;
public:
[[nodiscard]] int64_t InvalidValue() const;
[[nodiscard]] int64_t Latest() const;
[[nodiscard]] int64_t Min(int64_t sinceUs = 0) const;
[[nodiscard]] int64_t Max(int64_t sinceUs = 0) const;
[[nodiscard]] int64_t Median(int64_t sinceUs = 0) const;
[[nodiscard]] std::pair<int64_t, int64_t> MeanAndDeviation(int64_t sinceUs = 0) const;
[[nodiscard]] int64_t Mean(int64_t sinceUs = 0) const;
[[nodiscard]] int64_t Deviation(int64_t sinceUs = 0) const;
[[nodiscard]] size_t Count(int64_t sinceUs = 0) const;
[[nodiscard]] int64_t NextBlankInUs() const;
[[nodiscard]] double CountFractional(int64_t sinceUs = 0) const;
};
}