OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |