blob: 236a19e1b54086635089876d45466a33415b2f5e [file] [log] [blame]
[email protected]7c7a42752012-08-09 05:14:151// 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]b4af2ec2012-10-05 21:29:448#include "base/synchronization/lock.h"
[email protected]7c7a42752012-08-09 05:14:159
[email protected]b4af2ec2012-10-05 21:29:4410using std::map;
[email protected]7c7a42752012-08-09 05:14:1511using std::string;
12
13namespace base {
14
[email protected]b4af2ec2012-10-05 21:29:4415typedef HistogramBase::Count Count;
16typedef HistogramBase::Sample Sample;
17
[email protected]7c7a42752012-08-09 05:14:1518// static
[email protected]b4af2ec2012-10-05 21:29:4419HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) {
[email protected]7c7a42752012-08-09 05:14:1520 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder.
21 HistogramBase* histogram = new SparseHistogram(name);
22 histogram->SetFlags(flags);
23 return histogram;
24}
25
26SparseHistogram::~SparseHistogram() {}
27
28void SparseHistogram::Add(Sample value) {
29 base::AutoLock auto_lock(lock_);
[email protected]b4af2ec2012-10-05 21:29:4430 sample_counts_[value]++;
31 redundant_count_ += 1;
[email protected]7c7a42752012-08-09 05:14:1532}
33
[email protected]b4af2ec2012-10-05 21:29:4434scoped_ptr<SampleMap> SparseHistogram::SnapshotSamples() const {
35 scoped_ptr<SampleMap> snapshot(new SampleMap());
36
[email protected]7c7a42752012-08-09 05:14:1537 base::AutoLock auto_lock(lock_);
[email protected]b4af2ec2012-10-05 21:29:4438 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]7c7a42752012-08-09 05:14:1545}
46
47void SparseHistogram::WriteHTMLGraph(string* output) const {
48 // TODO(kaiwang): Implement.
49}
50
51void SparseHistogram::WriteAscii(string* output) const {
52 // TODO(kaiwang): Implement.
53}
54
55SparseHistogram::SparseHistogram(const string& name)
[email protected]b4af2ec2012-10-05 21:29:4456 : HistogramBase(name),
57 redundant_count_(0) {}
[email protected]7c7a42752012-08-09 05:14:1558
[email protected]24a7ec52012-10-08 10:31:5059void SparseHistogram::GetParameters(DictionaryValue* params) const {
60 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)
61}
62
63void SparseHistogram::GetCountAndBucketData(Count* count,
64 ListValue* buckets) const {
65 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)
66}
67
[email protected]7c7a42752012-08-09 05:14:1568} // namespace base