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

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: removed some unnecessary includes 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->SnapshotDelta();
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 histogram->Add(2);
196 histogram->Add(50);
197
198 samples = histogram->SnapshotFinalDelta();
199 EXPECT_EQ(2, samples->TotalCount());
200 EXPECT_EQ(1, samples->GetCount(2));
201 EXPECT_EQ(1, samples->GetCount(50));
202 EXPECT_EQ(samples->TotalCount(), samples->redundant_count());
203 }
204
179 TEST_P(HistogramTest, ExponentialRangesTest) { 205 TEST_P(HistogramTest, ExponentialRangesTest) {
180 // Check that we got a nice exponential when there was enough room. 206 // Check that we got a nice exponential when there was enough room.
181 BucketRanges ranges(9); 207 BucketRanges ranges(9);
182 Histogram::InitializeBucketRanges(1, 64, &ranges); 208 Histogram::InitializeBucketRanges(1, 64, &ranges);
183 EXPECT_EQ(0, ranges.range(0)); 209 EXPECT_EQ(0, ranges.range(0));
184 int power_of_2 = 1; 210 int power_of_2 = 1;
185 for (int i = 1; i < 8; i++) { 211 for (int i = 1; i < 8; i++) {
186 EXPECT_EQ(power_of_2, ranges.range(i)); 212 EXPECT_EQ(power_of_2, ranges.range(i));
187 power_of_2 *= 2; 213 power_of_2 *= 2;
188 } 214 }
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 // CustomHistogram needs at least 1 valid range. 742 // CustomHistogram needs at least 1 valid range.
717 custom_ranges.clear(); 743 custom_ranges.clear();
718 custom_ranges.push_back(0); 744 custom_ranges.push_back(0);
719 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, 745 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges,
720 HistogramBase::kNoFlags), 746 HistogramBase::kNoFlags),
721 ""); 747 "");
722 } 748 }
723 #endif 749 #endif
724 750
725 } // namespace base 751 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_snapshot_manager.cc ('k') | base/metrics/persistent_histogram_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698