[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "base/metrics/sparse_histogram.h" | ||||
6 | |||||
7 | #include "base/metrics/statistics_recorder.h" | ||||
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 8 | #include "base/synchronization/lock.h" |
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 9 | |
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 10 | using std::map; |
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 11 | using std::string; |
12 | |||||
13 | namespace base { | ||||
14 | |||||
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 15 | typedef HistogramBase::Count Count; |
16 | typedef HistogramBase::Sample Sample; | ||||
17 | |||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 18 | // static |
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 19 | HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { |
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 20 | // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. |
21 | HistogramBase* histogram = new SparseHistogram(name); | ||||
22 | histogram->SetFlags(flags); | ||||
23 | return histogram; | ||||
24 | } | ||||
25 | |||||
26 | SparseHistogram::~SparseHistogram() {} | ||||
27 | |||||
28 | void SparseHistogram::Add(Sample value) { | ||||
29 | base::AutoLock auto_lock(lock_); | ||||
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 30 | sample_counts_[value]++; |
31 | redundant_count_ += 1; | ||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 32 | } |
33 | |||||
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 34 | scoped_ptr<SampleMap> SparseHistogram::SnapshotSamples() const { |
35 | scoped_ptr<SampleMap> snapshot(new SampleMap()); | ||||
36 | |||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 37 | base::AutoLock auto_lock(lock_); |
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 38 | for(map<Sample, Count>::const_iterator it = sample_counts_.begin(); |
39 | it != sample_counts_.end(); | ||||
40 | ++it) { | ||||
41 | snapshot->Accumulate(it->first, it->second); | ||||
42 | } | ||||
43 | snapshot->ResetRedundantCount(redundant_count_); | ||||
44 | return snapshot.Pass(); | ||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 45 | } |
46 | |||||
47 | void SparseHistogram::WriteHTMLGraph(string* output) const { | ||||
48 | // TODO(kaiwang): Implement. | ||||
49 | } | ||||
50 | |||||
51 | void SparseHistogram::WriteAscii(string* output) const { | ||||
52 | // TODO(kaiwang): Implement. | ||||
53 | } | ||||
54 | |||||
55 | SparseHistogram::SparseHistogram(const string& name) | ||||
[email protected] | b4af2ec | 2012-10-05 21:29:44 | [diff] [blame] | 56 | : HistogramBase(name), |
57 | redundant_count_(0) {} | ||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 58 | |
[email protected] | 24a7ec5 | 2012-10-08 10:31:50 | [diff] [blame^] | 59 | void SparseHistogram::GetParameters(DictionaryValue* params) const { |
60 | // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) | ||||
61 | } | ||||
62 | |||||
63 | void SparseHistogram::GetCountAndBucketData(Count* count, | ||||
64 | ListValue* buckets) const { | ||||
65 | // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) | ||||
66 | } | ||||
67 | |||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 68 | } // namespace base |