Skip to content

Commit c34ff41

Browse files
author
ignatloskutov
committed
Store 64-bit counters for histogram buckets
* Changelog entry Type: fix Component: misc-server Store 64-bit counters for histogram buckets commit_hash:b183820320312db88fe17ebfb63310d69c0ef767
1 parent 1c323ac commit c34ff41

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

yt/yt/library/profiling/histogram_snapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace NYT::NProfiling {
1111
struct THistogramSnapshot
1212
{
1313
// When Values.size() == Bounds.size() + 1, Values.back() stores "Inf" bucket.
14-
std::vector<int> Values;
14+
std::vector<i64> Values;
1515
std::vector<double> Bounds;
1616

1717
THistogramSnapshot& operator += (const THistogramSnapshot& other);

yt/yt/library/profiling/solomon/cube.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ int TCube<T>::ReadSensors(
514514
}
515515

516516
for (size_t i = 0; i < n; ++i) {
517-
int bucketValue = i < value.Values.size() ? value.Values[i] : 0u;
517+
auto bucketValue = i < value.Values.size() ? value.Values[i] : 0u;
518518

519519
(*hist)[i] = {value.Bounds[i], bucketValue / options.RateDenominator};
520520
}
@@ -525,7 +525,7 @@ int TCube<T>::ReadSensors(
525525
auto rollup = Rollup(*window, indices.back());
526526

527527
for (size_t i = 0; i < n; ++i) {
528-
int bucketValue = i < rollup.Values.size() ? rollup.Values[i] : 0u;
528+
auto bucketValue = i < rollup.Values.size() ? rollup.Values[i] : 0u;
529529
(*hist)[i] = {rollup.Bounds[i], bucketValue};
530530
}
531531

@@ -549,7 +549,7 @@ int TCube<T>::ReadSensors(
549549
auto hist = NMonitoring::TExplicitHistogramSnapshot::New(n + 1);
550550

551551
for (size_t i = 0; i < n; ++i) {
552-
int bucketValue = i < value.Values.size() ? value.Values[i] : 0u;
552+
auto bucketValue = i < value.Values.size() ? value.Values[i] : 0u;
553553
(*hist)[i] = {value.Bounds[i], bucketValue};
554554
}
555555

@@ -576,7 +576,7 @@ int TCube<T>::ReadSensors(
576576
}
577577

578578
for (size_t i = 0; i < n; ++i) {
579-
int bucketValue = i < value.Values.size() ? value.Values[i] : 0u;
579+
auto bucketValue = i < value.Values.size() ? value.Values[i] : 0u;
580580
(*hist)[i] = {value.Bounds[i], bucketValue / options.RateDenominator};
581581
}
582582

@@ -669,11 +669,11 @@ int TCube<T>::ReadSensorValues(
669669
}
670670
++valuesRead;
671671
} else if constexpr (std::is_same_v<T, TTimeHistogramSnapshot> || std::is_same_v<T, TGaugeHistogramSnapshot> || std::is_same_v<T, TRateHistogramSnapshot>) {
672-
std::vector<std::pair<double, int>> hist;
672+
std::vector<std::pair<double, i64>> hist;
673673
size_t n = value.Bounds.size();
674674
hist.reserve(n + 1);
675675
for (size_t i = 0; i != n; ++i) {
676-
int bucketValue = i < value.Values.size() ? value.Values[i] : 0;
676+
auto bucketValue = i < value.Values.size() ? value.Values[i] : 0;
677677
hist.emplace_back(value.Bounds[i], bucketValue);
678678
}
679679
hist.emplace_back(Max<double>(), n < value.Values.size() ? value.Values[n] : 0u);

yt/yt/library/profiling/solomon/sensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class THistogram
121121

122122
private:
123123
std::vector<double> Bounds_;
124-
std::vector<std::atomic<int>> Buckets_;
124+
std::vector<std::atomic<i64>> Buckets_;
125125

126126
// These two methods are not used.
127127
TSummarySnapshot<TDuration> GetSummary() override;

yt/yt/library/profiling/unittests/solomon_ut.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,22 @@ TEST(TSolomonRegistry, SparseHistogram)
371371
CollectSensors(impl, 3);
372372
}
373373

374+
TEST(TSolomonRegistry, HistogramWithBigCounterValues)
375+
{
376+
auto impl = New<TSolomonRegistry>();
377+
TProfiler profiler(impl, "/d");
378+
379+
auto h0 = profiler.GaugeHistogram("/histogram", {1.0});
380+
381+
h0.Add(0, 2e9);
382+
h0.Add(0, 2e9);
383+
384+
auto result = h0.GetSnapshot().Values;
385+
386+
ASSERT_FALSE(result.empty());
387+
ASSERT_EQ(result.front(), 4e9);
388+
}
389+
374390
TEST(TSolomonRegistry, SparseCounters)
375391
{
376392
auto impl = New<TSolomonRegistry>();

0 commit comments

Comments
 (0)