[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef BASE_METRICS_HISTOGRAM_BASE_H_ | ||||
6 | #define BASE_METRICS_HISTOGRAM_BASE_H_ | ||||
7 | |||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 8 | #include <string> |
9 | |||||
10 | #include "base/base_export.h" | ||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 877ef56 | 2012-10-20 02:56:18 | [diff] [blame^] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 13 | |
14 | namespace base { | ||||
15 | |||||
[email protected] | 24a7ec5e | 2012-10-08 10:31:50 | [diff] [blame] | 16 | class DictionaryValue; |
17 | class ListValue; | ||||
18 | |||||
[email protected] | 877ef56 | 2012-10-20 02:56:18 | [diff] [blame^] | 19 | class HistogramSamples; |
20 | |||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 21 | class BASE_EXPORT HistogramBase { |
22 | public: | ||||
23 | typedef int Sample; // Used for samples. | ||||
24 | typedef int Count; // Used to count samples. | ||||
25 | |||||
[email protected] | 34d06232 | 2012-08-01 21:34:08 | [diff] [blame] | 26 | static const Sample kSampleType_MAX; // INT_MAX |
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 27 | |
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 28 | enum Flags { |
29 | kNoFlags = 0, | ||||
30 | kUmaTargetedHistogramFlag = 0x1, // Histogram should be UMA uploaded. | ||||
31 | |||||
32 | // Indicate that the histogram was pickled to be sent across an IPC Channel. | ||||
33 | // If we observe this flag on a histogram being aggregated into after IPC, | ||||
34 | // then we are running in a single process mode, and the aggregation should | ||||
35 | // not take place (as we would be aggregating back into the source | ||||
36 | // histogram!). | ||||
37 | kIPCSerializationSourceFlag = 0x10, | ||||
38 | |||||
39 | // Only for Histogram and its sub classes: fancy bucket-naming support. | ||||
40 | kHexRangePrintingFlag = 0x8000, | ||||
41 | }; | ||||
42 | |||||
43 | |||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 44 | HistogramBase(const std::string& name); |
45 | virtual ~HistogramBase(); | ||||
46 | |||||
47 | std::string histogram_name() const { return histogram_name_; } | ||||
48 | |||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 49 | // Operations with Flags enum. |
50 | int32 flags() const { return flags_; } | ||||
51 | void SetFlags(int32 flags); | ||||
52 | void ClearFlags(int32 flags); | ||||
53 | |||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 54 | virtual void Add(Sample value) = 0; |
55 | |||||
[email protected] | 877ef56 | 2012-10-20 02:56:18 | [diff] [blame^] | 56 | virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; |
57 | |||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 58 | // The following methods provide graphical histogram displays. |
59 | virtual void WriteHTMLGraph(std::string* output) const = 0; | ||||
60 | virtual void WriteAscii(std::string* output) const = 0; | ||||
61 | |||||
[email protected] | 24a7ec5e | 2012-10-08 10:31:50 | [diff] [blame] | 62 | // Produce a JSON representation of the histogram. This is implemented with |
63 | // the help of GetParameters and GetCountAndBucketData; overwrite them to | ||||
64 | // customize the output. | ||||
65 | void WriteJSON(std::string* output) const; | ||||
66 | |||||
67 | protected: | ||||
68 | // Writes information about the construction parameters in |params|. | ||||
69 | virtual void GetParameters(DictionaryValue* params) const = 0; | ||||
70 | |||||
71 | // Writes information about the current (non-empty) buckets and their sample | ||||
72 | // counts to |buckets| and the total sample count to |count|. | ||||
73 | virtual void GetCountAndBucketData(Count* count, | ||||
74 | ListValue* buckets) const = 0; | ||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 75 | private: |
76 | const std::string histogram_name_; | ||||
[email protected] | 7c7a4275 | 2012-08-09 05:14:15 | [diff] [blame] | 77 | int32 flags_; |
78 | |||||
79 | DISALLOW_COPY_AND_ASSIGN(HistogramBase); | ||||
[email protected] | c884117b | 2012-07-19 05:31:49 | [diff] [blame] | 80 | }; |
81 | |||||
82 | } // namespace base | ||||
83 | |||||
84 | #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |