Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: base/test/histogram_tester.cc

Issue 1190423006: base/test/histogram_tester.h: Add a way to query a whole family of related (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes from twifkak Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/histogram_tester.h ('k') | content/child/site_isolation_stats_gatherer_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/histogram_tester.cc
diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
index 0eba3a9a27938e6ef7ecd7872f466159284a5717..0bff2f841c1d66fcccc13be29fef0adf9a8a5c17 100644
--- a/base/test/histogram_tester.cc
+++ b/base/test/histogram_tester.cc
@@ -73,7 +73,8 @@ void HistogramTester::ExpectTotalCount(const std::string& name,
}
}
-std::vector<Bucket> HistogramTester::GetAllSamples(const std::string& name) {
+std::vector<Bucket> HistogramTester::GetAllSamples(
+ const std::string& name) const {
std::vector<Bucket> samples;
scoped_ptr<HistogramSamples> snapshot =
GetHistogramSamplesSinceCreation(name);
@@ -86,16 +87,37 @@ std::vector<Bucket> HistogramTester::GetAllSamples(const std::string& name) {
return samples;
}
+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"
+ << " many histograms.";
+
+ // Find matches by using the prefix-matching logic built into GetSnapshot().
+ StatisticsRecorder::Histograms query_matches;
+ StatisticsRecorder::GetSnapshot(query, &query_matches);
+
+ CountsMap result;
+ for (base::HistogramBase* histogram : query_matches) {
+ scoped_ptr<HistogramSamples> new_samples =
+ GetHistogramSamplesSinceCreation(histogram->histogram_name());
+ // Omit unchanged histograms from the result.
+ if (new_samples->TotalCount()) {
+ result[histogram->histogram_name()] = new_samples->TotalCount();
+ }
+ }
+ return result;
+}
+
scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation(
- const std::string& histogram_name) {
+ const std::string& histogram_name) const {
HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
if (!histogram)
return scoped_ptr<HistogramSamples>();
scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
- HistogramSamples* named_original_samples =
- histograms_snapshot_[histogram_name];
- if (named_original_samples)
- named_samples->Subtract(*named_original_samples);
+ auto original_samples_it = histograms_snapshot_.find(histogram_name);
+ if (original_samples_it != histograms_snapshot_.end())
+ named_samples->Subtract(*original_samples_it->second);
return named_samples.Pass();
}
« no previous file with comments | « base/test/histogram_tester.h ('k') | content/child/site_isolation_stats_gatherer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698