| OLD | NEW |
| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); | 201 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); |
| 202 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); | 202 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); |
| 203 HistogramBase* histogram = LinearHistogram::FactoryGet( | 203 HistogramBase* histogram = LinearHistogram::FactoryGet( |
| 204 "DuplicatedHistogram", 1, 101, 102, HistogramBase::kNoFlags); | 204 "DuplicatedHistogram", 1, 101, 102, HistogramBase::kNoFlags); |
| 205 | 205 |
| 206 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); | 206 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
| 207 EXPECT_EQ(2, samples->TotalCount()); | 207 EXPECT_EQ(2, samples->TotalCount()); |
| 208 EXPECT_EQ(2, samples->GetCount(10)); | 208 EXPECT_EQ(2, samples->GetCount(10)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 // Check that delta calculations work correct. |
| 212 TEST_F(HistogramTest, DeltaTest) { |
| 213 HistogramBase* histogram = |
| 214 Histogram::FactoryGet("DeltaHistogram", 1, 64, 8, |
| 215 HistogramBase::kNoFlags); |
| 216 histogram->Add(1); |
| 217 histogram->Add(10); |
| 218 histogram->Add(50); |
| 219 |
| 220 scoped_ptr<HistogramSamples> samples = histogram->SnapshotDelta(); |
| 221 EXPECT_EQ(3, samples->TotalCount()); |
| 222 EXPECT_EQ(1, samples->GetCount(1)); |
| 223 EXPECT_EQ(1, samples->GetCount(10)); |
| 224 EXPECT_EQ(1, samples->GetCount(50)); |
| 225 |
| 226 samples = histogram->SnapshotDelta(); |
| 227 EXPECT_EQ(0, samples->TotalCount()); |
| 228 |
| 229 histogram->Add(10); |
| 230 histogram->Add(10); |
| 231 samples = histogram->SnapshotDelta(); |
| 232 EXPECT_EQ(2, samples->TotalCount()); |
| 233 EXPECT_EQ(2, samples->GetCount(10)); |
| 234 |
| 235 samples = histogram->SnapshotDelta(); |
| 236 EXPECT_EQ(0, samples->TotalCount()); |
| 237 } |
| 238 |
| 211 TEST_F(HistogramTest, ExponentialRangesTest) { | 239 TEST_F(HistogramTest, ExponentialRangesTest) { |
| 212 // Check that we got a nice exponential when there was enough room. | 240 // Check that we got a nice exponential when there was enough room. |
| 213 BucketRanges ranges(9); | 241 BucketRanges ranges(9); |
| 214 Histogram::InitializeBucketRanges(1, 64, &ranges); | 242 Histogram::InitializeBucketRanges(1, 64, &ranges); |
| 215 EXPECT_EQ(0, ranges.range(0)); | 243 EXPECT_EQ(0, ranges.range(0)); |
| 216 int power_of_2 = 1; | 244 int power_of_2 = 1; |
| 217 for (int i = 1; i < 8; i++) { | 245 for (int i = 1; i < 8; i++) { |
| 218 EXPECT_EQ(power_of_2, ranges.range(i)); | 246 EXPECT_EQ(power_of_2, ranges.range(i)); |
| 219 power_of_2 *= 2; | 247 power_of_2 *= 2; |
| 220 } | 248 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 // CustomHistogram needs at least 1 valid range. | 752 // CustomHistogram needs at least 1 valid range. |
| 725 custom_ranges.clear(); | 753 custom_ranges.clear(); |
| 726 custom_ranges.push_back(0); | 754 custom_ranges.push_back(0); |
| 727 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 755 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
| 728 HistogramBase::kNoFlags), | 756 HistogramBase::kNoFlags), |
| 729 ""); | 757 ""); |
| 730 } | 758 } |
| 731 #endif | 759 #endif |
| 732 | 760 |
| 733 } // namespace base | 761 } // namespace base |
| OLD | NEW |