Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Unified Diff: base/metrics/histogram.cc

Issue 1485763002: Merge multiple histogram snapshots into single one for reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: rebased Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram.cc
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index c33d2f03c05c769d0dd9bad12c85a26ce3550460..df1368e6b07db5b1a41560ce0171ce32a9846dc7 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -272,10 +272,11 @@ HistogramBase* Histogram::PersistentGet(const std::string& name,
Sample maximum,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
uint32_t counts_size,
HistogramSamples::Metadata* meta) {
- return new Histogram(name, minimum, maximum, ranges, counts, counts_size,
- meta);
+ return new Histogram(name, minimum, maximum, ranges, counts, logged,
+ counts_size, meta);
}
// Calculate what range of values are held in each bucket.
@@ -430,6 +431,21 @@ scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const {
return SnapshotSampleVector();
}
+scoped_ptr<HistogramSamples> Histogram::SnapshotDelta() {
+ scoped_ptr<HistogramSamples> snapshot = SnapshotSampleVector();
+ if (!logged_) {
+ // If nothing has been previously logged, save this one as logged and
Alexei Svitkine (slow) 2016/02/09 19:46:51 Nit: save this one as |logged_counts_| and
bcwhite 2016/02/11 16:42:38 Done.
+ // gather another snapshot to return.
+ logged_.swap(snapshot);
+ return SnapshotSampleVector();
+ }
+
+ // Subtract what was previously logged and update that information.
+ snapshot->Subtract(*logged_);
+ logged_->Add(*snapshot);
+ return snapshot;
+}
+
void Histogram::AddSamples(const HistogramSamples& samples) {
samples_->Add(samples);
}
@@ -477,6 +493,7 @@ Histogram::Histogram(const std::string& name,
Sample maximum,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
uint32_t counts_size,
HistogramSamples::Metadata* meta)
: HistogramBase(name),
@@ -486,6 +503,8 @@ Histogram::Histogram(const std::string& name,
if (ranges) {
samples_.reset(new SampleVector(HashMetricName(name),
counts, counts_size, meta, ranges));
+ logged_.reset(new SampleVector(samples_->id(),
+ logged, counts_size, meta, ranges));
}
}
@@ -776,9 +795,10 @@ HistogramBase* LinearHistogram::PersistentGet(
Sample maximum,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
uint32_t counts_size,
HistogramSamples::Metadata* meta) {
- return new LinearHistogram(name, minimum, maximum, ranges, counts,
+ return new LinearHistogram(name, minimum, maximum, ranges, counts, logged,
counts_size, meta);
}
@@ -813,6 +833,7 @@ LinearHistogram::LinearHistogram(const std::string& name,
Sample maximum,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
uint32_t counts_size,
HistogramSamples::Metadata* meta)
: Histogram(name,
@@ -820,6 +841,7 @@ LinearHistogram::LinearHistogram(const std::string& name,
maximum,
ranges,
counts,
+ logged,
counts_size,
meta) {}
@@ -919,8 +941,9 @@ HistogramBase* BooleanHistogram::PersistentGet(
const std::string& name,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
HistogramSamples::Metadata* meta) {
- return new BooleanHistogram(name, ranges, counts, meta);
+ return new BooleanHistogram(name, ranges, counts, logged, meta);
}
HistogramType BooleanHistogram::GetHistogramType() const {
@@ -934,8 +957,9 @@ BooleanHistogram::BooleanHistogram(const std::string& name,
BooleanHistogram::BooleanHistogram(const std::string& name,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
HistogramSamples::Metadata* meta)
- : LinearHistogram(name, 1, 2, ranges, counts, 2, meta) {}
+ : LinearHistogram(name, 1, 2, ranges, counts, logged, 2, meta) {}
HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) {
std::string histogram_name;
@@ -1019,9 +1043,10 @@ HistogramBase* CustomHistogram::PersistentGet(
const std::string& name,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
uint32_t counts_size,
HistogramSamples::Metadata* meta) {
- return new CustomHistogram(name, ranges, counts, counts_size, meta);
+ return new CustomHistogram(name, ranges, counts, logged, counts_size, meta);
}
HistogramType CustomHistogram::GetHistogramType() const {
@@ -1053,6 +1078,7 @@ CustomHistogram::CustomHistogram(const std::string& name,
CustomHistogram::CustomHistogram(const std::string& name,
const BucketRanges* ranges,
HistogramBase::AtomicCount* counts,
+ HistogramBase::AtomicCount* logged,
uint32_t counts_size,
HistogramSamples::Metadata* meta)
: Histogram(name,
@@ -1060,6 +1086,7 @@ CustomHistogram::CustomHistogram(const std::string& name,
ranges->range(ranges->bucket_count() - 1),
ranges,
counts,
+ logged,
counts_size,
meta) {}

Powered by Google App Engine
This is Rietveld 408576698