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

Unified Diff: base/metrics/sparse_histogram.cc

Issue 11022002: Add SampleMap and use it in SparseHistogram (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more comments. Lock SampleMap while snapshotting. Created 8 years, 2 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/sparse_histogram.cc
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc
index 05a68b53540a1f5daf23c62c8ac6b6faa94e4006..684d5dc746ea98c884b497b9462994d8d54f30b7 100644
--- a/base/metrics/sparse_histogram.cc
+++ b/base/metrics/sparse_histogram.cc
@@ -5,6 +5,7 @@
#include "base/metrics/sparse_histogram.h"
#include "base/metrics/statistics_recorder.h"
+#include "base/synchronization/lock.h"
using std::string;
@@ -22,13 +23,14 @@ HistogramBase* SparseHistogram::FactoryGet(const string& name,
SparseHistogram::~SparseHistogram() {}
void SparseHistogram::Add(Sample value) {
- base::AutoLock auto_lock(lock_);
- samples_[value]++;
+ samples_.Accumulate(value, 1);
}
-void SparseHistogram::SnapshotSample(std::map<Sample, Count>* samples) const {
- base::AutoLock auto_lock(lock_);
- *samples = samples_;
+scoped_ptr<SampleMap> SparseHistogram::SnapshotSamples() const {
+ base::AutoLock auto_lock(samples_.lock_);
+ scoped_ptr<SampleMap> snapshot(new SampleMap());
+ snapshot->Add(samples_);
jar (doing other things) 2012/10/02 17:41:11 Will this induce numerous locks? Note that we don
+ return snapshot.Pass();
}
void SparseHistogram::WriteHTMLGraph(string* output) const {

Powered by Google App Engine
This is Rietveld 408576698