libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
histogram.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <cstdint>
14#include <promeki/namespace.h>
15#include <promeki/string.h>
16#include <promeki/duration.h>
17
18PROMEKI_NAMESPACE_BEGIN
19
78class Histogram {
79 public:
81 static constexpr size_t OctaveCount = 64;
83 static constexpr size_t SubBucketsPerOctave = 16;
85 static constexpr size_t BucketCount = OctaveCount * SubBucketsPerOctave;
86
88 Histogram();
89
94 void setName(const String &name);
95
97 const String &name() const { return _name; }
98
103 void setUnit(const String &unit);
104
106 const String &unit() const { return _unit; }
107
109 void reset();
110
120 void addSample(int64_t value);
121
126 void addSample(const Duration &d) { addSample(d.nanoseconds()); }
127
129 int64_t count() const { return _count; }
130
132 int64_t min() const { return _count > 0 ? _min : 0; }
133
135 int64_t max() const { return _count > 0 ? _max : 0; }
136
146 double mean() const;
147
160 int64_t percentile(double p) const;
161
170 String toString() const;
171
172 private:
173 String _name;
174 String _unit;
175 int64_t _count = 0;
176 int64_t _sum = 0;
177 int64_t _min = 0;
178 int64_t _max = 0;
179 int64_t _buckets[BucketCount] = {};
180};
181
182PROMEKI_NAMESPACE_END
183
184PROMEKI_FORMAT_VIA_TOSTRING(promeki::Histogram);
185
186#endif // PROMEKI_ENABLE_CORE