#include <userver/utils/statistics/percentile.hpp>
Class allows easy calculation of percentiles.
Stores M + ExtraBuckets
buckets of type Counter
.
On Account(x)
the bucket to increment is chosen depending on x
value. If x
belongs to:
[0, M)
, then bucket from M
buckets;[M, M + ExtraBuckets * ExtraBucketSize)
, then bucket from ExtraBuckets
;ExtraBuckets
.On GetPercentile(percent)
class sums up the required amount of buckets, knowing the total count of Account(x)
invocations.
M | buckets count for value step of 1 |
Counter | type of all the buckets |
ExtraBuckets | buckets for value step of ExtraBucketSize |
ExtraBucketSize | ExtraBuckets store values with this precision |
Example: Precisely count for first 500 milliseconds of execution using std::uint32_t
counters and leave 100 buckets for all the other values with precision of 9 milliseconds:
Type is safe to read/write concurrently from different threads/coroutines.
Percentile
metrics are non-summable, e.g. given RPS counts and timing percentiles for multiple hosts or handlers, we cannot accurately compute the total timing percentiles.
Definition at line 69 of file percentile.hpp.
Public Member Functions | |
Percentile (const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &other) noexcept | |
Percentile & | operator= (const Percentile &rhs) noexcept |
void | Account (std::size_t value) noexcept |
Account for another value. | |
std::size_t | GetPercentile (double percent) const |
Get X percentile - min value P so that total number of elements in buckets is no less than X percent. | |
template<class Duration = std::chrono::seconds> | |
void | Add (const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &other, Duration this_epoch_duration=Duration(), Duration before_this_epoch_duration=Duration()) |
void | Reset () noexcept |
Zero out all the buckets and total number of elements. | |
Counter | Count () const noexcept |
Total number of elements. | |
|
inlinenoexcept |
Definition at line 71 of file percentile.hpp.
|
inlinenoexcept |
Definition at line 77 of file percentile.hpp.
|
inlinenoexcept |
Account for another value.
1
is added to the bucket corresponding to value
Definition at line 102 of file percentile.hpp.
|
inline |
Definition at line 150 of file percentile.hpp.
|
inlinenoexcept |
Total number of elements.
Definition at line 178 of file percentile.hpp.
|
inline |
Get X percentile - min value P so that total number of elements in buckets is no less than X percent.
percent | - value in [0..100] - requested percentile. If outside of 100, then returns last bucket that has any element in it. |
Definition at line 124 of file percentile.hpp.
|
inlinenoexcept |
Definition at line 79 of file percentile.hpp.
|
inlinenoexcept |
Zero out all the buckets and total number of elements.
Definition at line 171 of file percentile.hpp.