aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib
diff options
context:
space:
mode:
authorVladislav Kuznetsov <va.kuznecov@physics.msu.ru>2022-02-10 16:46:54 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:54 +0300
commit3cbae1ba94bff7a82ee848c3e9b2cebd96a69dd5 (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/monlib
parentde20f5598f0832a6e646f61b4feca942c00da928 (diff)
downloadydb-3cbae1ba94bff7a82ee848c3e9b2cebd96a69dd5.tar.gz
Restoring authorship annotation for Vladislav Kuznetsov <va.kuznecov@physics.msu.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib')
-rw-r--r--library/cpp/monlib/dynamic_counters/percentile/percentile.h4
-rw-r--r--library/cpp/monlib/dynamic_counters/percentile/percentile_base.h58
-rw-r--r--library/cpp/monlib/dynamic_counters/percentile/percentile_lg.h20
-rw-r--r--library/cpp/monlib/dynamic_counters/percentile/percentile_ut.cpp104
4 files changed, 93 insertions, 93 deletions
diff --git a/library/cpp/monlib/dynamic_counters/percentile/percentile.h b/library/cpp/monlib/dynamic_counters/percentile/percentile.h
index cbe3c7a87d..73c482bce9 100644
--- a/library/cpp/monlib/dynamic_counters/percentile/percentile.h
+++ b/library/cpp/monlib/dynamic_counters/percentile/percentile.h
@@ -1,6 +1,6 @@
#pragma once
-#include "percentile_base.h"
+#include "percentile_base.h"
namespace NMonitoring {
@@ -9,7 +9,7 @@ namespace NMonitoring {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <size_t BUCKET_SIZE, size_t BUCKET_COUNT, size_t FRAME_COUNT>
-struct TPercentileTracker : public TPercentileBase {
+struct TPercentileTracker : public TPercentileBase {
TAtomic Items[BUCKET_COUNT];
TAtomicBase Frame[FRAME_COUNT][BUCKET_COUNT];
size_t CurrentFrame;
diff --git a/library/cpp/monlib/dynamic_counters/percentile/percentile_base.h b/library/cpp/monlib/dynamic_counters/percentile/percentile_base.h
index e8b1a40899..d3c825c43d 100644
--- a/library/cpp/monlib/dynamic_counters/percentile/percentile_base.h
+++ b/library/cpp/monlib/dynamic_counters/percentile/percentile_base.h
@@ -1,36 +1,36 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/monlib/dynamic_counters/counters.h>
-
-#include <util/string/printf.h>
-
-namespace NMonitoring {
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Percentile tracker for monitoring
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-struct TPercentileBase : public TThrRefBase {
- using TPercentile = std::pair<float, NMonitoring::TDynamicCounters::TCounterPtr>;
- using TPercentiles = TVector<TPercentile>;
-
- TPercentiles Percentiles;
-
+
+#include <util/string/printf.h>
+
+namespace NMonitoring {
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Percentile tracker for monitoring
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+struct TPercentileBase : public TThrRefBase {
+ using TPercentile = std::pair<float, NMonitoring::TDynamicCounters::TCounterPtr>;
+ using TPercentiles = TVector<TPercentile>;
+
+ TPercentiles Percentiles;
+
void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, const TVector<float> &thresholds,
TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public) {
- Percentiles.reserve(thresholds.size());
- for (size_t i = 0; i < thresholds.size(); ++i) {
- Percentiles.emplace_back(thresholds[i],
+ Percentiles.reserve(thresholds.size());
+ for (size_t i = 0; i < thresholds.size(); ++i) {
+ Percentiles.emplace_back(thresholds[i],
counters->GetNamedCounter("percentile", Sprintf("%.1f", thresholds[i] * 100.f), false, visibility));
- }
- }
-
- void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, TString group, TString subgroup,
+ }
+ }
+
+ void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, TString group, TString subgroup,
TString name, const TVector<float> &thresholds,
TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public) {
- auto subCounters = counters->GetSubgroup(group, subgroup)->GetSubgroup("sensor", name);
+ auto subCounters = counters->GetSubgroup(group, subgroup)->GetSubgroup("sensor", name);
Initialize(subCounters, thresholds, visibility);
- }
-};
-
-} // NMonitoring
+ }
+};
+
+} // NMonitoring
diff --git a/library/cpp/monlib/dynamic_counters/percentile/percentile_lg.h b/library/cpp/monlib/dynamic_counters/percentile/percentile_lg.h
index 9f862d959f..0042cd9a6a 100644
--- a/library/cpp/monlib/dynamic_counters/percentile/percentile_lg.h
+++ b/library/cpp/monlib/dynamic_counters/percentile/percentile_lg.h
@@ -6,8 +6,8 @@
#include <cmath>
-#include "percentile_base.h"
-
+#include "percentile_base.h"
+
namespace NMonitoring {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -15,14 +15,14 @@ namespace NMonitoring {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <size_t BASE_BITS, size_t EXP_BITS, size_t FRAME_COUNT>
-struct TPercentileTrackerLg : public TPercentileBase {
- static constexpr size_t BUCKET_COUNT = size_t(1) << EXP_BITS;
- static constexpr size_t BUCKET_SIZE = size_t(1) << BASE_BITS;
+struct TPercentileTrackerLg : public TPercentileBase {
+ static constexpr size_t BUCKET_COUNT = size_t(1) << EXP_BITS;
+ static constexpr size_t BUCKET_SIZE = size_t(1) << BASE_BITS;
static constexpr size_t ITEMS_COUNT = BUCKET_COUNT * BUCKET_SIZE;
- static constexpr size_t TRACKER_LIMIT = BUCKET_SIZE * ((size_t(1) << BUCKET_COUNT) - 1)
- - (size_t(1) << (BUCKET_COUNT - 1));
- static constexpr size_t MAX_GRANULARITY = size_t(1) << (BUCKET_COUNT - 1);
-
+ static constexpr size_t TRACKER_LIMIT = BUCKET_SIZE * ((size_t(1) << BUCKET_COUNT) - 1)
+ - (size_t(1) << (BUCKET_COUNT - 1));
+ static constexpr size_t MAX_GRANULARITY = size_t(1) << (BUCKET_COUNT - 1);
+
size_t Borders[BUCKET_COUNT];
TAtomic Items[ITEMS_COUNT];
TAtomicBase Frame[FRAME_COUNT][ITEMS_COUNT];
@@ -132,7 +132,7 @@ struct TPercentileTrackerLg : public TPercentileBase {
}
void Increment(size_t value) {
- size_t bucket_idx = BucketIdxMostSignificantBit(value);
+ size_t bucket_idx = BucketIdxMostSignificantBit(value);
size_t inside_bucket_idx = (value - Borders[bucket_idx] + (1 << bucket_idx) - 1) >> bucket_idx;
size_t idx = bucket_idx * BUCKET_SIZE + inside_bucket_idx;
AtomicIncrement(Items[Min(idx, ITEMS_COUNT - 1)]);
diff --git a/library/cpp/monlib/dynamic_counters/percentile/percentile_ut.cpp b/library/cpp/monlib/dynamic_counters/percentile/percentile_ut.cpp
index b30cf36328..6c8bb54ec9 100644
--- a/library/cpp/monlib/dynamic_counters/percentile/percentile_ut.cpp
+++ b/library/cpp/monlib/dynamic_counters/percentile/percentile_ut.cpp
@@ -5,58 +5,58 @@ using namespace NMonitoring;
Y_UNIT_TEST_SUITE(PercentileTest) {
-template<size_t A, size_t B, size_t B_BEGIN>
-void printSizeAndLimit() {
- using TPerc = TPercentileTrackerLg<A, B, 15>;
- Cout << "TPercentileTrackerLg<" << A << ", " << B << ", 15>"
- << "; sizeof# " << LeftPad(HumanReadableSize(sizeof(TPerc), SF_BYTES), 7)
- << "; max_granularity# " << LeftPad(HumanReadableSize(TPerc::MAX_GRANULARITY, SF_QUANTITY), 5)
- << "; limit# " << LeftPad(HumanReadableSize(TPerc::TRACKER_LIMIT , SF_QUANTITY), 5) << Endl;
- if constexpr (B > 1) {
- printSizeAndLimit<A, B - 1, B_BEGIN>();
- } else if constexpr (A > 1) {
- Cout << Endl;
- printSizeAndLimit<A - 1, B_BEGIN, B_BEGIN>();
- }
-}
-
- Y_UNIT_TEST(PrintTrackerLgSizeAndLimits) {
- printSizeAndLimit<10, 5, 5>();
- }
-
- Y_UNIT_TEST(TrackerLimitTest) {
- {
- using TPerc = TPercentileTrackerLg<1, 0, 1>;
- TPerc tracker;
- tracker.Increment(Max<size_t>());
- UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
- }
- {
- using TPerc = TPercentileTrackerLg<1, 1, 1>;
- TPerc tracker;
- tracker.Increment(Max<size_t>());
- UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
- }
- {
- using TPerc = TPercentileTrackerLg<1, 5, 1>;
- TPerc tracker;
- tracker.Increment(Max<size_t>());
- UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
- }
- {
- using TPerc = TPercentileTrackerLg<2, 1, 1>;
- TPerc tracker;
- tracker.Increment(Max<size_t>());
- UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
- }
- {
- using TPerc = TPercentileTrackerLg<5, 4, 1>;
- TPerc tracker;
- tracker.Increment(Max<size_t>());
- UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
- }
- }
-
+template<size_t A, size_t B, size_t B_BEGIN>
+void printSizeAndLimit() {
+ using TPerc = TPercentileTrackerLg<A, B, 15>;
+ Cout << "TPercentileTrackerLg<" << A << ", " << B << ", 15>"
+ << "; sizeof# " << LeftPad(HumanReadableSize(sizeof(TPerc), SF_BYTES), 7)
+ << "; max_granularity# " << LeftPad(HumanReadableSize(TPerc::MAX_GRANULARITY, SF_QUANTITY), 5)
+ << "; limit# " << LeftPad(HumanReadableSize(TPerc::TRACKER_LIMIT , SF_QUANTITY), 5) << Endl;
+ if constexpr (B > 1) {
+ printSizeAndLimit<A, B - 1, B_BEGIN>();
+ } else if constexpr (A > 1) {
+ Cout << Endl;
+ printSizeAndLimit<A - 1, B_BEGIN, B_BEGIN>();
+ }
+}
+
+ Y_UNIT_TEST(PrintTrackerLgSizeAndLimits) {
+ printSizeAndLimit<10, 5, 5>();
+ }
+
+ Y_UNIT_TEST(TrackerLimitTest) {
+ {
+ using TPerc = TPercentileTrackerLg<1, 0, 1>;
+ TPerc tracker;
+ tracker.Increment(Max<size_t>());
+ UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
+ }
+ {
+ using TPerc = TPercentileTrackerLg<1, 1, 1>;
+ TPerc tracker;
+ tracker.Increment(Max<size_t>());
+ UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
+ }
+ {
+ using TPerc = TPercentileTrackerLg<1, 5, 1>;
+ TPerc tracker;
+ tracker.Increment(Max<size_t>());
+ UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
+ }
+ {
+ using TPerc = TPercentileTrackerLg<2, 1, 1>;
+ TPerc tracker;
+ tracker.Increment(Max<size_t>());
+ UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
+ }
+ {
+ using TPerc = TPercentileTrackerLg<5, 4, 1>;
+ TPerc tracker;
+ tracker.Increment(Max<size_t>());
+ UNIT_ASSERT_EQUAL(TPerc::TRACKER_LIMIT, tracker.GetPercentile(1.0));
+ }
+ }
+
Y_UNIT_TEST(BucketIdxIfvsBucketIdxBinarySearch) {
for (size_t var = 0; var < 5; var++) {
if (var == 0) {