Chromium Code Reviews| Index: chrome/test/base/uma_histogram_helper.cc |
| diff --git a/chrome/test/base/uma_histogram_helper.cc b/chrome/test/base/uma_histogram_helper.cc |
| index 9b5122974bb6cc4ede50a82bc235d7b83f0a3c45..37ba5ca8a19717c7b96ec037b9c6eb274a1514a8 100644 |
| --- a/chrome/test/base/uma_histogram_helper.cc |
| +++ b/chrome/test/base/uma_histogram_helper.cc |
| @@ -11,6 +11,22 @@ |
| #include "content/public/browser/histogram_fetcher.h" |
| UMAHistogramHelper::UMAHistogramHelper() { |
| + base::StatisticsRecorder::Initialize(); |
| +} |
| + |
| +void UMAHistogramHelper::PrepareSnapshot(const char** histogram_names, |
| + int num_histograms) { |
| + for (int i = 0; i < num_histograms; i++) { |
| + std::string histogram_name = histogram_names[i]; |
| + |
| + base::HistogramBase* histogram = |
| + base::StatisticsRecorder::FindHistogram(histogram_name); |
| + // If there is no histogram present, then don't record a snapshot. The logic |
| + // in the Expect* methods will act to treat no histogram equivalent to |
| + // samples with zeros. |
| + if (histogram) |
| + histogram_snapshots[histogram_name] = histogram->SnapshotSamples(); |
| + } |
| } |
| void UMAHistogramHelper::Fetch() { |
| @@ -82,18 +98,33 @@ void UMAHistogramHelper::CheckBucketCount( |
| base::HistogramBase::Sample sample, |
| base::HistogramBase::Count expected_count, |
| base::HistogramSamples& samples) { |
| - EXPECT_EQ(expected_count, samples.GetCount(sample)) |
| + int actual_count; |
| + if (histogram_snapshots.count(name)) { |
| + actual_count = samples.GetCount(sample) - |
| + histogram_snapshots[name]->GetCount(sample); |
| + } else { |
| + actual_count = samples.GetCount(sample); |
| + } |
| + EXPECT_EQ(expected_count, actual_count) |
| << "Histogram \"" << name |
| << "\" does not have the right number of samples (" << expected_count |
| - << ") in the expected bucket (" << sample << ")."; |
| + << ") in the expected bucket (" << sample << "). It has (" |
| + << actual_count << ")."; |
| } |
| void UMAHistogramHelper::CheckTotalCount( |
| const std::string& name, |
| base::HistogramBase::Count expected_count, |
| base::HistogramSamples& samples) { |
| - EXPECT_EQ(expected_count, samples.TotalCount()) |
| + int actual_count; |
| + if (histogram_snapshots.count(name)) { |
|
Alexei Svitkine (slow)
2014/06/12 17:09:11
Nit: How about:
int actual_count = samples.TotalC
Mike Lerman
2014/06/12 18:12:15
Slick. Done.
|
| + actual_count = samples.TotalCount() - |
| + histogram_snapshots[name]->TotalCount(); |
| + } else { |
| + actual_count = samples.TotalCount(); |
| + } |
| + EXPECT_EQ(expected_count, actual_count) |
| << "Histogram \"" << name |
| << "\" does not have the right total number of samples (" |
| - << expected_count << ")."; |
| + << expected_count << "). It has (" << actual_count << ")."; |
| } |