OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_METRICS_HISTOGRAM_BASE_H_ | 5 #ifndef BASE_METRICS_HISTOGRAM_BASE_H_ |
6 #define BASE_METRICS_HISTOGRAM_BASE_H_ | 6 #define BASE_METRICS_HISTOGRAM_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/strings/string_piece.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 | 17 |
17 class Pickle; | 18 class Pickle; |
18 class PickleIterator; | 19 class PickleIterator; |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 | 22 |
22 class DictionaryValue; | 23 class DictionaryValue; |
23 class HistogramBase; | 24 class HistogramBase; |
24 class HistogramSamples; | 25 class HistogramSamples; |
(...skipping 16 matching lines...) Expand all Loading... |
41 | 42 |
42 // Create or find existing histogram that matches the pickled info. | 43 // Create or find existing histogram that matches the pickled info. |
43 // Returns NULL if the pickled data has problems. | 44 // Returns NULL if the pickled data has problems. |
44 BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 45 BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
45 PickleIterator* iter); | 46 PickleIterator* iter); |
46 | 47 |
47 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
48 | 49 |
49 class BASE_EXPORT HistogramBase { | 50 class BASE_EXPORT HistogramBase { |
50 public: | 51 public: |
51 typedef int Sample; // Used for samples. | 52 typedef int Sample; // Used for samples. |
52 typedef subtle::Atomic32 AtomicCount; // Used to count samples. | 53 typedef subtle::Atomic32 AtomicCount; // Used to count samples. |
53 typedef int32 Count; // Used to manipulate counts in temporaries. | 54 typedef int32 Count; // Used to manipulate counts in temporaries. |
54 | 55 |
55 static const Sample kSampleType_MAX; // INT_MAX | 56 static const Sample kSampleType_MAX; // INT_MAX |
56 | 57 |
57 enum Flags { | 58 enum Flags { |
58 kNoFlags = 0, | 59 kNoFlags = 0, |
59 | 60 |
60 // Histogram should be UMA uploaded. | 61 // Histogram should be UMA uploaded. |
61 kUmaTargetedHistogramFlag = 0x1, | 62 kUmaTargetedHistogramFlag = 0x1, |
62 | 63 |
(...skipping 22 matching lines...) Expand all Loading... |
85 COUNT_LOW_ERROR = 0x8, | 86 COUNT_LOW_ERROR = 0x8, |
86 | 87 |
87 NEVER_EXCEEDED_VALUE = 0x10 | 88 NEVER_EXCEEDED_VALUE = 0x10 |
88 }; | 89 }; |
89 | 90 |
90 explicit HistogramBase(const std::string& name); | 91 explicit HistogramBase(const std::string& name); |
91 virtual ~HistogramBase(); | 92 virtual ~HistogramBase(); |
92 | 93 |
93 std::string histogram_name() const { return histogram_name_; } | 94 std::string histogram_name() const { return histogram_name_; } |
94 | 95 |
| 96 // Comapres |name| to the histogram name and triggers a DCHECK if they do not |
| 97 // match. This is a helper function used by histogram macros, which results in |
| 98 // in more compact machine code being generated by the macros. |
| 99 void CheckName(const StringPiece& name) const; |
| 100 |
95 // Operations with Flags enum. | 101 // Operations with Flags enum. |
96 int32 flags() const { return flags_; } | 102 int32 flags() const { return flags_; } |
97 void SetFlags(int32 flags); | 103 void SetFlags(int32 flags); |
98 void ClearFlags(int32 flags); | 104 void ClearFlags(int32 flags); |
99 | 105 |
100 virtual HistogramType GetHistogramType() const = 0; | 106 virtual HistogramType GetHistogramType() const = 0; |
101 | 107 |
102 // Whether the histogram has construction arguments as parameters specified. | 108 // Whether the histogram has construction arguments as parameters specified. |
103 // For histograms that don't have the concept of minimum, maximum or | 109 // For histograms that don't have the concept of minimum, maximum or |
104 // bucket_count, this function always returns false. | 110 // bucket_count, this function always returns false. |
(...skipping 25 matching lines...) Expand all Loading... |
130 | 136 |
131 // The following methods provide graphical histogram displays. | 137 // The following methods provide graphical histogram displays. |
132 virtual void WriteHTMLGraph(std::string* output) const = 0; | 138 virtual void WriteHTMLGraph(std::string* output) const = 0; |
133 virtual void WriteAscii(std::string* output) const = 0; | 139 virtual void WriteAscii(std::string* output) const = 0; |
134 | 140 |
135 // Produce a JSON representation of the histogram. This is implemented with | 141 // Produce a JSON representation of the histogram. This is implemented with |
136 // the help of GetParameters and GetCountAndBucketData; overwrite them to | 142 // the help of GetParameters and GetCountAndBucketData; overwrite them to |
137 // customize the output. | 143 // customize the output. |
138 void WriteJSON(std::string* output) const; | 144 void WriteJSON(std::string* output) const; |
139 | 145 |
140 protected: | 146 protected: |
141 // Subclasses should implement this function to make SerializeInfo work. | 147 // Subclasses should implement this function to make SerializeInfo work. |
142 virtual bool SerializeInfoImpl(Pickle* pickle) const = 0; | 148 virtual bool SerializeInfoImpl(Pickle* pickle) const = 0; |
143 | 149 |
144 // Writes information about the construction parameters in |params|. | 150 // Writes information about the construction parameters in |params|. |
145 virtual void GetParameters(DictionaryValue* params) const = 0; | 151 virtual void GetParameters(DictionaryValue* params) const = 0; |
146 | 152 |
147 // Writes information about the current (non-empty) buckets and their sample | 153 // Writes information about the current (non-empty) buckets and their sample |
148 // counts to |buckets|, the total sample count to |count| and the total sum | 154 // counts to |buckets|, the total sample count to |count| and the total sum |
149 // to |sum|. | 155 // to |sum|. |
150 virtual void GetCountAndBucketData(Count* count, | 156 virtual void GetCountAndBucketData(Count* count, |
(...skipping 17 matching lines...) Expand all Loading... |
168 private: | 174 private: |
169 const std::string histogram_name_; | 175 const std::string histogram_name_; |
170 int32 flags_; | 176 int32 flags_; |
171 | 177 |
172 DISALLOW_COPY_AND_ASSIGN(HistogramBase); | 178 DISALLOW_COPY_AND_ASSIGN(HistogramBase); |
173 }; | 179 }; |
174 | 180 |
175 } // namespace base | 181 } // namespace base |
176 | 182 |
177 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ | 183 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |
OLD | NEW |