Skip to content

Commit 743722d

Browse files
authored
Merge pull request #81 from parsifal-47/master
No need to traverse twice
2 parents 0662643 + ba5dbcf commit 743722d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/histogram.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ io::prometheus::client::Metric Histogram::Collect() {
2626
auto metric = io::prometheus::client::Metric{};
2727
auto histogram = metric.mutable_histogram();
2828

29-
auto sample_count = std::accumulate(
30-
bucket_counts_.begin(), bucket_counts_.end(), double{0},
31-
[](double sum, const Counter& counter) { return sum + counter.Value(); });
32-
histogram->set_sample_count(sample_count);
33-
histogram->set_sample_sum(sum_.Value());
34-
3529
auto cumulative_count = 0ULL;
3630
for (std::size_t i = 0; i < bucket_counts_.size(); i++) {
3731
cumulative_count += bucket_counts_[i].Value();
@@ -41,7 +35,9 @@ io::prometheus::client::Metric Histogram::Collect() {
4135
? std::numeric_limits<double>::infinity()
4236
: bucket_boundaries_[i]);
4337
}
38+
histogram->set_sample_count(cumulative_count);
39+
histogram->set_sample_sum(sum_.Value());
40+
4441
return metric;
4542
}
4643
}
47-

0 commit comments

Comments
 (0)