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

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 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
« 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 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
« 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