Replace command buffer FlushSync with WaitForTokenInRange and WaitForGetOffsetInRange
[chromium-blink-merge.git] / base / metrics / sparse_histogram.h
blob07d56603a5d8b4b7a85caadedbbf67d6dba39215
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 // The common code for different SparseHistogram macros.
23 #define HISTOGRAM_SPARSE_COMMON(name, sample, flag) \
24 do { \
25 base::HistogramBase* histogram( \
26 base::SparseHistogram::FactoryGet(name, flag)); \
27 DCHECK_EQ(histogram->histogram_name(), name); \
28 histogram->Add(sample); \
29 } while (0)
31 #define HISTOGRAM_SPARSE_SLOWLY(name, sample) \
32 HISTOGRAM_SPARSE_COMMON(name, sample, base::HistogramBase::kNoFlags)
34 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \
35 HISTOGRAM_SPARSE_COMMON(name, sample, \
36 base::HistogramBase::kUmaTargetedHistogramFlag)
38 //------------------------------------------------------------------------------
39 // Define debug only version of macros.
40 #ifndef NDEBUG
42 #define DHISTOGRAM_SPARSE_SLOWLY(name, sample) \
43 HISTOGRAM_SPARSE_SLOWLY(name, sample)
45 #else // NDEBUG
47 #define DHISTOGRAM_SPARSE_SLOWLY(name, sample) \
48 while (0) { \
49 static_cast<void>(name); \
50 static_cast<void>(sample); \
53 #endif // NDEBUG
55 class HistogramSamples;
57 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase {
58 public:
59 // If there's one with same name, return the existing one. If not, create a
60 // new one.
61 static HistogramBase* FactoryGet(const std::string& name, int32 flags);
63 virtual ~SparseHistogram();
65 // HistogramBase implementation:
66 virtual HistogramType GetHistogramType() const OVERRIDE;
67 virtual bool HasConstructionArguments(
68 Sample expected_minimum,
69 Sample expected_maximum,
70 size_t expected_bucket_count) const OVERRIDE;
71 virtual void Add(Sample value) OVERRIDE;
72 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE;
73 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE;
74 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE;
75 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE;
76 virtual void WriteAscii(std::string* output) const OVERRIDE;
78 protected:
79 // HistogramBase implementation:
80 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE;
82 private:
83 // Clients should always use FactoryGet to create SparseHistogram.
84 explicit SparseHistogram(const std::string& name);
86 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
87 PickleIterator* iter);
88 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter);
90 virtual void GetParameters(DictionaryValue* params) const OVERRIDE;
91 virtual void GetCountAndBucketData(Count* count,
92 int64* sum,
93 ListValue* buckets) const OVERRIDE;
95 // Helpers for emitting Ascii graphic. Each method appends data to output.
96 void WriteAsciiImpl(bool graph_it,
97 const std::string& newline,
98 std::string* output) const;
100 // Write a common header message describing this histogram.
101 void WriteAsciiHeader(const Count total_count,
102 std::string* output) const;
104 // For constuctor calling.
105 friend class SparseHistogramTest;
107 // Protects access to |samples_|.
108 mutable base::Lock lock_;
110 SampleMap samples_;
112 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
115 } // namespace base
117 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_