| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 211     // that fit into each bucket. | 211     // that fit into each bucket. | 
| 212     Counts counts_; | 212     Counts counts_; | 
| 213 | 213 | 
| 214     // Save simple stats locally.  Note that this MIGHT get done in base class | 214     // Save simple stats locally.  Note that this MIGHT get done in base class | 
| 215     // without shared memory at some point. | 215     // without shared memory at some point. | 
| 216     int64 sum_;         // sum of samples. | 216     int64 sum_;         // sum of samples. | 
| 217     int64 square_sum_;  // sum of squares of samples. | 217     int64 square_sum_;  // sum of squares of samples. | 
| 218   }; | 218   }; | 
| 219   //---------------------------------------------------------------------------- | 219   //---------------------------------------------------------------------------- | 
| 220 | 220 | 
| 221   Histogram(const wchar_t* name, Sample minimum, | 221   Histogram(const char* name, Sample minimum, | 
| 222             Sample maximum, size_t bucket_count); | 222             Sample maximum, size_t bucket_count); | 
| 223   Histogram(const wchar_t* name, base::TimeDelta minimum, | 223   Histogram(const char* name, base::TimeDelta minimum, | 
| 224             base::TimeDelta maximum, size_t bucket_count); | 224             base::TimeDelta maximum, size_t bucket_count); | 
| 225   virtual ~Histogram(); | 225   virtual ~Histogram(); | 
| 226 | 226 | 
| 227   // Hooks to override stats counter methods.  This ensures that we gather all | 227   // Hooks to override stats counter methods.  This ensures that we gather all | 
| 228   // input the stats counter sees. | 228   // input the stats counter sees. | 
| 229   virtual void Add(int value); | 229   virtual void Add(int value); | 
| 230 | 230 | 
| 231   // The following methods provide graphical histogram displays. | 231   // The following methods provide graphical histogram displays. | 
| 232   void WriteHTMLGraph(std::string* output) const; | 232   void WriteHTMLGraph(std::string* output) const; | 
| 233   void WriteAscii(bool graph_it, const std::string& newline, | 233   void WriteAscii(bool graph_it, const std::string& newline, | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 350 //------------------------------------------------------------------------------ | 350 //------------------------------------------------------------------------------ | 
| 351 | 351 | 
| 352 // LinearHistogram is a more traditional histogram, with evenly spaced | 352 // LinearHistogram is a more traditional histogram, with evenly spaced | 
| 353 // buckets. | 353 // buckets. | 
| 354 class LinearHistogram : public Histogram { | 354 class LinearHistogram : public Histogram { | 
| 355  public: | 355  public: | 
| 356   struct DescriptionPair { | 356   struct DescriptionPair { | 
| 357     Sample sample; | 357     Sample sample; | 
| 358     const char* description;  // Null means end of a list of pairs. | 358     const char* description;  // Null means end of a list of pairs. | 
| 359   }; | 359   }; | 
| 360   LinearHistogram(const wchar_t* name, Sample minimum, | 360   LinearHistogram(const char* name, Sample minimum, | 
| 361             Sample maximum, size_t bucket_count); | 361             Sample maximum, size_t bucket_count); | 
| 362   LinearHistogram(const wchar_t* name, base::TimeDelta minimum, | 362   LinearHistogram(const char* name, base::TimeDelta minimum, | 
| 363             base::TimeDelta maximum, size_t bucket_count); | 363             base::TimeDelta maximum, size_t bucket_count); | 
| 364   ~LinearHistogram() {} | 364   ~LinearHistogram() {} | 
| 365 | 365 | 
| 366   // Store a list of number/text values for use in rendering the histogram. | 366   // Store a list of number/text values for use in rendering the histogram. | 
| 367   // The last element in the array has a null in its "description" slot. | 367   // The last element in the array has a null in its "description" slot. | 
| 368   void SetRangeDescriptions(const DescriptionPair descriptions[]); | 368   void SetRangeDescriptions(const DescriptionPair descriptions[]); | 
| 369 | 369 | 
| 370  protected: | 370  protected: | 
| 371   // Initialize ranges_ mapping. | 371   // Initialize ranges_ mapping. | 
| 372   virtual void InitializeBucketRange(); | 372   virtual void InitializeBucketRange(); | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 390   BucketDescriptionMap bucket_description_; | 390   BucketDescriptionMap bucket_description_; | 
| 391 | 391 | 
| 392   DISALLOW_EVIL_CONSTRUCTORS(LinearHistogram); | 392   DISALLOW_EVIL_CONSTRUCTORS(LinearHistogram); | 
| 393 }; | 393 }; | 
| 394 | 394 | 
| 395 //------------------------------------------------------------------------------ | 395 //------------------------------------------------------------------------------ | 
| 396 | 396 | 
| 397 // BooleanHistogram is a histogram for booleans. | 397 // BooleanHistogram is a histogram for booleans. | 
| 398 class BooleanHistogram : public LinearHistogram { | 398 class BooleanHistogram : public LinearHistogram { | 
| 399  public: | 399  public: | 
| 400   explicit BooleanHistogram(const wchar_t* name) | 400   explicit BooleanHistogram(const char* name) | 
| 401     : LinearHistogram(name, 0, 2, 3) { | 401     : LinearHistogram(name, 0, 2, 3) { | 
| 402   } | 402   } | 
| 403 | 403 | 
| 404   virtual void AddBoolean(bool value) { Add(value ? 1 : 0); } | 404   virtual void AddBoolean(bool value) { Add(value ? 1 : 0); } | 
| 405 | 405 | 
| 406  private: | 406  private: | 
| 407   DISALLOW_EVIL_CONSTRUCTORS(BooleanHistogram); | 407   DISALLOW_EVIL_CONSTRUCTORS(BooleanHistogram); | 
| 408 }; | 408 }; | 
| 409 | 409 | 
| 410 //------------------------------------------------------------------------------ | 410 //------------------------------------------------------------------------------ | 
| 411 // This section provides implementation for ThreadSafeHistogram. | 411 // This section provides implementation for ThreadSafeHistogram. | 
| 412 //------------------------------------------------------------------------------ | 412 //------------------------------------------------------------------------------ | 
| 413 | 413 | 
| 414 class ThreadSafeHistogram : public Histogram { | 414 class ThreadSafeHistogram : public Histogram { | 
| 415  public: | 415  public: | 
| 416   ThreadSafeHistogram(const wchar_t* name, Sample minimum, | 416   ThreadSafeHistogram(const char* name, Sample minimum, | 
| 417                       Sample maximum, size_t bucket_count); | 417                       Sample maximum, size_t bucket_count); | 
| 418 | 418 | 
| 419   // Provide the analog to Add() | 419   // Provide the analog to Add() | 
| 420   void Remove(int value); | 420   void Remove(int value); | 
| 421 | 421 | 
| 422  protected: | 422  protected: | 
| 423   // Provide locked versions to get precise counts. | 423   // Provide locked versions to get precise counts. | 
| 424   virtual void Accumulate(Sample value, Count count, size_t index); | 424   virtual void Accumulate(Sample value, Count count, size_t index); | 
| 425 | 425 | 
| 426   virtual void SnapshotSample(SampleSet* sample); | 426   virtual void SnapshotSample(SampleSet* sample); | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 478   // lock protects access to the above map. | 478   // lock protects access to the above map. | 
| 479   static Lock* lock_; | 479   static Lock* lock_; | 
| 480 | 480 | 
| 481   // Dump all known histograms to log. | 481   // Dump all known histograms to log. | 
| 482   static bool dump_on_exit_; | 482   static bool dump_on_exit_; | 
| 483 | 483 | 
| 484   DISALLOW_EVIL_CONSTRUCTORS(StatisticsRecorder); | 484   DISALLOW_EVIL_CONSTRUCTORS(StatisticsRecorder); | 
| 485 }; | 485 }; | 
| 486 | 486 | 
| 487 #endif  // BASE_HISTOGRAM_H__ | 487 #endif  // BASE_HISTOGRAM_H__ | 
| 488 |  | 
| OLD | NEW | 
|---|