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

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: Some changes about deserializing 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
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 HistogramBase* DeserializeHistogramInfo(PickleIterator* iter);
Ilya Sherman 2013/01/09 05:48:37 nit: Please tuck this into an anonymous namespace
kaiwang 2013/01/10 23:02:24 It's used by unittest. Although this is not direct
42
43 // Create or find existing histogram and add the samples from pickle.
44 bool DeserializeHistogramAndAddSamples(PickleIterator* iter);
Ilya Sherman 2013/01/09 05:48:37 nit: Why does this function need a return value?
kaiwang 2013/01/10 23:02:24 Done.
45
35 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
36 47
37 class BASE_EXPORT HistogramBase { 48 class BASE_EXPORT HistogramBase {
38 public: 49 public:
39 typedef int Sample; // Used for samples. 50 typedef int Sample; // Used for samples.
40 typedef int Count; // Used to count samples. 51 typedef int Count; // Used to count samples.
41 52
42 static const Sample kSampleType_MAX; // INT_MAX 53 static const Sample kSampleType_MAX; // INT_MAX
43 54
44 enum Flags { 55 enum Flags {
(...skipping 17 matching lines...) Expand all
62 std::string histogram_name() const { return histogram_name_; } 73 std::string histogram_name() const { return histogram_name_; }
63 74
64 // Operations with Flags enum. 75 // Operations with Flags enum.
65 int32 flags() const { return flags_; } 76 int32 flags() const { return flags_; }
66 void SetFlags(int32 flags); 77 void SetFlags(int32 flags);
67 void ClearFlags(int32 flags); 78 void ClearFlags(int32 flags);
68 79
69 virtual HistogramType GetHistogramType() const = 0; 80 virtual HistogramType GetHistogramType() const = 0;
70 81
71 // Whether the histogram has construction arguments as parameters specified. 82 // Whether the histogram has construction arguments as parameters specified.
72 // For histograms that don't have the concept of minimum, maximum or 83 // For histograms that don't have the concept of |minimum|, |maximum| or
73 // bucket_count, this function always returns false. 84 // |bucket_count|, this function always returns false.
74 virtual bool HasConstructionArguments(Sample minimum, 85 virtual bool HasConstructionArguments(Sample minimum,
75 Sample maximum, 86 Sample maximum,
76 size_t bucket_count) const = 0; 87 size_t bucket_count) const = 0;
77 88
78 virtual void Add(Sample value) = 0; 89 virtual void Add(Sample value) = 0;
79 90
91 virtual void AddSamples(const HistogramSamples& samples) = 0;
92 virtual bool AddSamplesFromPickle(PickleIterator* iter) = 0;
93
94 // Serialize the histogram info into |pickle|.
95 // Note. This only serializes the construction arguments of the histogram, but
Ilya Sherman 2013/01/09 05:48:37 nit: "Note." -> "Note:"; "but not" -> "but does no
kaiwang 2013/01/10 23:02:24 Done.
96 // not serialize the samples.
97 bool SerializeInfo(Pickle* pickle) const;
98
80 // Snapshot the current complete set of sample data. 99 // Snapshot the current complete set of sample data.
81 // Override with atomic/locked snapshot if needed. 100 // Override with atomic/locked snapshot if needed.
82 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0; 101 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0;
83 102
84 // The following methods provide graphical histogram displays. 103 // The following methods provide graphical histogram displays.
85 virtual void WriteHTMLGraph(std::string* output) const = 0; 104 virtual void WriteHTMLGraph(std::string* output) const = 0;
86 virtual void WriteAscii(std::string* output) const = 0; 105 virtual void WriteAscii(std::string* output) const = 0;
87 106
88 // Produce a JSON representation of the histogram. This is implemented with 107 // Produce a JSON representation of the histogram. This is implemented with
89 // the help of GetParameters and GetCountAndBucketData; overwrite them to 108 // the help of GetParameters and GetCountAndBucketData; overwrite them to
90 // customize the output. 109 // customize the output.
91 void WriteJSON(std::string* output) const; 110 void WriteJSON(std::string* output) const;
92 111
93 protected: 112 protected:
113 // Subclasses should implement this function to make SerializeInfo work.
114 virtual bool SerializeInfoImpl(Pickle* pickle) const = 0;
115
94 // Writes information about the construction parameters in |params|. 116 // Writes information about the construction parameters in |params|.
95 virtual void GetParameters(DictionaryValue* params) const = 0; 117 virtual void GetParameters(DictionaryValue* params) const = 0;
96 118
97 // Writes information about the current (non-empty) buckets and their sample 119 // Writes information about the current (non-empty) buckets and their sample
98 // counts to |buckets| and the total sample count to |count|. 120 // counts to |buckets| and the total sample count to |count|.
99 virtual void GetCountAndBucketData(Count* count, 121 virtual void GetCountAndBucketData(Count* count,
100 ListValue* buckets) const = 0; 122 ListValue* buckets) const = 0;
101 private: 123 private:
102 const std::string histogram_name_; 124 const std::string histogram_name_;
103 int32 flags_; 125 int32 flags_;
104 126
105 DISALLOW_COPY_AND_ASSIGN(HistogramBase); 127 DISALLOW_COPY_AND_ASSIGN(HistogramBase);
106 }; 128 };
107 129
108 } // namespace base 130 } // namespace base
109 131
110 #endif // BASE_METRICS_HISTOGRAM_BASE_H_ 132 #endif // BASE_METRICS_HISTOGRAM_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698