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

Side by Side Diff: base/test/histogram_tester.cc

Issue 1265403003: Fix HistogramTester::GetAllSamples when empty. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/test/histogram_tester_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/histogram_tester.h" 5 #include "base/test/histogram_tester.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/histogram_samples.h" 8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/sample_map.h" 9 #include "base/metrics/sample_map.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // No histogram means there were zero samples. 72 // No histogram means there were zero samples.
73 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist."; 73 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist.";
74 } 74 }
75 } 75 }
76 76
77 std::vector<Bucket> HistogramTester::GetAllSamples( 77 std::vector<Bucket> HistogramTester::GetAllSamples(
78 const std::string& name) const { 78 const std::string& name) const {
79 std::vector<Bucket> samples; 79 std::vector<Bucket> samples;
80 scoped_ptr<HistogramSamples> snapshot = 80 scoped_ptr<HistogramSamples> snapshot =
81 GetHistogramSamplesSinceCreation(name); 81 GetHistogramSamplesSinceCreation(name);
82 for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) { 82 if (snapshot) {
Ilya Sherman 2015/08/07 17:20:12 optional nit: I'd write this as an early return, p
twifkak 2015/08/07 19:36:38 Hmm. Was going to do this, but on second thought,
83 HistogramBase::Sample sample; 83 for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) {
84 HistogramBase::Count count; 84 HistogramBase::Sample sample;
85 it->Get(&sample, nullptr, &count); 85 HistogramBase::Count count;
86 samples.push_back(Bucket(sample, count)); 86 it->Get(&sample, nullptr, &count);
87 samples.push_back(Bucket(sample, count));
88 }
87 } 89 }
88 return samples; 90 return samples;
89 } 91 }
90 92
91 HistogramTester::CountsMap HistogramTester::GetTotalCountsForPrefix( 93 HistogramTester::CountsMap HistogramTester::GetTotalCountsForPrefix(
92 const std::string& query) const { 94 const std::string& query) const {
93 EXPECT_TRUE(query.find('.') != std::string::npos) 95 EXPECT_TRUE(query.find('.') != std::string::npos)
94 << "|query| ought to contain at least one period, to avoid matching too" 96 << "|query| ought to contain at least one period, to avoid matching too"
95 << " many histograms."; 97 << " many histograms.";
96 98
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 166
165 bool Bucket::operator==(const Bucket& other) const { 167 bool Bucket::operator==(const Bucket& other) const {
166 return min == other.min && count == other.count; 168 return min == other.min && count == other.count;
167 } 169 }
168 170
169 void PrintTo(const Bucket& bucket, std::ostream* os) { 171 void PrintTo(const Bucket& bucket, std::ostream* os) {
170 *os << "Bucket " << bucket.min << ": " << bucket.count; 172 *os << "Bucket " << bucket.min << ": " << bucket.count;
171 } 173 }
172 174
173 } // namespace base 175 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/test/histogram_tester_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698