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 <climits> | 7 #include <climits> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); | 74 LOCAL_HISTOGRAM_PERCENTAGE("DuplicatedHistogram", 10); |
75 HistogramBase* histogram = LinearHistogram::FactoryGet( | 75 HistogramBase* histogram = LinearHistogram::FactoryGet( |
76 "DuplicatedHistogram", 1, 101, 102, HistogramBase::kNoFlags); | 76 "DuplicatedHistogram", 1, 101, 102, HistogramBase::kNoFlags); |
77 | 77 |
78 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); | 78 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
79 EXPECT_EQ(2, samples->TotalCount()); | 79 EXPECT_EQ(2, samples->TotalCount()); |
80 EXPECT_EQ(2, samples->GetCount(10)); | 80 EXPECT_EQ(2, samples->GetCount(10)); |
81 } | 81 } |
82 | 82 |
83 TEST_F(HistogramTest, ExponentialRangesTest) { | 83 TEST_F(HistogramTest, ExponentialRangesTest) { |
84 // Check that we got a nice exponential when there was enough rooom. | 84 // Check that we got a nice exponential when there was enough room. |
85 BucketRanges ranges(9); | 85 BucketRanges ranges(9); |
86 Histogram::InitializeBucketRanges(1, 64, &ranges); | 86 Histogram::InitializeBucketRanges(1, 64, &ranges); |
87 EXPECT_EQ(0, ranges.range(0)); | 87 EXPECT_EQ(0, ranges.range(0)); |
88 int power_of_2 = 1; | 88 int power_of_2 = 1; |
89 for (int i = 1; i < 8; i++) { | 89 for (int i = 1; i < 8; i++) { |
90 EXPECT_EQ(power_of_2, ranges.range(i)); | 90 EXPECT_EQ(power_of_2, ranges.range(i)); |
91 power_of_2 *= 2; | 91 power_of_2 *= 2; |
92 } | 92 } |
93 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges.range(8)); | 93 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges.range(8)); |
94 | 94 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 // CustomHistogram needs at least 1 valid range. | 527 // CustomHistogram needs at least 1 valid range. |
528 custom_ranges.clear(); | 528 custom_ranges.clear(); |
529 custom_ranges.push_back(0); | 529 custom_ranges.push_back(0); |
530 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 530 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
531 HistogramBase::kNoFlags), | 531 HistogramBase::kNoFlags), |
532 ""); | 532 ""); |
533 } | 533 } |
534 #endif | 534 #endif |
535 | 535 |
536 } // namespace base | 536 } // namespace base |
OLD | NEW |