From ec0c0aa43dd73b963ec3be403f337693737c6f8e Mon Sep 17 00:00:00 2001 From: "rtenneti@google.com" Date: Tue, 14 Aug 2012 02:02:00 +0000 Subject: Histogram - Checks to cacth corruption in bucket ranges when histogram is created. We will back out this change. This is temporary to catch corruptions as early as possible. TBR=jar,kaiwang TEST=base unittests BUG=140688 Review URL: https://chromiumcodereview.appspot.com/10826293 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151415 0039d316-1c4b-4281-b951-d872f2087c98 --- base/metrics/histogram.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'base/metrics') diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc index ca2e4d9..dddb5ee 100644 --- a/base/metrics/histogram.cc +++ b/base/metrics/histogram.cc @@ -14,9 +14,12 @@ #include #include +#include "base/compiler_specific.h" +#include "base/debug/alias.h" #include "base/logging.h" #include "base/metrics/statistics_recorder.h" #include "base/pickle.h" +#include "base/string_util.h" #include "base/stringprintf.h" #include "base/synchronization/lock.h" @@ -129,6 +132,29 @@ bool Histogram::SampleSet::Deserialize(PickleIterator* iter) { return count == redundant_count_; } +// TODO(rtenneti): delete this code after debugging. +void CheckCorruption(const Histogram& histogram) { + const std::string& histogram_name = histogram.histogram_name(); + char histogram_name_buf[128]; + base::strlcpy(histogram_name_buf, + histogram_name.c_str(), + arraysize(histogram_name_buf)); + base::debug::Alias(histogram_name_buf); + + Sample previous_range = -1; // Bottom range is always 0. + for (size_t index = 0; index < histogram.bucket_count(); ++index) { + int new_range = histogram.ranges(index); + if (previous_range >= new_range) { + CHECK(false); // Crash for the bucket order corruption. + } + previous_range = new_range; + } + + if (!histogram.bucket_ranges()->HasValidChecksum()) { + CHECK(false); // Crash for the checksum corruption. + } +} + Histogram* Histogram::FactoryGet(const string& name, Sample minimum, Sample maximum, @@ -152,6 +178,8 @@ Histogram* Histogram::FactoryGet(const string& name, histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); } + // TODO(rtenneti): delete this code after debugging. + CheckCorruption(*histogram); CHECK_EQ(HISTOGRAM, histogram->histogram_type()); CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); @@ -704,6 +732,8 @@ Histogram* LinearHistogram::FactoryGet(const string& name, histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); } + // TODO(rtenneti): delete this code after debugging. + CheckCorruption(*histogram); CHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); @@ -795,6 +825,8 @@ Histogram* BooleanHistogram::FactoryGet(const string& name, int32 flags) { histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); } + // TODO(rtenneti): delete this code after debugging. + CheckCorruption(*histogram); CHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); return histogram; @@ -835,6 +867,8 @@ Histogram* CustomHistogram::FactoryGet(const string& name, histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); } + // TODO(rtenneti): delete this code after debugging. + CheckCorruption(*histogram); CHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); return histogram; -- cgit v1.1