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

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

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/test/histogram_tester.h ('k') | 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/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 base::StatisticsRecorder::FindHistogram(name); 66 base::StatisticsRecorder::FindHistogram(name);
67 if (histogram) { 67 if (histogram) {
68 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); 68 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
69 CheckTotalCount(name, count, *samples); 69 CheckTotalCount(name, count, *samples);
70 } else { 70 } else {
71 // No histogram means there were zero samples. 71 // No histogram means there were zero samples.
72 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist."; 72 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist.";
73 } 73 }
74 } 74 }
75 75
76 std::vector<Bucket> HistogramTester::GetAllSamples(const std::string& name) {
77 std::vector<Bucket> samples;
78 scoped_ptr<HistogramSamples> snapshot =
79 GetHistogramSamplesSinceCreation(name);
80 for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) {
81 HistogramBase::Sample sample;
82 HistogramBase::Count count;
83 it->Get(&sample, nullptr, &count);
84 samples.push_back(Bucket(sample, count));
85 }
86 return samples;
87 }
88
76 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( 89 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation(
77 const std::string& histogram_name) { 90 const std::string& histogram_name) {
78 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); 91 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
79 if (!histogram) 92 if (!histogram)
80 return scoped_ptr<HistogramSamples>(); 93 return scoped_ptr<HistogramSamples>();
81 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); 94 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
82 HistogramSamples* named_original_samples = 95 HistogramSamples* named_original_samples =
83 histograms_snapshot_[histogram_name]; 96 histograms_snapshot_[histogram_name];
84 if (named_original_samples) 97 if (named_original_samples)
85 named_samples->Subtract(*named_original_samples); 98 named_samples->Subtract(*named_original_samples);
(...skipping 27 matching lines...) Expand all
113 histogram_data = histograms_snapshot_.find(name); 126 histogram_data = histograms_snapshot_.find(name);
114 if (histogram_data != histograms_snapshot_.end()) 127 if (histogram_data != histograms_snapshot_.end())
115 actual_count -= histogram_data->second->TotalCount(); 128 actual_count -= histogram_data->second->TotalCount();
116 129
117 EXPECT_EQ(expected_count, actual_count) 130 EXPECT_EQ(expected_count, actual_count)
118 << "Histogram \"" << name 131 << "Histogram \"" << name
119 << "\" does not have the right total number of samples (" 132 << "\" does not have the right total number of samples ("
120 << expected_count << "). It has (" << actual_count << ")."; 133 << expected_count << "). It has (" << actual_count << ").";
121 } 134 }
122 135
136 bool Bucket::operator==(const Bucket& other) const {
137 return min == other.min && count == other.count;
138 }
139
140 void PrintTo(const Bucket& bucket, std::ostream* os) {
141 *os << "Bucket " << bucket.min << ": " << bucket.count;
142 }
143
123 } // namespace base 144 } // namespace base
OLDNEW
« no previous file with comments | « base/test/histogram_tester.h ('k') | base/test/histogram_tester_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698