Commit cd56dff0 authored by fischman@chromium.org's avatar fischman@chromium.org

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
parent 3adab525
...@@ -239,13 +239,16 @@ std::string Histogram::SerializeHistogramInfo(const Histogram& histogram, ...@@ -239,13 +239,16 @@ std::string Histogram::SerializeHistogramInfo(const Histogram& histogram,
pickle.WriteInt(histogram.flags()); pickle.WriteInt(histogram.flags());
snapshot.Serialize(&pickle); snapshot.Serialize(&pickle);
histogram.SerializeRanges(&pickle);
return std::string(static_cast<const char*>(pickle.data()), pickle.size()); return std::string(static_cast<const char*>(pickle.data()), pickle.size());
} }
// static // static
bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
if (histogram_info.empty()) { if (histogram_info.empty()) {
return false; return false;
} }
Pickle pickle(histogram_info.data(), Pickle pickle(histogram_info.data(),
...@@ -271,6 +274,7 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { ...@@ -271,6 +274,7 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name;
return false; return false;
} }
DCHECK(pickle_flags & kIPCSerializationSourceFlag); DCHECK(pickle_flags & kIPCSerializationSourceFlag);
// Since these fields may have come from an untrusted renderer, do additional // Since these fields may have come from an untrusted renderer, do additional
// checks above and beyond those in Histogram::Initialize() // checks above and beyond those in Histogram::Initialize()
...@@ -294,6 +298,14 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { ...@@ -294,6 +298,14 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
histogram_name, declared_min, declared_max, bucket_count, flags); histogram_name, declared_min, declared_max, bucket_count, flags);
} else if (histogram_type == BOOLEAN_HISTOGRAM) { } else if (histogram_type == BOOLEAN_HISTOGRAM) {
render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); 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 { } else {
DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: "
<< histogram_type; << histogram_type;
...@@ -440,6 +452,10 @@ Histogram::~Histogram() { ...@@ -440,6 +452,10 @@ Histogram::~Histogram() {
DCHECK(ValidateBucketRanges()); DCHECK(ValidateBucketRanges());
} }
bool Histogram::SerializeRanges(Pickle* pickle) const {
return true;
}
// Calculate what range of values are held in each bucket. // 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 // 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 // consecutive buckets that is sooo small, that the integer bounds are the same
...@@ -981,6 +997,24 @@ CustomHistogram::CustomHistogram(const std::string& name, ...@@ -981,6 +997,24 @@ CustomHistogram::CustomHistogram(const std::string& name,
DCHECK_EQ(custom_ranges[0], 0); 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( void CustomHistogram::InitializedCustomBucketRange(
const std::vector<Sample>& custom_ranges) { const std::vector<Sample>& custom_ranges) {
DCHECK_GT(custom_ranges.size(), 1u); DCHECK_GT(custom_ranges.size(), 1u);
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "base/atomicops.h" #include "base/atomicops.h"
#include "base/base_export.h" #include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/time.h" #include "base/time.h"
...@@ -482,6 +483,7 @@ class BASE_EXPORT Histogram { ...@@ -482,6 +483,7 @@ class BASE_EXPORT Histogram {
// Pickle class to flatten the object. // Pickle class to flatten the object.
static std::string SerializeHistogramInfo(const Histogram& histogram, static std::string SerializeHistogramInfo(const Histogram& histogram,
const SampleSet& snapshot); const SampleSet& snapshot);
// The following method accepts a list of pickled histograms and // The following method accepts a list of pickled histograms and
// builds a histogram and updates shadow copy of histogram data in the // builds a histogram and updates shadow copy of histogram data in the
// browser process. // browser process.
...@@ -530,6 +532,12 @@ class BASE_EXPORT Histogram { ...@@ -530,6 +532,12 @@ class BASE_EXPORT Histogram {
virtual ~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_. // Initialize ranges_ mapping in cached_ranges_.
void InitializeBucketRange(); void InitializeBucketRange();
...@@ -739,10 +747,18 @@ class BASE_EXPORT CustomHistogram : public Histogram { ...@@ -739,10 +747,18 @@ class BASE_EXPORT CustomHistogram : public Histogram {
static std::vector<Sample> ArrayToCustomRanges(const Sample* values, static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
size_t num_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: protected:
CustomHistogram(const std::string& name, CustomHistogram(const std::string& name,
const std::vector<Sample>& custom_ranges); const std::vector<Sample>& custom_ranges);
virtual bool SerializeRanges(Pickle* pickle) const OVERRIDE;
// Initialize ranges_ mapping in cached_ranges_. // Initialize ranges_ mapping in cached_ranges_.
void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges); void InitializedCustomBucketRange(const std::vector<Sample>& custom_ranges);
virtual double GetBucketSize(Count current, size_t i) const; virtual double GetBucketSize(Count current, size_t i) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment