| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 if (histogram) { | 71 if (histogram) { |
| 72 std::unique_ptr<base::HistogramSamples> samples = | 72 std::unique_ptr<base::HistogramSamples> samples = |
| 73 histogram->SnapshotSamples(); | 73 histogram->SnapshotSamples(); |
| 74 CheckTotalCount(name, count, *samples); | 74 CheckTotalCount(name, count, *samples); |
| 75 } else { | 75 } else { |
| 76 // No histogram means there were zero samples. | 76 // No histogram means there were zero samples. |
| 77 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist."; | 77 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist."; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 void HistogramTester::ExpectTimeBucketCount( |
| 82 const std::string& name, |
| 83 base::TimeDelta sample, |
| 84 base::HistogramBase::Count count) const { |
| 85 ExpectBucketCount(name, sample.InMilliseconds(), count); |
| 86 } |
| 87 |
| 81 std::vector<Bucket> HistogramTester::GetAllSamples( | 88 std::vector<Bucket> HistogramTester::GetAllSamples( |
| 82 const std::string& name) const { | 89 const std::string& name) const { |
| 83 std::vector<Bucket> samples; | 90 std::vector<Bucket> samples; |
| 84 std::unique_ptr<HistogramSamples> snapshot = | 91 std::unique_ptr<HistogramSamples> snapshot = |
| 85 GetHistogramSamplesSinceCreation(name); | 92 GetHistogramSamplesSinceCreation(name); |
| 86 if (snapshot) { | 93 if (snapshot) { |
| 87 for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) { | 94 for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) { |
| 88 HistogramBase::Sample sample; | 95 HistogramBase::Sample sample; |
| 89 HistogramBase::Count count; | 96 HistogramBase::Count count; |
| 90 it->Get(&sample, nullptr, &count); | 97 it->Get(&sample, nullptr, &count); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 179 |
| 173 bool Bucket::operator==(const Bucket& other) const { | 180 bool Bucket::operator==(const Bucket& other) const { |
| 174 return min == other.min && count == other.count; | 181 return min == other.min && count == other.count; |
| 175 } | 182 } |
| 176 | 183 |
| 177 void PrintTo(const Bucket& bucket, std::ostream* os) { | 184 void PrintTo(const Bucket& bucket, std::ostream* os) { |
| 178 *os << "Bucket " << bucket.min << ": " << bucket.count; | 185 *os << "Bucket " << bucket.min << ": " << bucket.count; |
| 179 } | 186 } |
| 180 | 187 |
| 181 } // namespace base | 188 } // namespace base |
| OLD | NEW |