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 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 | 13 |
14 class Pickle; | |
15 class PickleIterator; | |
16 | |
14 namespace base { | 17 namespace base { |
15 | 18 |
16 class DictionaryValue; | 19 class DictionaryValue; |
17 class HistogramSamples; | 20 class HistogramSamples; |
18 class ListValue; | 21 class ListValue; |
19 | 22 |
20 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
21 // These enums are used to facilitate deserialization of histograms from other | 24 // These enums are used to facilitate deserialization of histograms from other |
22 // processes into the browser. If you create another class that inherits from | 25 // processes into the browser. If you create another class that inherits from |
23 // HistogramBase, add new histogram types and names below. | 26 // HistogramBase, add new histogram types and names below. |
(...skipping 28 matching lines...) Expand all Loading... | |
52 // histogram!). | 55 // histogram!). |
53 kIPCSerializationSourceFlag = 0x10, | 56 kIPCSerializationSourceFlag = 0x10, |
54 | 57 |
55 // Only for Histogram and its sub classes: fancy bucket-naming support. | 58 // Only for Histogram and its sub classes: fancy bucket-naming support. |
56 kHexRangePrintingFlag = 0x8000, | 59 kHexRangePrintingFlag = 0x8000, |
57 }; | 60 }; |
58 | 61 |
59 HistogramBase(const std::string& name); | 62 HistogramBase(const std::string& name); |
60 virtual ~HistogramBase(); | 63 virtual ~HistogramBase(); |
61 | 64 |
65 // Create or find existing histogram that matches the pickled info. Returns | |
66 // NULL if the pickled data has problems. | |
67 static HistogramBase* DeserializeHistogramInfo(PickleIterator* iter); | |
68 | |
62 std::string histogram_name() const { return histogram_name_; } | 69 std::string histogram_name() const { return histogram_name_; } |
63 | 70 |
64 // Operations with Flags enum. | 71 // Operations with Flags enum. |
65 int32 flags() const { return flags_; } | 72 int32 flags() const { return flags_; } |
66 void SetFlags(int32 flags); | 73 void SetFlags(int32 flags); |
67 void ClearFlags(int32 flags); | 74 void ClearFlags(int32 flags); |
68 | 75 |
69 virtual HistogramType GetHistogramType() const = 0; | 76 virtual HistogramType GetHistogramType() const = 0; |
70 | 77 |
71 // Whether the histogram has construction arguments as parameters specified. | 78 // Whether the histogram has construction arguments as parameters specified. |
72 // For histograms that don't have the concept of minimum, maximum or | 79 // For histograms that don't have the concept of |minimum|, |maximum| or |
73 // bucket_count, this function always returns false. | 80 // |bucket_count|, this function always returns false. |
74 virtual bool HasConstructionArguments(Sample minimum, | 81 virtual bool HasConstructionArguments(Sample minimum, |
75 Sample maximum, | 82 Sample maximum, |
76 size_t bucket_count) const = 0; | 83 size_t bucket_count) const = 0; |
77 | 84 |
78 virtual void Add(Sample value) = 0; | 85 virtual void Add(Sample value) = 0; |
79 | 86 |
87 virtual void AddSamples(const HistogramSamples& samples) = 0; | |
88 virtual bool AddSamplesFromPickle(PickleIterator* iter) = 0; | |
89 | |
90 // Serialize the histogram info into |pickle|. | |
91 // Note. This only serialize construction info of the histogram, but not | |
92 // serialize the samples. | |
Ilya Sherman
2012/12/29 00:17:30
nit: "Note: This only serializes the construction
kaiwang
2013/01/08 00:51:40
Done.
| |
93 bool SerializeInfo(Pickle* pickle) const; | |
94 | |
80 // Snapshot the current complete set of sample data. | 95 // Snapshot the current complete set of sample data. |
81 // Override with atomic/locked snapshot if needed. | 96 // Override with atomic/locked snapshot if needed. |
82 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; | 97 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; |
83 | 98 |
84 // The following methods provide graphical histogram displays. | 99 // The following methods provide graphical histogram displays. |
85 virtual void WriteHTMLGraph(std::string* output) const = 0; | 100 virtual void WriteHTMLGraph(std::string* output) const = 0; |
86 virtual void WriteAscii(std::string* output) const = 0; | 101 virtual void WriteAscii(std::string* output) const = 0; |
87 | 102 |
88 // Produce a JSON representation of the histogram. This is implemented with | 103 // Produce a JSON representation of the histogram. This is implemented with |
89 // the help of GetParameters and GetCountAndBucketData; overwrite them to | 104 // the help of GetParameters and GetCountAndBucketData; overwrite them to |
90 // customize the output. | 105 // customize the output. |
91 void WriteJSON(std::string* output) const; | 106 void WriteJSON(std::string* output) const; |
92 | 107 |
93 protected: | 108 protected: |
109 // Subclasses should implement this function to make SerializeInfo work. | |
110 virtual bool SerializeInfoImpl(Pickle* pickle) const = 0; | |
111 | |
94 // Writes information about the construction parameters in |params|. | 112 // Writes information about the construction parameters in |params|. |
95 virtual void GetParameters(DictionaryValue* params) const = 0; | 113 virtual void GetParameters(DictionaryValue* params) const = 0; |
96 | 114 |
97 // Writes information about the current (non-empty) buckets and their sample | 115 // Writes information about the current (non-empty) buckets and their sample |
98 // counts to |buckets| and the total sample count to |count|. | 116 // counts to |buckets| and the total sample count to |count|. |
99 virtual void GetCountAndBucketData(Count* count, | 117 virtual void GetCountAndBucketData(Count* count, |
100 ListValue* buckets) const = 0; | 118 ListValue* buckets) const = 0; |
101 private: | 119 private: |
102 const std::string histogram_name_; | 120 const std::string histogram_name_; |
103 int32 flags_; | 121 int32 flags_; |
104 | 122 |
105 DISALLOW_COPY_AND_ASSIGN(HistogramBase); | 123 DISALLOW_COPY_AND_ASSIGN(HistogramBase); |
106 }; | 124 }; |
107 | 125 |
108 } // namespace base | 126 } // namespace base |
109 | 127 |
110 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ | 128 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |
OLD | NEW |