Chromium Code Reviews| 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. | |
|
Ilya Sherman
2017/05/11 00:42:34
nit: I'd phrase this comment as something like:
"
altimin
2017/05/11 12:38:33
Done.
| |
| 406 TEST_P(HistogramTest, AddCount_LargeCountsDontOverflow) { | |
| 407 const size_t kBucketCount = 10; | |
| 408 Histogram* histogram = static_cast<Histogram*>(Histogram::FactoryGet( | |
| 409 "AddCountHistogram", 10, 50, kBucketCount, HistogramBase::kNoFlags)); | |
| 410 | |
| 411 const int count = (1 << 30) - 1; | |
| 412 | |
| 413 // Repeat N times to make sure that there is no internal value overflow. | |
| 414 for (int i = 0; i < 10; ++i) { | |
| 415 histogram->AddCount(42, count); | |
| 416 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta(); | |
| 417 EXPECT_EQ(count, samples->TotalCount()); | |
| 418 EXPECT_EQ(count, samples->GetCount(42)); | |
| 419 } | |
| 420 } | |
| 421 | |
| 404 // Make sure histogram handles out-of-bounds data gracefully. | 422 // Make sure histogram handles out-of-bounds data gracefully. |
| 405 TEST_P(HistogramTest, BoundsTest) { | 423 TEST_P(HistogramTest, BoundsTest) { |
| 406 const size_t kBucketCount = 50; | 424 const size_t kBucketCount = 50; |
| 407 Histogram* histogram = static_cast<Histogram*>( | 425 Histogram* histogram = static_cast<Histogram*>( |
| 408 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, | 426 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, |
| 409 HistogramBase::kNoFlags)); | 427 HistogramBase::kNoFlags)); |
| 410 | 428 |
| 411 // Put two samples "out of bounds" above and below. | 429 // Put two samples "out of bounds" above and below. |
| 412 histogram->Add(5); | 430 histogram->Add(5); |
| 413 histogram->Add(-50); | 431 histogram->Add(-50); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 // CustomHistogram needs at least 1 valid range. | 761 // CustomHistogram needs at least 1 valid range. |
| 744 custom_ranges.clear(); | 762 custom_ranges.clear(); |
| 745 custom_ranges.push_back(0); | 763 custom_ranges.push_back(0); |
| 746 EXPECT_DEATH_IF_SUPPORTED( | 764 EXPECT_DEATH_IF_SUPPORTED( |
| 747 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 765 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
| 748 HistogramBase::kNoFlags), | 766 HistogramBase::kNoFlags), |
| 749 ""); | 767 ""); |
| 750 } | 768 } |
| 751 | 769 |
| 752 } // namespace base | 770 } // namespace base |
| OLD | NEW |