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/histogram_snapshot.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/monlib/metrics/histogram_snapshot.cpp')
-rw-r--r-- | library/cpp/monlib/metrics/histogram_snapshot.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/library/cpp/monlib/metrics/histogram_snapshot.cpp b/library/cpp/monlib/metrics/histogram_snapshot.cpp new file mode 100644 index 0000000000..75b5811546 --- /dev/null +++ b/library/cpp/monlib/metrics/histogram_snapshot.cpp @@ -0,0 +1,63 @@ +#include "histogram_snapshot.h" + +#include <util/stream/output.h> + +#include <iostream> + + +namespace NMonitoring { + + IHistogramSnapshotPtr ExplicitHistogramSnapshot(TConstArrayRef<TBucketBound> bounds, TConstArrayRef<TBucketValue> values) { + Y_ENSURE(bounds.size() == values.size(), + "mismatched sizes: bounds(" << bounds.size() << + ") != buckets(" << values.size() << ')'); + + auto snapshot = TExplicitHistogramSnapshot::New(bounds.size()); + + for (size_t i = 0; i != bounds.size(); ++i) { + (*snapshot)[i].first = bounds[i]; + (*snapshot)[i].second = values[i]; + } + + return snapshot; + } + +} // namespace NMonitoring + +namespace { + +template <typename TStream> +auto& Output(TStream& os, const NMonitoring::IHistogramSnapshot& hist) { + os << TStringBuf("{"); + + ui32 i = 0; + ui32 count = hist.Count(); + + if (count > 0) { + for (; i < count - 1; ++i) { + os << hist.UpperBound(i) << TStringBuf(": ") << hist.Value(i); + os << TStringBuf(", "); + } + + if (hist.UpperBound(i) == Max<NMonitoring::TBucketBound>()) { + os << TStringBuf("inf: ") << hist.Value(i); + } else { + os << hist.UpperBound(i) << TStringBuf(": ") << hist.Value(i); + } + } + + os << TStringBuf("}"); + + return os; +} + +} // namespace + +std::ostream& operator<<(std::ostream& os, const NMonitoring::IHistogramSnapshot& hist) { + return Output(os, hist); +} + +template <> +void Out<NMonitoring::IHistogramSnapshot>(IOutputStream& os, const NMonitoring::IHistogramSnapshot& hist) { + Output(os, hist); +} |