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.
5 #include "base/metrics/sparse_histogram.h"
7 #include "base/metrics/statistics_recorder.h"
8 #include "base/synchronization/lock.h"
15 typedef HistogramBase::Count Count
;
16 typedef HistogramBase::Sample Sample
;
19 HistogramBase
* SparseHistogram::FactoryGet(const string
& name
, int32 flags
) {
20 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder.
21 HistogramBase
* histogram
= new SparseHistogram(name
);
22 histogram
->SetFlags(flags
);
26 SparseHistogram::~SparseHistogram() {}
28 void SparseHistogram::Add(Sample value
) {
29 base::AutoLock
auto_lock(lock_
);
30 sample_counts_
[value
]++;
31 redundant_count_
+= 1;
34 scoped_ptr
<SampleMap
> SparseHistogram::SnapshotSamples() const {
35 scoped_ptr
<SampleMap
> snapshot(new SampleMap());
37 base::AutoLock
auto_lock(lock_
);
38 for(map
<Sample
, Count
>::const_iterator it
= sample_counts_
.begin();
39 it
!= sample_counts_
.end();
41 snapshot
->Accumulate(it
->first
, it
->second
);
43 snapshot
->ResetRedundantCount(redundant_count_
);
44 return snapshot
.Pass();
47 void SparseHistogram::WriteHTMLGraph(string
* output
) const {
48 // TODO(kaiwang): Implement.
51 void SparseHistogram::WriteAscii(string
* output
) const {
52 // TODO(kaiwang): Implement.
55 SparseHistogram::SparseHistogram(const string
& name
)
56 : HistogramBase(name
),
57 redundant_count_(0) {}
59 void SparseHistogram::GetParameters(DictionaryValue
* params
) const {
60 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)
63 void SparseHistogram::GetCountAndBucketData(Count
* count
,
64 ListValue
* buckets
) const {
65 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)