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

Side by Side Diff: base/metrics/histogram_unittest.cc

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed some build problems Created 4 years, 8 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/metrics/histogram.h" 5 #include "base/metrics/histogram.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); 140 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10);
141 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); 141 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10);
142 HistogramBase* histogram = LinearHistogram::FactoryGet( 142 HistogramBase* histogram = LinearHistogram::FactoryGet(
143 "DuplicatedHistogram", 1, 101, 102, HistogramBase::kNoFlags); 143 "DuplicatedHistogram", 1, 101, 102, HistogramBase::kNoFlags);
144 144
145 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); 145 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
146 EXPECT_EQ(2, samples->TotalCount()); 146 EXPECT_EQ(2, samples->TotalCount());
147 EXPECT_EQ(2, samples->GetCount(10)); 147 EXPECT_EQ(2, samples->GetCount(10));
148 } 148 }
149 149
150 // Check that delta calculations work correct. 150 // Check that delta calculations work correctly.
151 TEST_P(HistogramTest, DeltaTest) { 151 TEST_P(HistogramTest, DeltaTest) {
152 HistogramBase* histogram = 152 HistogramBase* histogram =
153 Histogram::FactoryGet("DeltaHistogram", 1, 64, 8, 153 Histogram::FactoryGet("DeltaHistogram", 1, 64, 8,
154 HistogramBase::kNoFlags); 154 HistogramBase::kNoFlags);
155 histogram->Add(1); 155 histogram->Add(1);
156 histogram->Add(10); 156 histogram->Add(10);
157 histogram->Add(50); 157 histogram->Add(50);
158 158
159 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta(); 159 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta();
160 EXPECT_EQ(3, samples->TotalCount()); 160 EXPECT_EQ(3, samples->TotalCount());
161 EXPECT_EQ(1, samples->GetCount(1)); 161 EXPECT_EQ(1, samples->GetCount(1));
162 EXPECT_EQ(1, samples->GetCount(10)); 162 EXPECT_EQ(1, samples->GetCount(10));
163 EXPECT_EQ(1, samples->GetCount(50)); 163 EXPECT_EQ(1, samples->GetCount(50));
164 EXPECT_EQ(samples->TotalCount(), samples->redundant_count()); 164 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
165 165
166 samples = histogram->SnapshotDelta(); 166 samples = histogram->SnapshotDelta();
167 EXPECT_EQ(0, samples->TotalCount()); 167 EXPECT_EQ(0, samples->TotalCount());
168 168
169 histogram->Add(10); 169 histogram->Add(10);
170 histogram->Add(10); 170 histogram->Add(10);
171 samples = histogram->SnapshotDelta(); 171 samples = histogram->SnapshotDelta();
172 EXPECT_EQ(2, samples->TotalCount()); 172 EXPECT_EQ(2, samples->TotalCount());
173 EXPECT_EQ(2, samples->GetCount(10)); 173 EXPECT_EQ(2, samples->GetCount(10));
174 174
175 samples = histogram->SnapshotDelta(); 175 samples = histogram->SnapshotDelta();
176 EXPECT_EQ(0, samples->TotalCount()); 176 EXPECT_EQ(0, samples->TotalCount());
177 } 177 }
178 178
179 // Check that difference calculations work correctly.
180 TEST_P(HistogramTest, DifferenceTest) {
181 HistogramBase* histogram =
182 Histogram::FactoryGet("DifferenceHistogram", 1, 64, 8,
183 HistogramBase::kNoFlags);
184 histogram->Add(1);
185 histogram->Add(10);
186 histogram->Add(50);
187
188 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDifference();
189 EXPECT_EQ(3, samples->TotalCount());
190 EXPECT_EQ(1, samples->GetCount(1));
191 EXPECT_EQ(1, samples->GetCount(10));
192 EXPECT_EQ(1, samples->GetCount(50));
193 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
194
195 samples = histogram->SnapshotDifference();
196 EXPECT_EQ(3, samples->TotalCount());
197 EXPECT_EQ(1, samples->GetCount(1));
198 EXPECT_EQ(1, samples->GetCount(10));
199 EXPECT_EQ(1, samples->GetCount(50));
200 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
201
202 histogram->Add(10);
203 histogram->Add(10);
204 samples = histogram->SnapshotDifference();
205 EXPECT_EQ(5, samples->TotalCount());
206 EXPECT_EQ(1, samples->GetCount(1));
207 EXPECT_EQ(3, samples->GetCount(10));
208 EXPECT_EQ(1, samples->GetCount(50));
209 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
210
211 samples = histogram->SnapshotDelta(); // Delta will reset differences.
212 EXPECT_EQ(5, samples->TotalCount());
213 EXPECT_EQ(1, samples->GetCount(1));
214 EXPECT_EQ(3, samples->GetCount(10));
215 EXPECT_EQ(1, samples->GetCount(50));
216 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
217
218 samples = histogram->SnapshotDifference();
219 EXPECT_EQ(0, samples->TotalCount());
220
221 histogram->Add(10);
222 histogram->Add(10);
223 samples = histogram->SnapshotDifference();
224 EXPECT_EQ(2, samples->TotalCount());
225 EXPECT_EQ(2, samples->GetCount(10));
226 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
227
228 samples = histogram->SnapshotDifference();
229 EXPECT_EQ(2, samples->TotalCount());
230 EXPECT_EQ(2, samples->GetCount(10));
231 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
232 }
233
179 TEST_P(HistogramTest, ExponentialRangesTest) { 234 TEST_P(HistogramTest, ExponentialRangesTest) {
180 // Check that we got a nice exponential when there was enough room. 235 // Check that we got a nice exponential when there was enough room.
181 BucketRanges ranges(9); 236 BucketRanges ranges(9);
182 Histogram::InitializeBucketRanges(1, 64, &ranges); 237 Histogram::InitializeBucketRanges(1, 64, &ranges);
183 EXPECT_EQ(0, ranges.range(0)); 238 EXPECT_EQ(0, ranges.range(0));
184 int power_of_2 = 1; 239 int power_of_2 = 1;
185 for (int i = 1; i < 8; i++) { 240 for (int i = 1; i < 8; i++) {
186 EXPECT_EQ(power_of_2, ranges.range(i)); 241 EXPECT_EQ(power_of_2, ranges.range(i));
187 power_of_2 *= 2; 242 power_of_2 *= 2;
188 } 243 }
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 // CustomHistogram needs at least 1 valid range. 771 // CustomHistogram needs at least 1 valid range.
717 custom_ranges.clear(); 772 custom_ranges.clear();
718 custom_ranges.push_back(0); 773 custom_ranges.push_back(0);
719 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, 774 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges,
720 HistogramBase::kNoFlags), 775 HistogramBase::kNoFlags),
721 ""); 776 "");
722 } 777 }
723 #endif 778 #endif
724 779
725 } // namespace base 780 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698