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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 histogram->AddCount(200000000, 25); | 394 histogram->AddCount(200000000, 25); |
395 histogram->AddCount(300000000, 24); | 395 histogram->AddCount(300000000, 24); |
396 | 396 |
397 std::unique_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); | 397 std::unique_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples(); |
398 EXPECT_EQ(78, samples2->TotalCount()); | 398 EXPECT_EQ(78, samples2->TotalCount()); |
399 EXPECT_EQ(40, samples2->GetCount(200000000)); | 399 EXPECT_EQ(40, samples2->GetCount(200000000)); |
400 EXPECT_EQ(38, samples2->GetCount(300000000)); | 400 EXPECT_EQ(38, samples2->GetCount(300000000)); |
401 EXPECT_EQ(19400000000LL, samples2->sum()); | 401 EXPECT_EQ(19400000000LL, samples2->sum()); |
402 } | 402 } |
403 | 403 |
404 // Make sure that counts returned by Histogram::SnapshotDelta do not overflow | |
405 // even when a total count (returned by Histogram::SnapshotSample) does. | |
406 TEST_P(HistogramTest, AddCount_LargeCountsDontOverflow) { | |
407 const size_t kBucketCount = 50; | |
408 Histogram* histogram = static_cast<Histogram*>(Histogram::FactoryGet( | |
409 "AddCountHistogram", 10, 50, kBucketCount, HistogramBase::kNoFlags)); | |
bcwhite
2017/05/10 12:40:33
You have 50 buckets for a range of 40.
altimin
2017/05/10 13:08:55
Done.
| |
410 | |
411 // Repeat N times to make sure that there is no internal value overflow. | |
412 for (int i = 0; i < 10; ++i) { | |
413 histogram->AddCount(42, 1 << 30); | |
414 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta(); | |
415 EXPECT_EQ(1 << 30, samples->TotalCount()); | |
416 EXPECT_EQ(1 << 30, samples->GetCount(42)); | |
417 } | |
418 } | |
419 | |
404 // Make sure histogram handles out-of-bounds data gracefully. | 420 // Make sure histogram handles out-of-bounds data gracefully. |
405 TEST_P(HistogramTest, BoundsTest) { | 421 TEST_P(HistogramTest, BoundsTest) { |
406 const size_t kBucketCount = 50; | 422 const size_t kBucketCount = 50; |
407 Histogram* histogram = static_cast<Histogram*>( | 423 Histogram* histogram = static_cast<Histogram*>( |
408 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, | 424 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, |
409 HistogramBase::kNoFlags)); | 425 HistogramBase::kNoFlags)); |
410 | 426 |
411 // Put two samples "out of bounds" above and below. | 427 // Put two samples "out of bounds" above and below. |
412 histogram->Add(5); | 428 histogram->Add(5); |
413 histogram->Add(-50); | 429 histogram->Add(-50); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 // CustomHistogram needs at least 1 valid range. | 759 // CustomHistogram needs at least 1 valid range. |
744 custom_ranges.clear(); | 760 custom_ranges.clear(); |
745 custom_ranges.push_back(0); | 761 custom_ranges.push_back(0); |
746 EXPECT_DEATH_IF_SUPPORTED( | 762 EXPECT_DEATH_IF_SUPPORTED( |
747 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 763 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
748 HistogramBase::kNoFlags), | 764 HistogramBase::kNoFlags), |
749 ""); | 765 ""); |
750 } | 766 } |
751 | 767 |
752 } // namespace base | 768 } // namespace base |
OLD | NEW |