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

Unified Diff: base/metrics/sparse_histogram.cc

Issue 2867303004: [histogram] Make histograms more resistant to overflows. (Closed)
Patch Set: final final fix Created 3 years, 7 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
« no previous file with comments | « base/metrics/sparse_histogram.h ('k') | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/sparse_histogram.cc
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc
index 916dcd5739ef845e824102b8f648dd43c62aeed8..e9bacd1ab2af62c8a472a217aac56ca6fdf1470c 100644
--- a/base/metrics/sparse_histogram.cc
+++ b/base/metrics/sparse_histogram.cc
@@ -85,7 +85,7 @@ std::unique_ptr<HistogramBase> SparseHistogram::PersistentCreate(
SparseHistogram::~SparseHistogram() {}
uint64_t SparseHistogram::name_hash() const {
- return samples_->id();
+ return unlogged_samples_->id();
}
HistogramType SparseHistogram::GetHistogramType() const {
@@ -111,7 +111,7 @@ void SparseHistogram::AddCount(Sample value, int count) {
}
{
base::AutoLock auto_lock(lock_);
- samples_->Accumulate(value, count);
+ unlogged_samples_->Accumulate(value, count);
}
FindAndRunCallback(value);
@@ -121,7 +121,8 @@ std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const {
std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash()));
base::AutoLock auto_lock(lock_);
- snapshot->Add(*samples_);
+ snapshot->Add(*unlogged_samples_);
+ snapshot->Add(*logged_samples_);
return std::move(snapshot);
}
@@ -130,10 +131,9 @@ std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotDelta() {
std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash()));
base::AutoLock auto_lock(lock_);
- snapshot->Add(*samples_);
+ snapshot->Add(*unlogged_samples_);
- // Subtract what was previously logged and update that information.
- snapshot->Subtract(*logged_samples_);
+ unlogged_samples_->Subtract(*snapshot);
logged_samples_->Add(*snapshot);
return std::move(snapshot);
}
@@ -144,21 +144,19 @@ std::unique_ptr<HistogramSamples> SparseHistogram::SnapshotFinalDelta() const {
std::unique_ptr<SampleMap> snapshot(new SampleMap(name_hash()));
base::AutoLock auto_lock(lock_);
- snapshot->Add(*samples_);
+ snapshot->Add(*unlogged_samples_);
- // Subtract what was previously logged and then return.
- snapshot->Subtract(*logged_samples_);
return std::move(snapshot);
}
void SparseHistogram::AddSamples(const HistogramSamples& samples) {
base::AutoLock auto_lock(lock_);
- samples_->Add(samples);
+ unlogged_samples_->Add(samples);
}
bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) {
base::AutoLock auto_lock(lock_);
- return samples_->AddFromPickle(iter);
+ return unlogged_samples_->AddFromPickle(iter);
}
void SparseHistogram::WriteHTMLGraph(std::string* output) const {
@@ -177,8 +175,8 @@ bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const {
SparseHistogram::SparseHistogram(const std::string& name)
: HistogramBase(name),
- samples_(new SampleMap(HashMetricName(name))),
- logged_samples_(new SampleMap(samples_->id())) {}
+ unlogged_samples_(new SampleMap(HashMetricName(name))),
+ logged_samples_(new SampleMap(unlogged_samples_->id())) {}
SparseHistogram::SparseHistogram(PersistentHistogramAllocator* allocator,
const std::string& name,
@@ -195,10 +193,11 @@ SparseHistogram::SparseHistogram(PersistentHistogramAllocator* allocator,
// "active" samples use, for convenience purposes, an ID matching
// that of the histogram while the "logged" samples use that number
// plus 1.
- samples_(new PersistentSampleMap(HashMetricName(name), allocator, meta)),
- logged_samples_(
- new PersistentSampleMap(samples_->id() + 1, allocator, logged_meta)) {
-}
+ unlogged_samples_(
+ new PersistentSampleMap(HashMetricName(name), allocator, meta)),
+ logged_samples_(new PersistentSampleMap(unlogged_samples_->id() + 1,
+ allocator,
+ logged_meta)) {}
HistogramBase* SparseHistogram::DeserializeInfoImpl(PickleIterator* iter) {
std::string histogram_name;
« no previous file with comments | « base/metrics/sparse_histogram.h ('k') | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698