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

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 some 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
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)));
126 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); 128 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
127 auto original_samples_it = histograms_snapshot_.find(histogram_name); 129 auto original_samples_it = histograms_snapshot_.find(histogram_name);
128 if (original_samples_it != histograms_snapshot_.end()) 130 if (original_samples_it != histograms_snapshot_.end())
129 named_samples->Subtract(*original_samples_it->second); 131 named_samples->Subtract(*original_samples_it->second);
130 return named_samples; 132 return named_samples;
131 } 133 }
132 134
133 void HistogramTester::CheckBucketCount( 135 void HistogramTester::CheckBucketCount(
134 const std::string& name, 136 const std::string& name,
135 base::HistogramBase::Sample sample, 137 base::HistogramBase::Sample sample,
(...skipping 30 matching lines...) Expand all
166 168
167 bool Bucket::operator==(const Bucket& other) const { 169 bool Bucket::operator==(const Bucket& other) const {
168 return min == other.min && count == other.count; 170 return min == other.min && count == other.count;
169 } 171 }
170 172
171 void PrintTo(const Bucket& bucket, std::ostream* os) { 173 void PrintTo(const Bucket& bucket, std::ostream* os) {
172 *os << "Bucket " << bucket.min << ": " << bucket.count; 174 *os << "Bucket " << bucket.min << ": " << bucket.count;
173 } 175 }
174 176
175 } // namespace base 177 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698