| Index: base/test/histogram_tester.cc
|
| diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
|
| index 90981e232637f8eb3323c96f9f22dc9538c5b89a..59ea1c630217a3e9cdc3d986b8594bc5201db63b 100644
|
| --- a/base/test/histogram_tester.cc
|
| +++ b/base/test/histogram_tester.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/metrics/metrics_hashes.h"
|
| #include "base/metrics/sample_map.h"
|
| #include "base/metrics/statistics_recorder.h"
|
| +#include "base/strings/string_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace base {
|
| @@ -33,16 +34,14 @@ HistogramTester::~HistogramTester() {
|
|
|
| void HistogramTester::ExpectUniqueSample(
|
| const std::string& name,
|
| - base::HistogramBase::Sample sample,
|
| - base::HistogramBase::Count expected_count) const {
|
| - base::HistogramBase* histogram =
|
| - base::StatisticsRecorder::FindHistogram(name);
|
| + HistogramBase::Sample sample,
|
| + HistogramBase::Count expected_count) const {
|
| + HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
|
| EXPECT_NE(nullptr, histogram) << "Histogram \"" << name
|
| << "\" does not exist.";
|
|
|
| if (histogram) {
|
| - std::unique_ptr<base::HistogramSamples> samples =
|
| - histogram->SnapshotSamples();
|
| + std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
|
| CheckBucketCount(name, sample, expected_count, *samples);
|
| CheckTotalCount(name, expected_count, *samples);
|
| }
|
| @@ -50,27 +49,23 @@ void HistogramTester::ExpectUniqueSample(
|
|
|
| void HistogramTester::ExpectBucketCount(
|
| const std::string& name,
|
| - base::HistogramBase::Sample sample,
|
| - base::HistogramBase::Count expected_count) const {
|
| - base::HistogramBase* histogram =
|
| - base::StatisticsRecorder::FindHistogram(name);
|
| + HistogramBase::Sample sample,
|
| + HistogramBase::Count expected_count) const {
|
| + HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
|
| EXPECT_NE(nullptr, histogram) << "Histogram \"" << name
|
| << "\" does not exist.";
|
|
|
| if (histogram) {
|
| - std::unique_ptr<base::HistogramSamples> samples =
|
| - histogram->SnapshotSamples();
|
| + std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
|
| CheckBucketCount(name, sample, expected_count, *samples);
|
| }
|
| }
|
|
|
| void HistogramTester::ExpectTotalCount(const std::string& name,
|
| - base::HistogramBase::Count count) const {
|
| - base::HistogramBase* histogram =
|
| - base::StatisticsRecorder::FindHistogram(name);
|
| + HistogramBase::Count count) const {
|
| + HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
|
| if (histogram) {
|
| - std::unique_ptr<base::HistogramSamples> samples =
|
| - histogram->SnapshotSamples();
|
| + std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
|
| CheckTotalCount(name, count, *samples);
|
| } else {
|
| // No histogram means there were zero samples.
|
| @@ -78,10 +73,9 @@ void HistogramTester::ExpectTotalCount(const std::string& name,
|
| }
|
| }
|
|
|
| -void HistogramTester::ExpectTimeBucketCount(
|
| - const std::string& name,
|
| - base::TimeDelta sample,
|
| - base::HistogramBase::Count count) const {
|
| +void HistogramTester::ExpectTimeBucketCount(const std::string& name,
|
| + TimeDelta sample,
|
| + HistogramBase::Count count) const {
|
| ExpectBucketCount(name, sample.InMilliseconds(), count);
|
| }
|
|
|
| @@ -102,17 +96,21 @@ std::vector<Bucket> HistogramTester::GetAllSamples(
|
| }
|
|
|
| HistogramTester::CountsMap HistogramTester::GetTotalCountsForPrefix(
|
| - const std::string& query) const {
|
| - EXPECT_TRUE(query.find('.') != std::string::npos)
|
| - << "|query| ought to contain at least one period, to avoid matching too"
|
| + const std::string& prefix) const {
|
| + EXPECT_TRUE(prefix.find('.') != std::string::npos)
|
| + << "|prefix| ought to contain at least one period, to avoid matching too"
|
| << " many histograms.";
|
|
|
| - // Find matches by using the prefix-matching logic built into GetSnapshot().
|
| - StatisticsRecorder::Histograms query_matches;
|
| - StatisticsRecorder::GetSnapshot(query, &query_matches);
|
| + // Find candidate matches by using the logic built into GetSnapshot().
|
| + StatisticsRecorder::Histograms candidate_matches;
|
| + StatisticsRecorder::GetSnapshot(prefix, &candidate_matches);
|
|
|
| CountsMap result;
|
| - for (base::HistogramBase* histogram : query_matches) {
|
| + for (HistogramBase* histogram : candidate_matches) {
|
| + if (!StartsWith(histogram->histogram_name(), prefix,
|
| + CompareCase::SENSITIVE)) {
|
| + continue;
|
| + }
|
| std::unique_ptr<HistogramSamples> new_samples =
|
| GetHistogramSamplesSinceCreation(histogram->histogram_name());
|
| // Omit unchanged histograms from the result.
|
| @@ -145,11 +143,10 @@ HistogramTester::GetHistogramSamplesSinceCreation(
|
| return named_samples;
|
| }
|
|
|
| -void HistogramTester::CheckBucketCount(
|
| - const std::string& name,
|
| - base::HistogramBase::Sample sample,
|
| - base::HistogramBase::Count expected_count,
|
| - const base::HistogramSamples& samples) const {
|
| +void HistogramTester::CheckBucketCount(const std::string& name,
|
| + HistogramBase::Sample sample,
|
| + HistogramBase::Count expected_count,
|
| + const HistogramSamples& samples) const {
|
| int actual_count = samples.GetCount(sample);
|
| auto histogram_data = histograms_snapshot_.find(name);
|
| if (histogram_data != histograms_snapshot_.end())
|
| @@ -162,10 +159,9 @@ void HistogramTester::CheckBucketCount(
|
| << ").";
|
| }
|
|
|
| -void HistogramTester::CheckTotalCount(
|
| - const std::string& name,
|
| - base::HistogramBase::Count expected_count,
|
| - const base::HistogramSamples& samples) const {
|
| +void HistogramTester::CheckTotalCount(const std::string& name,
|
| + HistogramBase::Count expected_count,
|
| + const HistogramSamples& samples) const {
|
| int actual_count = samples.TotalCount();
|
| auto histogram_data = histograms_snapshot_.find(name);
|
| if (histogram_data != histograms_snapshot_.end())
|
|
|