Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/base/histograms.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 using base::TimeDelta; | |
| 12 using Sample = base::HistogramBase::Sample; | |
| 13 | |
| 14 namespace cc { | |
| 15 | |
| 16 class ScopedUMAHistogramAreaTimerBaseTest : public ::testing::Test { | |
| 17 protected: | |
| 18 void ExpectInvalid(base::TimeDelta elapsed, int area) { | |
| 19 Sample time_microseconds; | |
| 20 Sample pixels_per_ms; | |
| 21 EXPECT_FALSE(ScopedUMAHistogramAreaTimerBase::GetHistogramValues( | |
| 22 elapsed, area, &time_microseconds, &pixels_per_ms)); | |
| 23 } | |
| 24 | |
| 25 void ExpectValidHistogramValues(base::TimeDelta elapsed, | |
| 26 int area, | |
| 27 Sample expected_time_microseconds, | |
| 28 Sample expected_pixels_per_ms) { | |
| 29 Sample time_microseconds; | |
| 30 Sample pixels_per_ms; | |
| 31 ASSERT_TRUE(ScopedUMAHistogramAreaTimerBase::GetHistogramValues( | |
| 32 elapsed, area, &time_microseconds, &pixels_per_ms)); | |
| 33 EXPECT_EQ(expected_time_microseconds, time_microseconds); | |
| 34 EXPECT_EQ(expected_pixels_per_ms, pixels_per_ms); | |
| 35 } | |
| 36 }; | |
| 37 | |
| 38 namespace { | |
| 39 | |
| 40 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, CommonCase) { | |
| 41 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 1000, 500, 2000); | |
| 42 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(300), 1000, 300, 3333); | |
| 43 } | |
| 44 | |
| 45 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroArea) { | |
| 46 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 0, 500, 0); | |
| 47 } | |
| 48 | |
| 49 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroTime) { | |
| 50 ExpectValidHistogramValues(TimeDelta(), 1000, 0, | |
| 51 std::numeric_limits<Sample>::max()); | |
|
chrishtr
2015/04/13 19:54:09
Shouldn't this case just bail and not record a his
jbroman
2015/04/13 19:58:04
Should it? It seems to me that if we do often mana
chrishtr
2015/04/13 20:06:19
I think it would be bad to average with infinity (
jbroman
2015/04/13 20:52:52
Well, not infinity, just a big number. And of cour
| |
| 52 } | |
| 53 | |
| 54 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroTimeAndArea) { | |
| 55 ExpectInvalid(TimeDelta(), 0); | |
| 56 } | |
| 57 | |
| 58 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, VeryLargeTime) { | |
| 59 ExpectValidHistogramValues(TimeDelta::FromHours(24), 1000, | |
| 60 std::numeric_limits<Sample>::max(), 0); | |
| 61 } | |
| 62 | |
| 63 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, VeryLargeArea) { | |
| 64 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 1000000000, 500, | |
| 65 2000000000); | |
| 66 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(1000), | |
| 67 std::numeric_limits<int>::max(), 1000, | |
| 68 std::numeric_limits<Sample>::max()); | |
| 69 } | |
| 70 | |
| 71 } // namespace | |
| 72 } // namespace cc | |
| OLD | NEW |