Chromium Code Reviews| Index: base/test/histogram_tester.cc |
| diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc |
| index ea738b0557b6e864a7e68c7d840c079d5c5967d8..3ca7515b1046c94d50a238962a125bad434c6513 100644 |
| --- a/base/test/histogram_tester.cc |
| +++ b/base/test/histogram_tester.cc |
| @@ -4,10 +4,15 @@ |
| #include "base/test/histogram_tester.h" |
| +#include <algorithm> |
| +#include <vector> |
| + |
| #include "base/metrics/histogram.h" |
| #include "base/metrics/histogram_samples.h" |
| #include "base/metrics/statistics_recorder.h" |
| #include "base/stl_util.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace base { |
| @@ -73,6 +78,45 @@ void HistogramTester::ExpectTotalCount(const std::string& name, |
| } |
| } |
| +std::string HistogramTester::GetTotalCountsForQuery( |
| + const std::string& query) const { |
| + EXPECT_TRUE(query.find('.') != std::string::npos) |
| + << "|query| ought to contain at least one period, to avoid matching too" |
| + << " many histograms."; |
|
Ilya Sherman
2015/06/23 00:57:40
nit: Perhaps output the query?
|
| + |
| + std::vector<std::string> result; |
| + StatisticsRecorder::Histograms histograms; |
| + StatisticsRecorder::GetSnapshot(query, &histograms); |
| + for (base::HistogramBase* histogram : histograms) { |
| + scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
| + auto old_histogram = histograms_snapshot_.find(histogram->histogram_name()); |
| + if (old_histogram != histograms_snapshot_.end()) |
| + samples->Subtract(*old_histogram->second); |
| + |
| + if (histogram->GetHistogramType() == LINEAR_HISTOGRAM || |
| + histogram->GetHistogramType() == BOOLEAN_HISTOGRAM) { |
| + for (scoped_ptr<SampleCountIterator> bucket_it = samples->Iterator(); |
| + !bucket_it->Done(); bucket_it->Next()) { |
| + HistogramBase::Sample min, max; |
| + HistogramBase::Count count; |
| + bucket_it->Get(&min, &max, &count); |
| + if (count != 0) { |
| + result.push_back(base::StringPrintf( |
| + "%s[%d]=%d", histogram->histogram_name().c_str(), min, count)); |
| + } |
| + } |
| + } else { |
| + HistogramBase::Count count = samples->TotalCount(); |
| + if (count != 0) { |
| + result.push_back(base::StringPrintf( |
| + "%s=%d", histogram->histogram_name().c_str(), count)); |
| + } |
| + } |
| + } |
| + std::sort(result.begin(), result.end()); |
| + return JoinString(result, "\n"); |
| +} |
| + |
| scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( |
| const std::string& histogram_name) { |
| HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); |