Chromium Code Reviews| 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 { |