Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / base / metrics / sparse_histogram.h
blobc1149163f59b4cb5b8d6dff303bd1a3721a07105
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 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_
6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_
8 #include <map>
9 #include <string>
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/histogram_base.h"
17 #include "base/metrics/sample_map.h"
18 #include "base/synchronization/lock.h"
20 namespace base {
22 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \
23 do { \
24 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \
25 name, base::HistogramBase::kUmaTargetedHistogramFlag); \
26 histogram->Add(sample); \
27 } while (0)
29 class HistogramSamples;
31 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase {
32 public:
33 // If there's one with same name, return the existing one. If not, create a
34 // new one.
35 static HistogramBase* FactoryGet(const std::string& name, int32 flags);
37 virtual ~SparseHistogram();
39 // HistogramBase implementation:
40 virtual HistogramType GetHistogramType() const OVERRIDE;
41 virtual bool HasConstructionArguments(
42 Sample expected_minimum,
43 Sample expected_maximum,
44 size_t expected_bucket_count) const OVERRIDE;
45 virtual void Add(Sample value) OVERRIDE;
46 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE;
47 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE;
48 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE;
49 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE;
50 virtual void WriteAscii(std::string* output) const OVERRIDE;
52 protected:
53 // HistogramBase implementation:
54 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE;
56 private:
57 // Clients should always use FactoryGet to create SparseHistogram.
58 explicit SparseHistogram(const std::string& name);
60 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
61 PickleIterator* iter);
62 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter);
64 virtual void GetParameters(DictionaryValue* params) const OVERRIDE;
65 virtual void GetCountAndBucketData(Count* count,
66 int64* sum,
67 ListValue* buckets) const OVERRIDE;
69 // Helpers for emitting Ascii graphic. Each method appends data to output.
70 void WriteAsciiImpl(bool graph_it,
71 const std::string& newline,
72 std::string* output) const;
74 // Write a common header message describing this histogram.
75 void WriteAsciiHeader(const Count total_count,
76 std::string* output) const;
78 // For constuctor calling.
79 friend class SparseHistogramTest;
81 // Protects access to |samples_|.
82 mutable base::Lock lock_;
84 SampleMap samples_;
86 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
89 } // namespace base
91 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_