aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/dynamic_counters/percentile/percentile.h
diff options
context:
space:
mode:
authormsherbakov <msherbakov@yandex-team.ru>2022-02-10 16:49:16 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:16 +0300
commitc224a621661ddd69699f9476922eb316607ef57e (patch)
tree33f4d878aa0a9faa964005e06bfab0272313aa71 /library/cpp/monlib/dynamic_counters/percentile/percentile.h
parent29d0b2eeae154d04156e0698067c0c21a97ea61d (diff)
downloadydb-c224a621661ddd69699f9476922eb316607ef57e.tar.gz
Restoring authorship annotation for <msherbakov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/dynamic_counters/percentile/percentile.h')
-rw-r--r--library/cpp/monlib/dynamic_counters/percentile/percentile.h114
1 files changed, 57 insertions, 57 deletions
diff --git a/library/cpp/monlib/dynamic_counters/percentile/percentile.h b/library/cpp/monlib/dynamic_counters/percentile/percentile.h
index 73c482bce9..08b7ec5f0f 100644
--- a/library/cpp/monlib/dynamic_counters/percentile/percentile.h
+++ b/library/cpp/monlib/dynamic_counters/percentile/percentile.h
@@ -1,59 +1,59 @@
-#pragma once
-
+#pragma once
+
#include "percentile_base.h"
-
-namespace NMonitoring {
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Percentile tracker for monitoring
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-template <size_t BUCKET_SIZE, size_t BUCKET_COUNT, size_t FRAME_COUNT>
+
+namespace NMonitoring {
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Percentile tracker for monitoring
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+template <size_t BUCKET_SIZE, size_t BUCKET_COUNT, size_t FRAME_COUNT>
struct TPercentileTracker : public TPercentileBase {
- TAtomic Items[BUCKET_COUNT];
- TAtomicBase Frame[FRAME_COUNT][BUCKET_COUNT];
- size_t CurrentFrame;
-
- TPercentileTracker()
- : CurrentFrame(0)
- {
- for (size_t i = 0; i < BUCKET_COUNT; ++i) {
- AtomicSet(Items[i], 0);
- }
- for (size_t frame = 0; frame < FRAME_COUNT; ++frame) {
- for (size_t bucket = 0; bucket < BUCKET_COUNT; ++bucket) {
- Frame[frame][bucket] = 0;
- }
- }
- }
-
- void Increment(size_t value) {
- AtomicIncrement(Items[Min((value + BUCKET_SIZE - 1) / BUCKET_SIZE, BUCKET_COUNT - 1)]);
- }
-
- // shift frame (call periodically)
- void Update() {
- TVector<TAtomicBase> totals(BUCKET_COUNT);
- totals.resize(BUCKET_COUNT);
- TAtomicBase total = 0;
- for (size_t i = 0; i < BUCKET_COUNT; ++i) {
- TAtomicBase item = AtomicGet(Items[i]);
- TAtomicBase prevItem = Frame[CurrentFrame][i];
- Frame[CurrentFrame][i] = item;
- total += item - prevItem;
- totals[i] = total;
- }
-
- for (size_t i = 0; i < Percentiles.size(); ++i) {
- TPercentile &percentile = Percentiles[i];
- auto threshold = (TAtomicBase)(percentile.first * (float)total);
- threshold = Min(threshold, total);
- auto it = LowerBound(totals.begin(), totals.end(), threshold);
- size_t index = it - totals.begin();
- (*percentile.second) = index * BUCKET_SIZE;
- }
- CurrentFrame = (CurrentFrame + 1) % FRAME_COUNT;
- }
-};
-
-} // NMonitoring
+ TAtomic Items[BUCKET_COUNT];
+ TAtomicBase Frame[FRAME_COUNT][BUCKET_COUNT];
+ size_t CurrentFrame;
+
+ TPercentileTracker()
+ : CurrentFrame(0)
+ {
+ for (size_t i = 0; i < BUCKET_COUNT; ++i) {
+ AtomicSet(Items[i], 0);
+ }
+ for (size_t frame = 0; frame < FRAME_COUNT; ++frame) {
+ for (size_t bucket = 0; bucket < BUCKET_COUNT; ++bucket) {
+ Frame[frame][bucket] = 0;
+ }
+ }
+ }
+
+ void Increment(size_t value) {
+ AtomicIncrement(Items[Min((value + BUCKET_SIZE - 1) / BUCKET_SIZE, BUCKET_COUNT - 1)]);
+ }
+
+ // shift frame (call periodically)
+ void Update() {
+ TVector<TAtomicBase> totals(BUCKET_COUNT);
+ totals.resize(BUCKET_COUNT);
+ TAtomicBase total = 0;
+ for (size_t i = 0; i < BUCKET_COUNT; ++i) {
+ TAtomicBase item = AtomicGet(Items[i]);
+ TAtomicBase prevItem = Frame[CurrentFrame][i];
+ Frame[CurrentFrame][i] = item;
+ total += item - prevItem;
+ totals[i] = total;
+ }
+
+ for (size_t i = 0; i < Percentiles.size(); ++i) {
+ TPercentile &percentile = Percentiles[i];
+ auto threshold = (TAtomicBase)(percentile.first * (float)total);
+ threshold = Min(threshold, total);
+ auto it = LowerBound(totals.begin(), totals.end(), threshold);
+ size_t index = it - totals.begin();
+ (*percentile.second) = index * BUCKET_SIZE;
+ }
+ CurrentFrame = (CurrentFrame + 1) % FRAME_COUNT;
+ }
+};
+
+} // NMonitoring