Chromium Code Reviews| 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/sample_map.h" | |
| 9 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 HistogramTester::HistogramTester() { | 16 HistogramTester::HistogramTester() { |
| 16 StatisticsRecorder::Initialize(); // Safe to call multiple times. | 17 StatisticsRecorder::Initialize(); // Safe to call multiple times. |
| 17 | 18 |
| 18 // Record any histogram data that exists when the object is created so it can | 19 // Record any histogram data that exists when the object is created so it can |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 if (new_samples->TotalCount()) { | 106 if (new_samples->TotalCount()) { |
| 106 result[histogram->histogram_name()] = new_samples->TotalCount(); | 107 result[histogram->histogram_name()] = new_samples->TotalCount(); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 return result; | 110 return result; |
| 110 } | 111 } |
| 111 | 112 |
| 112 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( | 113 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( |
| 113 const std::string& histogram_name) const { | 114 const std::string& histogram_name) const { |
| 114 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); | 115 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); |
| 116 // Whether the histogram exists or not may not depend on the current test | |
| 117 // calling this method, but rather on which tests ran before and possibly | |
| 118 // generated a histogram or not (see http://crbug.com/473689). To provide a | |
| 119 // response which is independent of the previously run tests, this method | |
| 120 // creates empty samples in the absence of the histogram, rather than | |
| 121 // returning null. | |
| 115 if (!histogram) | 122 if (!histogram) |
| 116 return scoped_ptr<HistogramSamples>(); | 123 return scoped_ptr<HistogramSamples>(new SampleMap); |
|
Lei Zhang
2015/07/31 18:30:59
GetHistogramSamplesSinceCreation() now always retu
vabr (Chromium)
2015/07/31 18:49:45
Good catch. I grepped for GetHistogramSamplesSince
| |
| 117 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); | 124 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); |
| 118 auto original_samples_it = histograms_snapshot_.find(histogram_name); | 125 auto original_samples_it = histograms_snapshot_.find(histogram_name); |
| 119 if (original_samples_it != histograms_snapshot_.end()) | 126 if (original_samples_it != histograms_snapshot_.end()) |
| 120 named_samples->Subtract(*original_samples_it->second); | 127 named_samples->Subtract(*original_samples_it->second); |
| 121 return named_samples.Pass(); | 128 return named_samples.Pass(); |
| 122 } | 129 } |
| 123 | 130 |
| 124 void HistogramTester::CheckBucketCount( | 131 void HistogramTester::CheckBucketCount( |
| 125 const std::string& name, | 132 const std::string& name, |
| 126 base::HistogramBase::Sample sample, | 133 base::HistogramBase::Sample sample, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 157 | 164 |
| 158 bool Bucket::operator==(const Bucket& other) const { | 165 bool Bucket::operator==(const Bucket& other) const { |
| 159 return min == other.min && count == other.count; | 166 return min == other.min && count == other.count; |
| 160 } | 167 } |
| 161 | 168 |
| 162 void PrintTo(const Bucket& bucket, std::ostream* os) { | 169 void PrintTo(const Bucket& bucket, std::ostream* os) { |
| 163 *os << "Bucket " << bucket.min << ": " << bucket.count; | 170 *os << "Bucket " << bucket.min << ": " << bucket.count; |
| 164 } | 171 } |
| 165 | 172 |
| 166 } // namespace base | 173 } // namespace base |
| OLD | NEW |