Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: base/metrics/histogram_base.h

Issue 11682003: Serialize/Deserialize support in HistogramBase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another friend change Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/metrics/histogram.cc ('k') | base/metrics/histogram_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
20 class HistogramBase;
17 class HistogramSamples; 21 class HistogramSamples;
18 class ListValue; 22 class ListValue;
19 23
20 //////////////////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////////////////
21 // These enums are used to facilitate deserialization of histograms from other 25 // These enums are used to facilitate deserialization of histograms from other
22 // processes into the browser. If you create another class that inherits from 26 // processes into the browser. If you create another class that inherits from
23 // HistogramBase, add new histogram types and names below. 27 // HistogramBase, add new histogram types and names below.
24 28
25 enum BASE_EXPORT HistogramType { 29 enum BASE_EXPORT HistogramType {
26 HISTOGRAM, 30 HISTOGRAM,
27 LINEAR_HISTOGRAM, 31 LINEAR_HISTOGRAM,
28 BOOLEAN_HISTOGRAM, 32 BOOLEAN_HISTOGRAM,
29 CUSTOM_HISTOGRAM, 33 CUSTOM_HISTOGRAM,
30 SPARSE_HISTOGRAM, 34 SPARSE_HISTOGRAM,
31 }; 35 };
32 36
33 std::string HistogramTypeToString(HistogramType type); 37 std::string HistogramTypeToString(HistogramType type);
34 38
39 // Create or find existing histogram that matches the pickled info.
40 // Returns NULL if the pickled data has problems.
41 BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
42 PickleIterator* iter);
43
44 // Create or find existing histogram and add the samples from pickle.
45 // Silently returns when seeing any data problem in the pickle.
46 BASE_EXPORT void DeserializeHistogramAndAddSamples(PickleIterator* iter);
47
35 //////////////////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////////////////
36 49
37 class BASE_EXPORT HistogramBase { 50 class BASE_EXPORT HistogramBase {
38 public: 51 public:
39 typedef int Sample; // Used for samples. 52 typedef int Sample; // Used for samples.
40 typedef int Count; // Used to count samples. 53 typedef int Count; // Used to count samples.
41 54
42 static const Sample kSampleType_MAX; // INT_MAX 55 static const Sample kSampleType_MAX; // INT_MAX
43 56
44 enum Flags { 57 enum Flags {
(...skipping 17 matching lines...) Expand all
62 std::string histogram_name() const { return histogram_name_; } 75 std::string histogram_name() const { return histogram_name_; }
63 76
64 // Operations with Flags enum. 77 // Operations with Flags enum.
65 int32 flags() const { return flags_; } 78 int32 flags() const { return flags_; }
66 void SetFlags(int32 flags); 79 void SetFlags(int32 flags);
67 void ClearFlags(int32 flags); 80 void ClearFlags(int32 flags);
68 81
69 virtual HistogramType GetHistogramType() const = 0; 82 virtual HistogramType GetHistogramType() const = 0;
70 83
71 // Whether the histogram has construction arguments as parameters specified. 84 // Whether the histogram has construction arguments as parameters specified.
72 // For histograms that don't have the concept of minimum, maximum or 85 // For histograms that don't have the concept of |minimum|, |maximum| or
73 // bucket_count, this function always returns false. 86 // |bucket_count|, this function always returns false.
74 virtual bool HasConstructionArguments(Sample minimum, 87 virtual bool HasConstructionArguments(Sample minimum,
75 Sample maximum, 88 Sample maximum,
76 size_t bucket_count) const = 0; 89 size_t bucket_count) const = 0;
77 90
78 virtual void Add(Sample value) = 0; 91 virtual void Add(Sample value) = 0;
79 92
93 virtual void AddSamples(const HistogramSamples& samples) = 0;
94 virtual bool AddSamplesFromPickle(PickleIterator* iter) = 0;
95
96 // Serialize the histogram info into |pickle|.
97 // Note: This only serializes the construction arguments of the histogram, but
98 // does not serialize the samples.
99 bool SerializeInfo(Pickle* pickle) const;
100
80 // Snapshot the current complete set of sample data. 101 // Snapshot the current complete set of sample data.
81 // Override with atomic/locked snapshot if needed. 102 // Override with atomic/locked snapshot if needed.
82 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; 103 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0;
83 104
84 // The following methods provide graphical histogram displays. 105 // The following methods provide graphical histogram displays.
85 virtual void WriteHTMLGraph(std::string* output) const = 0; 106 virtual void WriteHTMLGraph(std::string* output) const = 0;
86 virtual void WriteAscii(std::string* output) const = 0; 107 virtual void WriteAscii(std::string* output) const = 0;
87 108
88 // Produce a JSON representation of the histogram. This is implemented with 109 // Produce a JSON representation of the histogram. This is implemented with
89 // the help of GetParameters and GetCountAndBucketData; overwrite them to 110 // the help of GetParameters and GetCountAndBucketData; overwrite them to
90 // customize the output. 111 // customize the output.
91 void WriteJSON(std::string* output) const; 112 void WriteJSON(std::string* output) const;
92 113
93 protected: 114 protected:
115 // Subclasses should implement this function to make SerializeInfo work.
116 virtual bool SerializeInfoImpl(Pickle* pickle) const = 0;
117
94 // Writes information about the construction parameters in |params|. 118 // Writes information about the construction parameters in |params|.
95 virtual void GetParameters(DictionaryValue* params) const = 0; 119 virtual void GetParameters(DictionaryValue* params) const = 0;
96 120
97 // Writes information about the current (non-empty) buckets and their sample 121 // Writes information about the current (non-empty) buckets and their sample
98 // counts to |buckets| and the total sample count to |count|. 122 // counts to |buckets| and the total sample count to |count|.
99 virtual void GetCountAndBucketData(Count* count, 123 virtual void GetCountAndBucketData(Count* count,
100 ListValue* buckets) const = 0; 124 ListValue* buckets) const = 0;
101 private: 125 private:
102 const std::string histogram_name_; 126 const std::string histogram_name_;
103 int32 flags_; 127 int32 flags_;
104 128
105 DISALLOW_COPY_AND_ASSIGN(HistogramBase); 129 DISALLOW_COPY_AND_ASSIGN(HistogramBase);
106 }; 130 };
107 131
108 } // namespace base 132 } // namespace base
109 133
110 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ 134 #endif // BASE_METRICS_HISTOGRAM_BASE_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram.cc ('k') | base/metrics/histogram_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698