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

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

Issue 1149113006: Move Pickle to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « base/files/file_path.h ('k') | base/metrics/histogram_base.h » ('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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 8
9 // It supports calls to accumulate either time intervals (which are processed 9 // It supports calls to accumulate either time intervals (which are processed
10 // as integral number of milliseconds), or arbitrary integral units. 10 // as integral number of milliseconds), or arbitrary integral units.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #include "base/gtest_prod_util.h" 76 #include "base/gtest_prod_util.h"
77 #include "base/logging.h" 77 #include "base/logging.h"
78 #include "base/memory/scoped_ptr.h" 78 #include "base/memory/scoped_ptr.h"
79 #include "base/metrics/bucket_ranges.h" 79 #include "base/metrics/bucket_ranges.h"
80 #include "base/metrics/histogram_base.h" 80 #include "base/metrics/histogram_base.h"
81 // TODO(asvitkine): Migrate callers to to include this directly and remove this. 81 // TODO(asvitkine): Migrate callers to to include this directly and remove this.
82 #include "base/metrics/histogram_macros.h" 82 #include "base/metrics/histogram_macros.h"
83 #include "base/metrics/histogram_samples.h" 83 #include "base/metrics/histogram_samples.h"
84 #include "base/time/time.h" 84 #include "base/time/time.h"
85 85
86 class Pickle;
87 class PickleIterator;
88
89 namespace base { 86 namespace base {
90 87
91 class BooleanHistogram; 88 class BooleanHistogram;
92 class CustomHistogram; 89 class CustomHistogram;
93 class Histogram; 90 class Histogram;
94 class LinearHistogram; 91 class LinearHistogram;
92 class Pickle;
93 class PickleIterator;
95 class SampleVector; 94 class SampleVector;
96 95
97 class BASE_EXPORT Histogram : public HistogramBase { 96 class BASE_EXPORT Histogram : public HistogramBase {
98 public: 97 public:
99 // Initialize maximum number of buckets in histograms as 16,384. 98 // Initialize maximum number of buckets in histograms as 16,384.
100 static const size_t kBucketCount_MAX; 99 static const size_t kBucketCount_MAX;
101 100
102 typedef std::vector<Count> Counts; 101 typedef std::vector<Count> Counts;
103 102
104 //---------------------------------------------------------------------------- 103 //----------------------------------------------------------------------------
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 size_t* bucket_count); 162 size_t* bucket_count);
164 163
165 // HistogramBase implementation: 164 // HistogramBase implementation:
166 HistogramType GetHistogramType() const override; 165 HistogramType GetHistogramType() const override;
167 bool HasConstructionArguments(Sample expected_minimum, 166 bool HasConstructionArguments(Sample expected_minimum,
168 Sample expected_maximum, 167 Sample expected_maximum,
169 size_t expected_bucket_count) const override; 168 size_t expected_bucket_count) const override;
170 void Add(Sample value) override; 169 void Add(Sample value) override;
171 scoped_ptr<HistogramSamples> SnapshotSamples() const override; 170 scoped_ptr<HistogramSamples> SnapshotSamples() const override;
172 void AddSamples(const HistogramSamples& samples) override; 171 void AddSamples(const HistogramSamples& samples) override;
173 bool AddSamplesFromPickle(PickleIterator* iter) override; 172 bool AddSamplesFromPickle(base::PickleIterator* iter) override;
174 void WriteHTMLGraph(std::string* output) const override; 173 void WriteHTMLGraph(std::string* output) const override;
175 void WriteAscii(std::string* output) const override; 174 void WriteAscii(std::string* output) const override;
176 175
177 protected: 176 protected:
178 // |ranges| should contain the underflow and overflow buckets. See top 177 // |ranges| should contain the underflow and overflow buckets. See top
179 // comments for example. 178 // comments for example.
180 Histogram(const std::string& name, 179 Histogram(const std::string& name,
181 Sample minimum, 180 Sample minimum,
182 Sample maximum, 181 Sample maximum,
183 const BucketRanges* ranges); 182 const BucketRanges* ranges);
184 183
185 ~Histogram() override; 184 ~Histogram() override;
186 185
187 // HistogramBase implementation: 186 // HistogramBase implementation:
188 bool SerializeInfoImpl(Pickle* pickle) const override; 187 bool SerializeInfoImpl(base::Pickle* pickle) const override;
189 188
190 // Method to override to skip the display of the i'th bucket if it's empty. 189 // Method to override to skip the display of the i'th bucket if it's empty.
191 virtual bool PrintEmptyBucket(size_t index) const; 190 virtual bool PrintEmptyBucket(size_t index) const;
192 191
193 // Get normalized size, relative to the ranges(i). 192 // Get normalized size, relative to the ranges(i).
194 virtual double GetBucketSize(Count current, size_t i) const; 193 virtual double GetBucketSize(Count current, size_t i) const;
195 194
196 // Return a string description of what goes in a given bucket. 195 // Return a string description of what goes in a given bucket.
197 // Most commonly this is the numeric value, but in derived classes it may 196 // Most commonly this is the numeric value, but in derived classes it may
198 // be a name (or string description) given to the bucket. 197 // be a name (or string description) given to the bucket.
199 virtual const std::string GetAsciiBucketRange(size_t it) const; 198 virtual const std::string GetAsciiBucketRange(size_t it) const;
200 199
201 private: 200 private:
202 // Allow tests to corrupt our innards for testing purposes. 201 // Allow tests to corrupt our innards for testing purposes.
203 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BoundsTest); 202 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BoundsTest);
204 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest); 203 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest);
205 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds); 204 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds);
206 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); 205 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
207 FRIEND_TEST_ALL_PREFIXES(HistogramTest, NameMatchTest); 206 FRIEND_TEST_ALL_PREFIXES(HistogramTest, NameMatchTest);
208 207
209 friend class StatisticsRecorder; // To allow it to delete duplicates. 208 friend class StatisticsRecorder; // To allow it to delete duplicates.
210 friend class StatisticsRecorderTest; 209 friend class StatisticsRecorderTest;
211 210
212 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( 211 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
213 PickleIterator* iter); 212 base::PickleIterator* iter);
214 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); 213 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
215 214
216 // Implementation of SnapshotSamples function. 215 // Implementation of SnapshotSamples function.
217 scoped_ptr<SampleVector> SnapshotSampleVector() const; 216 scoped_ptr<SampleVector> SnapshotSampleVector() const;
218 217
219 //---------------------------------------------------------------------------- 218 //----------------------------------------------------------------------------
220 // Helpers for emitting Ascii graphic. Each method appends data to output. 219 // Helpers for emitting Ascii graphic. Each method appends data to output.
221 220
222 void WriteAsciiImpl(bool graph_it, 221 void WriteAsciiImpl(bool graph_it,
223 const std::string& newline, 222 const std::string& newline,
224 std::string* output) const; 223 std::string* output) const;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // If we have a description for a bucket, then return that. Otherwise 313 // If we have a description for a bucket, then return that. Otherwise
315 // let parent class provide a (numeric) description. 314 // let parent class provide a (numeric) description.
316 const std::string GetAsciiBucketRange(size_t i) const override; 315 const std::string GetAsciiBucketRange(size_t i) const override;
317 316
318 // Skip printing of name for numeric range if we have a name (and if this is 317 // Skip printing of name for numeric range if we have a name (and if this is
319 // an empty bucket). 318 // an empty bucket).
320 bool PrintEmptyBucket(size_t index) const override; 319 bool PrintEmptyBucket(size_t index) const override;
321 320
322 private: 321 private:
323 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( 322 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
324 PickleIterator* iter); 323 base::PickleIterator* iter);
325 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); 324 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
326 325
327 // For some ranges, we store a printable description of a bucket range. 326 // For some ranges, we store a printable description of a bucket range.
328 // If there is no description, then GetAsciiBucketRange() uses parent class 327 // If there is no description, then GetAsciiBucketRange() uses parent class
329 // to provide a description. 328 // to provide a description.
330 typedef std::map<Sample, std::string> BucketDescriptionMap; 329 typedef std::map<Sample, std::string> BucketDescriptionMap;
331 BucketDescriptionMap bucket_description_; 330 BucketDescriptionMap bucket_description_;
332 331
333 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); 332 DISALLOW_COPY_AND_ASSIGN(LinearHistogram);
334 }; 333 };
335 334
336 //------------------------------------------------------------------------------ 335 //------------------------------------------------------------------------------
337 336
338 // BooleanHistogram is a histogram for booleans. 337 // BooleanHistogram is a histogram for booleans.
339 class BASE_EXPORT BooleanHistogram : public LinearHistogram { 338 class BASE_EXPORT BooleanHistogram : public LinearHistogram {
340 public: 339 public:
341 static HistogramBase* FactoryGet(const std::string& name, int32 flags); 340 static HistogramBase* FactoryGet(const std::string& name, int32 flags);
342 341
343 HistogramType GetHistogramType() const override; 342 HistogramType GetHistogramType() const override;
344 343
345 private: 344 private:
346 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 345 BooleanHistogram(const std::string& name, const BucketRanges* ranges);
347 346
348 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( 347 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
349 PickleIterator* iter); 348 base::PickleIterator* iter);
350 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); 349 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
351 350
352 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); 351 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
353 }; 352 };
354 353
355 //------------------------------------------------------------------------------ 354 //------------------------------------------------------------------------------
356 355
357 // CustomHistogram is a histogram for a set of custom integers. 356 // CustomHistogram is a histogram for a set of custom integers.
358 class BASE_EXPORT CustomHistogram : public Histogram { 357 class BASE_EXPORT CustomHistogram : public Histogram {
359 public: 358 public:
360 // |custom_ranges| contains a vector of limits on ranges. Each limit should be 359 // |custom_ranges| contains a vector of limits on ranges. Each limit should be
(...skipping 13 matching lines...) Expand all
374 // valid sample value (unless the next higher sample is also a valid value), 373 // valid sample value (unless the next higher sample is also a valid value),
375 // so that invalid samples never fall into the same bucket as valid samples. 374 // so that invalid samples never fall into the same bucket as valid samples.
376 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 375 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
377 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 376 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
378 size_t num_values); 377 size_t num_values);
379 protected: 378 protected:
380 CustomHistogram(const std::string& name, 379 CustomHistogram(const std::string& name,
381 const BucketRanges* ranges); 380 const BucketRanges* ranges);
382 381
383 // HistogramBase implementation: 382 // HistogramBase implementation:
384 bool SerializeInfoImpl(Pickle* pickle) const override; 383 bool SerializeInfoImpl(base::Pickle* pickle) const override;
385 384
386 double GetBucketSize(Count current, size_t i) const override; 385 double GetBucketSize(Count current, size_t i) const override;
387 386
388 private: 387 private:
389 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( 388 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
390 PickleIterator* iter); 389 base::PickleIterator* iter);
391 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); 390 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
392 391
393 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 392 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
394 static BucketRanges* CreateBucketRangesFromCustomRanges( 393 static BucketRanges* CreateBucketRangesFromCustomRanges(
395 const std::vector<Sample>& custom_ranges); 394 const std::vector<Sample>& custom_ranges);
396 395
397 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 396 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
398 }; 397 };
399 398
400 } // namespace base 399 } // namespace base
401 400
402 #endif // BASE_METRICS_HISTOGRAM_H_ 401 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « base/files/file_path.h ('k') | base/metrics/histogram_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698