| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
| 14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 | 19 |
| 20 class Pickle; | |
| 21 class PickleIterator; | |
| 22 | |
| 23 namespace base { | 20 namespace base { |
| 24 | 21 |
| 25 class DictionaryValue; | 22 class DictionaryValue; |
| 26 class HistogramBase; | 23 class HistogramBase; |
| 27 class HistogramSamples; | 24 class HistogramSamples; |
| 28 class ListValue; | 25 class ListValue; |
| 26 class Pickle; |
| 27 class PickleIterator; |
| 29 | 28 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 31 // These enums are used to facilitate deserialization of histograms from other | 30 // These enums are used to facilitate deserialization of histograms from other |
| 32 // processes into the browser. If you create another class that inherits from | 31 // processes into the browser. If you create another class that inherits from |
| 33 // HistogramBase, add new histogram types and names below. | 32 // HistogramBase, add new histogram types and names below. |
| 34 | 33 |
| 35 enum BASE_EXPORT HistogramType { | 34 enum BASE_EXPORT HistogramType { |
| 36 HISTOGRAM, | 35 HISTOGRAM, |
| 37 LINEAR_HISTOGRAM, | 36 LINEAR_HISTOGRAM, |
| 38 BOOLEAN_HISTOGRAM, | 37 BOOLEAN_HISTOGRAM, |
| 39 CUSTOM_HISTOGRAM, | 38 CUSTOM_HISTOGRAM, |
| 40 SPARSE_HISTOGRAM, | 39 SPARSE_HISTOGRAM, |
| 41 }; | 40 }; |
| 42 | 41 |
| 43 std::string HistogramTypeToString(HistogramType type); | 42 std::string HistogramTypeToString(HistogramType type); |
| 44 | 43 |
| 45 // Create or find existing histogram that matches the pickled info. | 44 // Create or find existing histogram that matches the pickled info. |
| 46 // Returns NULL if the pickled data has problems. | 45 // Returns NULL if the pickled data has problems. |
| 47 BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 46 BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
| 48 PickleIterator* iter); | 47 base::PickleIterator* iter); |
| 49 | 48 |
| 50 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
| 51 | 50 |
| 52 class BASE_EXPORT HistogramBase { | 51 class BASE_EXPORT HistogramBase { |
| 53 public: | 52 public: |
| 54 typedef int32_t Sample; // Used for samples. | 53 typedef int32_t Sample; // Used for samples. |
| 55 typedef subtle::Atomic32 AtomicCount; // Used to count samples. | 54 typedef subtle::Atomic32 AtomicCount; // Used to count samples. |
| 56 typedef int32_t Count; // Used to manipulate counts in temporaries. | 55 typedef int32_t Count; // Used to manipulate counts in temporaries. |
| 57 | 56 |
| 58 static const Sample kSampleType_MAX; // INT_MAX | 57 static const Sample kSampleType_MAX; // INT_MAX |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 Sample expected_maximum, | 113 Sample expected_maximum, |
| 115 size_t expected_bucket_count) const = 0; | 114 size_t expected_bucket_count) const = 0; |
| 116 | 115 |
| 117 virtual void Add(Sample value) = 0; | 116 virtual void Add(Sample value) = 0; |
| 118 | 117 |
| 119 // 2 convenient functions that call Add(Sample). | 118 // 2 convenient functions that call Add(Sample). |
| 120 void AddTime(const TimeDelta& time); | 119 void AddTime(const TimeDelta& time); |
| 121 void AddBoolean(bool value); | 120 void AddBoolean(bool value); |
| 122 | 121 |
| 123 virtual void AddSamples(const HistogramSamples& samples) = 0; | 122 virtual void AddSamples(const HistogramSamples& samples) = 0; |
| 124 virtual bool AddSamplesFromPickle(PickleIterator* iter) = 0; | 123 virtual bool AddSamplesFromPickle(base::PickleIterator* iter) = 0; |
| 125 | 124 |
| 126 // Serialize the histogram info into |pickle|. | 125 // Serialize the histogram info into |pickle|. |
| 127 // Note: This only serializes the construction arguments of the histogram, but | 126 // Note: This only serializes the construction arguments of the histogram, but |
| 128 // does not serialize the samples. | 127 // does not serialize the samples. |
| 129 bool SerializeInfo(Pickle* pickle) const; | 128 bool SerializeInfo(base::Pickle* pickle) const; |
| 130 | 129 |
| 131 // Try to find out data corruption from histogram and the samples. | 130 // Try to find out data corruption from histogram and the samples. |
| 132 // The returned value is a combination of Inconsistency enum. | 131 // The returned value is a combination of Inconsistency enum. |
| 133 virtual int FindCorruption(const HistogramSamples& samples) const; | 132 virtual int FindCorruption(const HistogramSamples& samples) const; |
| 134 | 133 |
| 135 // Snapshot the current complete set of sample data. | 134 // Snapshot the current complete set of sample data. |
| 136 // Override with atomic/locked snapshot if needed. | 135 // Override with atomic/locked snapshot if needed. |
| 137 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; | 136 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; |
| 138 | 137 |
| 139 // The following methods provide graphical histogram displays. | 138 // The following methods provide graphical histogram displays. |
| 140 virtual void WriteHTMLGraph(std::string* output) const = 0; | 139 virtual void WriteHTMLGraph(std::string* output) const = 0; |
| 141 virtual void WriteAscii(std::string* output) const = 0; | 140 virtual void WriteAscii(std::string* output) const = 0; |
| 142 | 141 |
| 143 // Produce a JSON representation of the histogram. This is implemented with | 142 // Produce a JSON representation of the histogram. This is implemented with |
| 144 // the help of GetParameters and GetCountAndBucketData; overwrite them to | 143 // the help of GetParameters and GetCountAndBucketData; overwrite them to |
| 145 // customize the output. | 144 // customize the output. |
| 146 void WriteJSON(std::string* output) const; | 145 void WriteJSON(std::string* output) const; |
| 147 | 146 |
| 148 protected: | 147 protected: |
| 149 // Subclasses should implement this function to make SerializeInfo work. | 148 // Subclasses should implement this function to make SerializeInfo work. |
| 150 virtual bool SerializeInfoImpl(Pickle* pickle) const = 0; | 149 virtual bool SerializeInfoImpl(base::Pickle* pickle) const = 0; |
| 151 | 150 |
| 152 // Writes information about the construction parameters in |params|. | 151 // Writes information about the construction parameters in |params|. |
| 153 virtual void GetParameters(DictionaryValue* params) const = 0; | 152 virtual void GetParameters(DictionaryValue* params) const = 0; |
| 154 | 153 |
| 155 // Writes information about the current (non-empty) buckets and their sample | 154 // Writes information about the current (non-empty) buckets and their sample |
| 156 // counts to |buckets|, the total sample count to |count| and the total sum | 155 // counts to |buckets|, the total sample count to |count| and the total sum |
| 157 // to |sum|. | 156 // to |sum|. |
| 158 virtual void GetCountAndBucketData(Count* count, | 157 virtual void GetCountAndBucketData(Count* count, |
| 159 int64* sum, | 158 int64* sum, |
| 160 ListValue* buckets) const = 0; | 159 ListValue* buckets) const = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 176 private: | 175 private: |
| 177 const std::string histogram_name_; | 176 const std::string histogram_name_; |
| 178 int32_t flags_; | 177 int32_t flags_; |
| 179 | 178 |
| 180 DISALLOW_COPY_AND_ASSIGN(HistogramBase); | 179 DISALLOW_COPY_AND_ASSIGN(HistogramBase); |
| 181 }; | 180 }; |
| 182 | 181 |
| 183 } // namespace base | 182 } // namespace base |
| 184 | 183 |
| 185 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ | 184 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ |
| OLD | NEW |