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

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: remove DCHECK_IS_ON from .h files because it's not always defined and don't want to add the include Created 4 years, 7 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 final-delta calculations work correctly.
180 TEST_P(HistogramTest, FinalDeltaTest) {
181 HistogramBase* histogram =
182 Histogram::FactoryGet("FinalDeltaHistogram", 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->SnapshotFinalDelta();
Ilya Sherman 2016/05/04 06:48:07 Please include an additional test where the code f
bcwhite 2016/05/04 14:12:50 Done.
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
179 TEST_P(HistogramTest, ExponentialRangesTest) { 196 TEST_P(HistogramTest, ExponentialRangesTest) {
180 // Check that we got a nice exponential when there was enough room. 197 // Check that we got a nice exponential when there was enough room.
181 BucketRanges ranges(9); 198 BucketRanges ranges(9);
182 Histogram::InitializeBucketRanges(1, 64, &ranges); 199 Histogram::InitializeBucketRanges(1, 64, &ranges);
183 EXPECT_EQ(0, ranges.range(0)); 200 EXPECT_EQ(0, ranges.range(0));
184 int power_of_2 = 1; 201 int power_of_2 = 1;
185 for (int i = 1; i < 8; i++) { 202 for (int i = 1; i < 8; i++) {
186 EXPECT_EQ(power_of_2, ranges.range(i)); 203 EXPECT_EQ(power_of_2, ranges.range(i));
187 power_of_2 *= 2; 204 power_of_2 *= 2;
188 } 205 }
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 // CustomHistogram needs at least 1 valid range. 733 // CustomHistogram needs at least 1 valid range.
717 custom_ranges.clear(); 734 custom_ranges.clear();
718 custom_ranges.push_back(0); 735 custom_ranges.push_back(0);
719 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, 736 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges,
720 HistogramBase::kNoFlags), 737 HistogramBase::kNoFlags),
721 ""); 738 "");
722 } 739 }
723 #endif 740 #endif
724 741
725 } // namespace base 742 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698