summaryrefslogtreecommitdiffstats
path: root/base/histogram.h
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 22:39:55 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 22:39:55 +0000
commit70cc56e458e6195caf02ceeb81d335c124be76c1 (patch)
treecf3afb2cc8a81c7fbacf970b965f418770a8e597 /base/histogram.h
parent762f386d2816478c19c15469ec4efb887df2db0f (diff)
downloadchromium_src-70cc56e458e6195caf02ceeb81d335c124be76c1.zip
chromium_src-70cc56e458e6195caf02ceeb81d335c124be76c1.tar.gz
chromium_src-70cc56e458e6195caf02ceeb81d335c124be76c1.tar.bz2
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
Diffstat (limited to 'base/histogram.h')
-rw-r--r--base/histogram.h51
1 files changed, 46 insertions, 5 deletions
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<Histogram> 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<Histogram> 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> {
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<Histogram> FactoryGet(const std::string& name,
+ const std::vector<int>& custom_ranges, Flags flags);
+
+ protected:
+ CustomHistogram(const std::string& name,
+ const std::vector<int>& 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<int>* 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.