diff options
author | rtenneti@google.com <rtenneti@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-14 02:02:00 +0000 |
---|---|---|
committer | rtenneti@google.com <rtenneti@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-14 02:02:00 +0000 |
commit | ec0c0aa43dd73b963ec3be403f337693737c6f8e (patch) | |
tree | 8b60fcc1258847742ba22ab5859b68ec2238efc1 /base/metrics | |
parent | 3cdbc0361acb001e7de1ea8a1a9f11f32a73374f (diff) | |
download | chromium_src-ec0c0aa43dd73b963ec3be403f337693737c6f8e.zip chromium_src-ec0c0aa43dd73b963ec3be403f337693737c6f8e.tar.gz chromium_src-ec0c0aa43dd73b963ec3be403f337693737c6f8e.tar.bz2 |
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
Diffstat (limited to 'base/metrics')
-rw-r--r-- | base/metrics/histogram.cc | 34 |
1 files changed, 34 insertions, 0 deletions
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 <algorithm> #include <string> +#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; |