userver: utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > Class Template Reference
Loading...
Searching...
No Matches
utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > Class Template Referencefinal

Class stores M buckets of type Counter and allows easy calculation of percentiles. More...

#include <userver/utils/statistics/percentile.hpp>

Public Member Functions

 Percentile (const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &other) noexcept
 
Percentileoperator= (const Percentile &rhs) noexcept
 
void Account (size_t value)
 Account for another value. Value is truncated [0..M) and added to the corresponding bucket.
 
size_t GetPercentile (double percent) const
 Get X percentile - min value P in [0..M) so that total number of elements in buckets 0..P 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 ()
 
Counter Count () const
 Total number of elements.
 

Detailed Description

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
class utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >

Class stores M buckets of type Counter and allows easy calculation of percentiles.

Bucket X stores how many elements with value X was accounted for, for the first M buckets. Bucket X stores how many elements with values [X-ExtraBucketSize/2; X+ExtraBucketSize/2) were accounted for, for the next ExtraBuckets buckets.

Template Parameters
Mhow many buckets store precise value
Counterbucket type
ExtraBucketshow many buckets store approximated values
ExtraBucketSizeExtraBuckets store values with this precision
See also
GetPercentile
Account

Example: Precisely count for first 500 milliseconds of execution using uint32_t counters and leave 100 buckets for all the other values with precision of 42 milliseconds:

using Percentile =
void Account(Percentile& perc, std::chrono::milliseconds ms) {
perc.Account(ms.count());
}
formats::json::Value ExtendStatistics(
stats_builder["timings"]["1min"] = PercentileToJson(perc).ExtractValue();
return stats_builder.ExtractValue();
}

Definition at line 56 of file percentile.hpp.

Constructor & Destructor Documentation

◆ Percentile() [1/2]

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::Percentile ( )
inline

Definition at line 58 of file percentile.hpp.

◆ Percentile() [2/2]

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::Percentile ( const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &  other)
inlinenoexcept

Definition at line 64 of file percentile.hpp.

Member Function Documentation

◆ Account()

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
void utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::Account ( size_t  value)
inline

Account for another value. Value is truncated [0..M) and added to the corresponding bucket.

Definition at line 91 of file percentile.hpp.

◆ Add()

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
template<class Duration = std::chrono::seconds>
void utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::Add ( const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &  other,
Duration  this_epoch_duration = Duration(),
Duration  before_this_epoch_duration = Duration() 
)
inline

Definition at line 141 of file percentile.hpp.

◆ Count()

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
Counter utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::Count ( ) const
inline

Total number of elements.

Definition at line 167 of file percentile.hpp.

◆ GetPercentile()

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
size_t utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::GetPercentile ( double  percent) const
inline

Get X percentile - min value P in [0..M) so that total number of elements in buckets 0..P is no less than X percent.

Parameters
percent- value in [0..100] - requested percentile if outside of 100, then returns last bucket that has any element in it.

Definition at line 115 of file percentile.hpp.

◆ operator=()

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
Percentile & utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::operator= ( const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &  rhs)
inlinenoexcept

Definition at line 69 of file percentile.hpp.

◆ Reset()

template<size_t M, typename Counter = uint32_t, size_t ExtraBuckets = 0, size_t ExtraBucketSize = 500>
void utils::statistics::Percentile< M, Counter, ExtraBuckets, ExtraBucketSize >::Reset ( )
inline

Definition at line 159 of file percentile.hpp.


The documentation for this class was generated from the following file: