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/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 base::StatisticsRecorder::FindHistogram(name); | 66 base::StatisticsRecorder::FindHistogram(name); |
67 if (histogram) { | 67 if (histogram) { |
68 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | 68 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
69 CheckTotalCount(name, count, *samples); | 69 CheckTotalCount(name, count, *samples); |
70 } else { | 70 } else { |
71 // No histogram means there were zero samples. | 71 // No histogram means there were zero samples. |
72 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist."; | 72 EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist."; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
| 76 std::vector<std::pair<HistogramBase::Sample, HistogramBase::Count>> |
| 77 HistogramTester::GetAllSamples(const std::string& name) { |
| 78 std::vector<std::pair<HistogramBase::Sample, HistogramBase::Count>> samples; |
| 79 scoped_ptr<HistogramSamples> snapshot = |
| 80 GetHistogramSamplesSinceCreation(name); |
| 81 for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) { |
| 82 HistogramBase::Sample sample; |
| 83 HistogramBase::Count count; |
| 84 it->Get(&sample, nullptr, &count); |
| 85 samples.push_back(std::make_pair(sample, count)); |
| 86 } |
| 87 return samples; |
| 88 } |
| 89 |
76 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( | 90 scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation( |
77 const std::string& histogram_name) { | 91 const std::string& histogram_name) { |
78 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); | 92 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); |
79 if (!histogram) | 93 if (!histogram) |
80 return scoped_ptr<HistogramSamples>(); | 94 return scoped_ptr<HistogramSamples>(); |
81 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); | 95 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); |
82 HistogramSamples* named_original_samples = | 96 HistogramSamples* named_original_samples = |
83 histograms_snapshot_[histogram_name]; | 97 histograms_snapshot_[histogram_name]; |
84 if (named_original_samples) | 98 if (named_original_samples) |
85 named_samples->Subtract(*named_original_samples); | 99 named_samples->Subtract(*named_original_samples); |
(...skipping 28 matching lines...) Expand all Loading... |
114 if (histogram_data != histograms_snapshot_.end()) | 128 if (histogram_data != histograms_snapshot_.end()) |
115 actual_count -= histogram_data->second->TotalCount(); | 129 actual_count -= histogram_data->second->TotalCount(); |
116 | 130 |
117 EXPECT_EQ(expected_count, actual_count) | 131 EXPECT_EQ(expected_count, actual_count) |
118 << "Histogram \"" << name | 132 << "Histogram \"" << name |
119 << "\" does not have the right total number of samples (" | 133 << "\" does not have the right total number of samples (" |
120 << expected_count << "). It has (" << actual_count << ")."; | 134 << expected_count << "). It has (" << actual_count << ")."; |
121 } | 135 } |
122 | 136 |
123 } // namespace base | 137 } // namespace base |
OLD | NEW |