diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-13 04:19:15 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-13 04:19:15 +0000 |
commit | cd56dff09800161fbdbf690995babdf861770c5b (patch) | |
tree | f6ce487311dd8eadee2681330959fc68a496eb25 /base/metrics | |
parent | 3adab52539491a995d90a4cdfae50519e71b9d7f (diff) | |
download | chromium_src-cd56dff09800161fbdbf690995babdf861770c5b.zip chromium_src-cd56dff09800161fbdbf690995babdf861770c5b.tar.gz chromium_src-cd56dff09800161fbdbf690995babdf861770c5b.tar.bz2 |
Support using UMA_HISTOGRAM_CUSTOM_ENUMERATION from the renderer.
BUG=103633
TEST=trybots & manually checking that chrome://histograms/Aspect now shows the two custom enum histograms from r108951, with correctly specific buckets.
Review URL: http://codereview.chromium.org/8506038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/metrics')
-rw-r--r-- | base/metrics/histogram.cc | 36 | ||||
-rw-r--r-- | base/metrics/histogram.h | 16 |
2 files changed, 51 insertions, 1 deletions
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc index 7077b09..a44a2eb 100644 --- a/base/metrics/histogram.cc +++ b/base/metrics/histogram.cc @@ -239,13 +239,16 @@ std::string Histogram::SerializeHistogramInfo(const Histogram& histogram, pickle.WriteInt(histogram.flags()); snapshot.Serialize(&pickle); + + histogram.SerializeRanges(&pickle); + return std::string(static_cast<const char*>(pickle.data()), pickle.size()); } // static bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { if (histogram_info.empty()) { - return false; + return false; } Pickle pickle(histogram_info.data(), @@ -271,6 +274,7 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; return false; } + DCHECK(pickle_flags & kIPCSerializationSourceFlag); // Since these fields may have come from an untrusted renderer, do additional // checks above and beyond those in Histogram::Initialize() @@ -294,6 +298,14 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { histogram_name, declared_min, declared_max, bucket_count, flags); } else if (histogram_type == BOOLEAN_HISTOGRAM) { render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); + } else if (histogram_type == CUSTOM_HISTOGRAM) { + std::vector<Histogram::Sample> sample_ranges(bucket_count); + if (!CustomHistogram::DeserializeRanges(&iter, pickle, &sample_ranges)) { + DLOG(ERROR) << "Pickle error decoding ranges: " << histogram_name; + return false; + } + render_histogram = + CustomHistogram::FactoryGet(histogram_name, sample_ranges, flags); } else { DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " << histogram_type; @@ -440,6 +452,10 @@ Histogram::~Histogram() { DCHECK(ValidateBucketRanges()); } +bool Histogram::SerializeRanges(Pickle* pickle) const { + return true; +} + // Calculate what range of values are held in each bucket. // We have to be careful that we don't pick a ratio between starting points in // consecutive buckets that is sooo small, that the integer bounds are the same @@ -981,6 +997,24 @@ CustomHistogram::CustomHistogram(const std::string& name, DCHECK_EQ(custom_ranges[0], 0); } +bool CustomHistogram::SerializeRanges(Pickle* pickle) const { + for (size_t i = 0; i < cached_ranges()->size(); ++i) { + if (!pickle->WriteInt(cached_ranges()->ranges(i))) + return false; + } + return true; +} + +// static +bool CustomHistogram::DeserializeRanges( + void** iter, const Pickle& pickle, std::vector<Histogram::Sample>* ranges) { + for (size_t i = 0; i < ranges->size(); ++i) { + if (!pickle.ReadInt(iter, &(*ranges)[i])) + return false; + } + return true; +} + void CustomHistogram::InitializedCustomBucketRange( const std::vector<Sample>& custom_ranges) { DCHECK_GT(custom_ranges.size(), 1u); diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h index e5f0d04..115c9d8 100644 --- a/base/metrics/histogram.h +++ b/base/metrics/histogram.h @@ -48,6 +48,7 @@ #include "base/atomicops.h" #include "base/base_export.h" +#include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/logging.h" #include "base/time.h" @@ -482,6 +483,7 @@ class BASE_EXPORT Histogram { // Pickle class to flatten the object. static std::string SerializeHistogramInfo(const Histogram& histogram, const SampleSet& snapshot); + // The following method accepts a list of pickled histograms and // builds a histogram and updates shadow copy of histogram data in the // browser process. @@ -530,6 +532,12 @@ class BASE_EXPORT Histogram { virtual ~Histogram(); + // Serialize the histogram's ranges to |*pickle|, returning true on success. + // Most subclasses can leave this no-op implementation, but some will want to + // override it, especially if the ranges cannot be re-derived from other + // serialized parameters. + virtual bool SerializeRanges(Pickle* pickle) const; + // Initialize ranges_ mapping in cached_ranges_. void InitializeBucketRange(); @@ -739,10 +747,18 @@ class BASE_EXPORT CustomHistogram : public Histogram { static std::vector<Sample> ArrayToCustomRanges(const Sample* values, size_t num_values); + // Helper for deserializing CustomHistograms. |*ranges| should already be + // correctly sized before this call. Return true on success. + static bool DeserializeRanges(void** iter, const Pickle& pickle, + std::vector<Histogram::Sample>* ranges); + + protected: CustomHistogram(const std::string& name, const std::vector<Sample>& custom_ranges); + virtual bool SerializeRanges(Pickle* pickle) const OVERRIDE; + // Initialize ranges_ mapping in cached_ranges_. void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); virtual double GetBucketSize(Count current, size_t i) const; |