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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include "base/metrics/statistics_recorder.h" 7 #include "base/metrics/statistics_recorder.h"
8 8
9 using std::string; 9 using std::string;
10 10
11 namespace base { 11 namespace base {
12 12
13 // static 13 // static
14 HistogramBase* SparseHistogram::FactoryGet(const string& name, 14 HistogramBase* SparseHistogram::FactoryGet(const string& name,
15 int32 flags) { 15 int32 flags) {
16 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. 16 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder.
17 HistogramBase* histogram = new SparseHistogram(name); 17 HistogramBase* histogram = new SparseHistogram(name);
18 histogram->SetFlags(flags); 18 histogram->SetFlags(flags);
19 return histogram; 19 return histogram;
20 } 20 }
21 21
22 SparseHistogram::~SparseHistogram() {} 22 SparseHistogram::~SparseHistogram() {}
23 23
24 void SparseHistogram::Add(Sample value) { 24 void SparseHistogram::Add(Sample value) {
25 base::AutoLock auto_lock(lock_); 25 samples_.Accumulate(value, 1);
26 samples_[value]++;
27 } 26 }
28 27
29 void SparseHistogram::SnapshotSample(std::map<Sample, Count>* samples) const { 28 scoped_ptr<SampleMap> SparseHistogram::SnapshotSamples() const {
30 base::AutoLock auto_lock(lock_); 29 scoped_ptr<SampleMap> snapshot(new SampleMap());
31 *samples = samples_; 30 snapshot->Add(samples_);
31 return snapshot.Pass();
32 } 32 }
33 33
34 void SparseHistogram::WriteHTMLGraph(string* output) const { 34 void SparseHistogram::WriteHTMLGraph(string* output) const {
35 // TODO(kaiwang): Implement. 35 // TODO(kaiwang): Implement.
36 } 36 }
37 37
38 void SparseHistogram::WriteAscii(string* output) const { 38 void SparseHistogram::WriteAscii(string* output) const {
39 // TODO(kaiwang): Implement. 39 // TODO(kaiwang): Implement.
40 } 40 }
41 41
42 SparseHistogram::SparseHistogram(const string& name) 42 SparseHistogram::SparseHistogram(const string& name)
43 : HistogramBase(name) {} 43 : HistogramBase(name) {}
44 44
45 } // namespace base 45 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698