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

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

Issue 1471073007: Reorganize histograms for persistence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: addressed review comments by Alexei Created 5 years 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/metrics/statistics_recorder.cc ('k') | components/metrics/histogram_encoder_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/metrics_hashes.h"
9 #include "base/metrics/sample_map.h" 10 #include "base/metrics/sample_map.h"
10 #include "base/metrics/statistics_recorder.h" 11 #include "base/metrics/statistics_recorder.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 HistogramTester::HistogramTester() { 17 HistogramTester::HistogramTester() {
17 StatisticsRecorder::Initialize(); // Safe to call multiple times. 18 StatisticsRecorder::Initialize(); // Safe to call multiple times.
18 19
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( 116 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation(
116 const std::string& histogram_name) const { 117 const std::string& histogram_name) const {
117 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); 118 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
118 // Whether the histogram exists or not may not depend on the current test 119 // Whether the histogram exists or not may not depend on the current test
119 // calling this method, but rather on which tests ran before and possibly 120 // calling this method, but rather on which tests ran before and possibly
120 // generated a histogram or not (see http://crbug.com/473689). To provide a 121 // generated a histogram or not (see http://crbug.com/473689). To provide a
121 // response which is independent of the previously run tests, this method 122 // response which is independent of the previously run tests, this method
122 // creates empty samples in the absence of the histogram, rather than 123 // creates empty samples in the absence of the histogram, rather than
123 // returning null. 124 // returning null.
124 if (!histogram) 125 if (!histogram) {
125 return scoped_ptr<HistogramSamples>(new SampleMap); 126 return scoped_ptr<HistogramSamples>(
127 new SampleMap(HashMetricName(histogram_name)));
128 }
126 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); 129 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
127 auto original_samples_it = histograms_snapshot_.find(histogram_name); 130 auto original_samples_it = histograms_snapshot_.find(histogram_name);
128 if (original_samples_it != histograms_snapshot_.end()) 131 if (original_samples_it != histograms_snapshot_.end())
129 named_samples->Subtract(*original_samples_it->second); 132 named_samples->Subtract(*original_samples_it->second);
130 return named_samples; 133 return named_samples;
131 } 134 }
132 135
133 void HistogramTester::CheckBucketCount( 136 void HistogramTester::CheckBucketCount(
134 const std::string& name, 137 const std::string& name,
135 base::HistogramBase::Sample sample, 138 base::HistogramBase::Sample sample,
(...skipping 30 matching lines...) Expand all
166 169
167 bool Bucket::operator==(const Bucket& other) const { 170 bool Bucket::operator==(const Bucket& other) const {
168 return min == other.min && count == other.count; 171 return min == other.min && count == other.count;
169 } 172 }
170 173
171 void PrintTo(const Bucket& bucket, std::ostream* os) { 174 void PrintTo(const Bucket& bucket, std::ostream* os) {
172 *os << "Bucket " << bucket.min << ": " << bucket.count; 175 *os << "Bucket " << bucket.min << ": " << bucket.count;
173 } 176 }
174 177
175 } // namespace base 178 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.cc ('k') | components/metrics/histogram_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698