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

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 more comments. Lock SampleMap while snapshotting. 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 #include "base/synchronization/lock.h"
8 9
9 using std::string; 10 using std::string;
10 11
11 namespace base { 12 namespace base {
12 13
13 // static 14 // static
14 HistogramBase* SparseHistogram::FactoryGet(const string& name, 15 HistogramBase* SparseHistogram::FactoryGet(const string& name,
15 int32 flags) { 16 int32 flags) {
16 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. 17 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder.
17 HistogramBase* histogram = new SparseHistogram(name); 18 HistogramBase* histogram = new SparseHistogram(name);
18 histogram->SetFlags(flags); 19 histogram->SetFlags(flags);
19 return histogram; 20 return histogram;
20 } 21 }
21 22
22 SparseHistogram::~SparseHistogram() {} 23 SparseHistogram::~SparseHistogram() {}
23 24
24 void SparseHistogram::Add(Sample value) { 25 void SparseHistogram::Add(Sample value) {
25 base::AutoLock auto_lock(lock_); 26 samples_.Accumulate(value, 1);
26 samples_[value]++;
27 } 27 }
28 28
29 void SparseHistogram::SnapshotSample(std::map<Sample, Count>* samples) const { 29 scoped_ptr<SampleMap> SparseHistogram::SnapshotSamples() const {
30 base::AutoLock auto_lock(lock_); 30 base::AutoLock auto_lock(samples_.lock_);
31 *samples = samples_; 31 scoped_ptr<SampleMap> snapshot(new SampleMap());
32 snapshot->Add(samples_);
jar (doing other things) 2012/10/02 17:41:11 Will this induce numerous locks? Note that we don
33 return snapshot.Pass();
32 } 34 }
33 35
34 void SparseHistogram::WriteHTMLGraph(string* output) const { 36 void SparseHistogram::WriteHTMLGraph(string* output) const {
35 // TODO(kaiwang): Implement. 37 // TODO(kaiwang): Implement.
36 } 38 }
37 39
38 void SparseHistogram::WriteAscii(string* output) const { 40 void SparseHistogram::WriteAscii(string* output) const {
39 // TODO(kaiwang): Implement. 41 // TODO(kaiwang): Implement.
40 } 42 }
41 43
42 SparseHistogram::SparseHistogram(const string& name) 44 SparseHistogram::SparseHistogram(const string& name)
43 : HistogramBase(name) {} 45 : HistogramBase(name) {}
44 46
45 } // namespace base 47 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698