diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/monlib/metrics/log_histogram_snapshot.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/monlib/metrics/log_histogram_snapshot.h')
-rw-r--r-- | library/cpp/monlib/metrics/log_histogram_snapshot.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/library/cpp/monlib/metrics/log_histogram_snapshot.h b/library/cpp/monlib/metrics/log_histogram_snapshot.h new file mode 100644 index 0000000000..7673b43751 --- /dev/null +++ b/library/cpp/monlib/metrics/log_histogram_snapshot.h @@ -0,0 +1,71 @@ +#pragma once + +#include <util/generic/ptr.h> +#include <util/generic/vector.h> + +#include <cmath> + +namespace NMonitoring { + + constexpr ui32 LOG_HIST_MAX_BUCKETS = 100; + + class TLogHistogramSnapshot: public TAtomicRefCount<TLogHistogramSnapshot> { + public: + TLogHistogramSnapshot(double base, ui64 zerosCount, int startPower, TVector<double> buckets) + : Base_(base) + , ZerosCount_(zerosCount) + , StartPower_(startPower) + , Buckets_(std::move(buckets)) { + } + + /** + * @return buckets count. + */ + ui32 Count() const noexcept { + return Buckets_.size(); + } + + /** + * @return upper bound for the bucket with particular index. + */ + double UpperBound(int index) const noexcept { + return std::pow(Base_, StartPower_ + index); + } + + /** + * @return value stored in the bucket with particular index. + */ + double Bucket(ui32 index) const noexcept { + return Buckets_[index]; + } + + /** + * @return nonpositive values count + */ + ui64 ZerosCount() const noexcept { + return ZerosCount_; + } + + double Base() const noexcept { + return Base_; + } + + int StartPower() const noexcept { + return StartPower_; + } + + ui64 MemorySizeBytes() const noexcept { + return sizeof(*this) + Buckets_.capacity() * sizeof(double); + } + + private: + double Base_; + ui64 ZerosCount_; + int StartPower_; + TVector<double> Buckets_; + }; + + using TLogHistogramSnapshotPtr = TIntrusivePtr<TLogHistogramSnapshot>; +} + +std::ostream& operator<<(std::ostream& os, const NMonitoring::TLogHistogramSnapshot& hist); |