diff options
author | Sergey Polovko <sergey@polovko.me> | 2022-02-10 16:47:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:03 +0300 |
commit | 2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5 (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /library/cpp/monlib/metrics/histogram_collector_explicit.cpp | |
parent | 3e0b762a82514bac89c1dd6ea7211e381d8aa248 (diff) | |
download | ydb-2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5.tar.gz |
Restoring authorship annotation for Sergey Polovko <sergey@polovko.me>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/metrics/histogram_collector_explicit.cpp')
-rw-r--r-- | library/cpp/monlib/metrics/histogram_collector_explicit.cpp | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/library/cpp/monlib/metrics/histogram_collector_explicit.cpp b/library/cpp/monlib/metrics/histogram_collector_explicit.cpp index 90c41a235a..377fc233ef 100644 --- a/library/cpp/monlib/metrics/histogram_collector_explicit.cpp +++ b/library/cpp/monlib/metrics/histogram_collector_explicit.cpp @@ -1,55 +1,55 @@ -#include "histogram_collector.h" -#include "atomics_array.h" - -#include <util/generic/algorithm.h> -#include <util/generic/vector.h> -#include <util/generic/yexception.h> -#include <util/generic/ylimits.h> - -namespace NMonitoring { - - /////////////////////////////////////////////////////////////////////////// - // TExplicitHistogramCollector - /////////////////////////////////////////////////////////////////////////// - class TExplicitHistogramCollector: public IHistogramCollector { - public: +#include "histogram_collector.h" +#include "atomics_array.h" + +#include <util/generic/algorithm.h> +#include <util/generic/vector.h> +#include <util/generic/yexception.h> +#include <util/generic/ylimits.h> + +namespace NMonitoring { + + /////////////////////////////////////////////////////////////////////////// + // TExplicitHistogramCollector + /////////////////////////////////////////////////////////////////////////// + class TExplicitHistogramCollector: public IHistogramCollector { + public: TExplicitHistogramCollector(TBucketBounds bounds) : Values_(bounds.size() + 1) , Bounds_(std::move(bounds)) - { - // add one bucket as +INF - Bounds_.push_back(Max<TBucketBound>()); - } - + { + // add one bucket as +INF + Bounds_.push_back(Max<TBucketBound>()); + } + void Collect(double value, ui32 count) override { auto it = LowerBound(Bounds_.begin(), Bounds_.end(), value); - auto index = std::distance(Bounds_.begin(), it); - Values_.Add(index, count); - } - + auto index = std::distance(Bounds_.begin(), it); + Values_.Add(index, count); + } + void Reset() override { Values_.Reset(); } - IHistogramSnapshotPtr Snapshot() const override { + IHistogramSnapshotPtr Snapshot() const override { auto values = Values_.Copy(); return ExplicitHistogramSnapshot(Bounds_, values); - } - - private: + } + + private: TAtomicsArray Values_; - TBucketBounds Bounds_; - }; - - IHistogramCollectorPtr ExplicitHistogram(TBucketBounds bounds) { - Y_ENSURE(bounds.size() >= 1, - "explicit histogram must contain at least one bucket"); + TBucketBounds Bounds_; + }; + + IHistogramCollectorPtr ExplicitHistogram(TBucketBounds bounds) { + Y_ENSURE(bounds.size() >= 1, + "explicit histogram must contain at least one bucket"); Y_ENSURE(bounds.size() <= HISTOGRAM_MAX_BUCKETS_COUNT, "buckets count must be <=" << HISTOGRAM_MAX_BUCKETS_COUNT - << ", but got: " << bounds.size()); - Y_ENSURE(IsSorted(bounds.begin(), bounds.end()), - "bounds for explicit histogram must be sorted"); - + << ", but got: " << bounds.size()); + Y_ENSURE(IsSorted(bounds.begin(), bounds.end()), + "bounds for explicit histogram must be sorted"); + return MakeHolder<TExplicitHistogramCollector>(bounds); - } -} + } +} |