OLD | NEW |
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 |
OLD | NEW |