From 70cc56e458e6195caf02ceeb81d335c124be76c1 Mon Sep 17 00:00:00 2001 From: "jar@chromium.org" Date: Thu, 29 Apr 2010 22:39:55 +0000 Subject: Extend Histogram class to support custom range definitions Some users have a small sparsely separated enumerated list of plausible samples which don't fit well into a default (log space) histogarm, or a consistently spaced (LinearHistogram). This implementation does not yet support renderer histograms of this sort, but it at least unblocks the dependent bug that needs support for these sparse histograms in the browser. The bulk of this patch was written by Raman Tenetti, in CL 1706012. BUG=40953 r=eroman Review URL: http://codereview.chromium.org/1737017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45998 0039d316-1c4b-4281-b951-d872f2087c98 --- base/histogram.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'base/histogram.h') diff --git a/base/histogram.h b/base/histogram.h index f16dde0..1737b85 100644 --- a/base/histogram.h +++ b/base/histogram.h @@ -90,6 +90,12 @@ counter->Add(sample); \ } while (0) +#define HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ + static scoped_refptr counter = CustomHistogram::FactoryGet( \ + name, custom_ranges, Histogram::kNoFlags); \ + counter->Add(sample); \ + } while (0) + //------------------------------------------------------------------------------ // Define Debug vs non-debug flavors of macros. @@ -107,6 +113,8 @@ HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \ HISTOGRAM_ENUMERATION(name, sample, boundary_value) +#define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ + HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) #else // NDEBUG @@ -120,6 +128,8 @@ #define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ do {} while (0) #define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) do {} while (0) +#define DHISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ + do {} while (0) #endif // NDEBUG @@ -186,13 +196,19 @@ counter->Add(sample); \ } while (0) +#define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) do { \ + static scoped_refptr counter = CustomHistogram::FactoryGet( \ + name, custom_ranges, Histogram::kUmaTargetedHistogramFlag); \ + counter->Add(sample); \ + } while (0) //------------------------------------------------------------------------------ -class Pickle; +class BooleanHistogram; +class CustomHistogram; class Histogram; class LinearHistogram; -class BooleanHistogram; +class Pickle; namespace disk_cache { class StatsHistogram; @@ -214,12 +230,14 @@ class Histogram : public base::RefCountedThreadSafe { HISTOGRAM, LINEAR_HISTOGRAM, BOOLEAN_HISTOGRAM, + CUSTOM_HISTOGRAM, NOT_VALID_IN_RENDERER }; enum BucketLayout { EXPONENTIAL, - LINEAR + LINEAR, + CUSTOM }; enum Flags { @@ -482,8 +500,6 @@ class LinearHistogram : public Histogram { LinearHistogram(const std::string& name, base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count); - virtual ~LinearHistogram() {} - // Initialize ranges_ mapping. virtual void InitializeBucketRange(); virtual double GetBucketSize(Count current, size_t i) const; @@ -527,6 +543,31 @@ class BooleanHistogram : public LinearHistogram { }; //------------------------------------------------------------------------------ + +// CustomHistogram is a histogram for a set of custom integers. +class CustomHistogram : public Histogram { + public: + virtual ClassType histogram_type() const { return CUSTOM_HISTOGRAM; } + + static scoped_refptr FactoryGet(const std::string& name, + const std::vector& custom_ranges, Flags flags); + + protected: + CustomHistogram(const std::string& name, + const std::vector& custom_ranges); + + // Initialize ranges_ mapping. + virtual void InitializeBucketRange(); + virtual double GetBucketSize(Count current, size_t i) const; + + private: + // Temporary pointer used during construction/initialization, and then NULLed. + const std::vector* ranges_vector_; + + DISALLOW_COPY_AND_ASSIGN(CustomHistogram); +}; + +//------------------------------------------------------------------------------ // StatisticsRecorder handles all histograms in the system. It provides a // general place for histograms to register, and supports a global API for // accessing (i.e., dumping, or graphing) the data in all the histograms. -- cgit v1.1