Index: base/metrics/sparse_histogram.cc |
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc |
index 05a68b53540a1f5daf23c62c8ac6b6faa94e4006..bc1913f5ea586709a9e63a54109b4c821c3c9fdc 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 { |
+ scoped_ptr<SampleMap> snapshot(new SampleMap()); |
+ |
base::AutoLock auto_lock(lock_); |
- *samples = samples_; |
+ 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 |