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..c91cab8699e0f4260dd71edb75b33c26590f8b2e 100644 |
| --- a/base/metrics/sparse_histogram.cc |
| +++ b/base/metrics/sparse_histogram.cc |
| @@ -5,14 +5,18 @@ |
| #include "base/metrics/sparse_histogram.h" |
| #include "base/metrics/statistics_recorder.h" |
| +#include "base/synchronization/lock.h" |
| +using std::map; |
| using std::string; |
| namespace base { |
| +typedef HistogramBase::Count Count; |
| +typedef HistogramBase::Sample Sample; |
| + |
| // static |
| -HistogramBase* SparseHistogram::FactoryGet(const string& name, |
| - int32 flags) { |
| +HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { |
| // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. |
| HistogramBase* histogram = new SparseHistogram(name); |
| histogram->SetFlags(flags); |
| @@ -23,12 +27,21 @@ SparseHistogram::~SparseHistogram() {} |
| void SparseHistogram::Add(Sample value) { |
| base::AutoLock auto_lock(lock_); |
| - samples_[value]++; |
| + sample_counts_[value]++; |
| + redundant_count_ += 1; |
| } |
| -void SparseHistogram::SnapshotSample(std::map<Sample, Count>* samples) const { |
| +scoped_ptr<SampleMap> SparseHistogram::SnapshotSamples() const { |
| base::AutoLock auto_lock(lock_); |
| - *samples = samples_; |
| + scoped_ptr<SampleMap> snapshot(new SampleMap()); |
|
jar (doing other things)
2012/10/05 01:27:36
nit: always do as much as possible outside the loc
kaiwang
2012/10/05 03:16:17
Done.
|
| + |
| + for(map<Sample, Count>::const_iterator it = sample_counts_.begin(); |
| + it != sample_counts_.end(); |
| + ++it) { |
| + snapshot->Accumulate(it->first, it->second); |
| + } |
| + snapshot->ResetRedundantCount(redundant_count_); |
| + return snapshot.Pass(); |
| } |
| void SparseHistogram::WriteHTMLGraph(string* output) const { |
| @@ -40,6 +53,7 @@ void SparseHistogram::WriteAscii(string* output) const { |
| } |
| SparseHistogram::SparseHistogram(const string& name) |
| - : HistogramBase(name) {} |
| + : HistogramBase(name), |
| + redundant_count_(0) {} |
| } // namespace base |