OLD | NEW |
1 // Copyright (c) 2011 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 // Test of classes in tracked_time.cc | 5 // Test of classes in tracked_time.cc |
6 | 6 |
7 #include "base/profiler/tracked_time.h" | 7 #include "base/profiler/tracked_time.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Now make sure that we bracketed our tracked time nicely. | 69 // Now make sure that we bracketed our tracked time nicely. |
70 Duration before = now - TrackedTime(ticks_before); | 70 Duration before = now - TrackedTime(ticks_before); |
71 EXPECT_LE(0, before.InMilliseconds()); | 71 EXPECT_LE(0, before.InMilliseconds()); |
72 Duration after = now - TrackedTime(ticks_after); | 72 Duration after = now - TrackedTime(ticks_after); |
73 EXPECT_GE(0, after.InMilliseconds()); | 73 EXPECT_GE(0, after.InMilliseconds()); |
74 } | 74 } |
75 | 75 |
76 TEST(TrackedTimeTest, TrackedTimerDisabled) { | 76 TEST(TrackedTimeTest, TrackedTimerDisabled) { |
77 // Check to be sure disabling the collection of data induces a null time | 77 // Check to be sure disabling the collection of data induces a null time |
78 // (which we know will return much faster). | 78 // (which we know will return much faster). |
79 if (!ThreadData::InitializeAndSetTrackingStatus(false)) | 79 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
80 return; | 80 return; |
81 // Since we disabled tracking, we should get a null response. | 81 // Since we disabled tracking, we should get a null response. |
82 TrackedTime track_now = ThreadData::Now(); | 82 TrackedTime track_now = ThreadData::Now(); |
83 EXPECT_TRUE(track_now.is_null()); | 83 EXPECT_TRUE(track_now.is_null()); |
84 track_now = ThreadData::NowForStartOfRun(NULL); | 84 track_now = ThreadData::NowForStartOfRun(NULL); |
85 EXPECT_TRUE(track_now.is_null()); | 85 EXPECT_TRUE(track_now.is_null()); |
86 track_now = ThreadData::NowForEndOfRun(); | 86 track_now = ThreadData::NowForEndOfRun(); |
87 EXPECT_TRUE(track_now.is_null()); | 87 EXPECT_TRUE(track_now.is_null()); |
88 } | 88 } |
89 | 89 |
90 TEST(TrackedTimeTest, TrackedTimerEnabled) { | 90 TEST(TrackedTimeTest, TrackedTimerEnabled) { |
91 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 91 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 92 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
92 return; | 93 return; |
93 // Make sure that when we enable tracking, we get a real timer result. | 94 // Make sure that when we enable tracking, we get a real timer result. |
94 | 95 |
95 // First get a 64 bit timer (which should not be null). | 96 // First get a 64 bit timer (which should not be null). |
96 base::TimeTicks ticks_before = base::TimeTicks::Now(); | 97 base::TimeTicks ticks_before = base::TimeTicks::Now(); |
97 EXPECT_FALSE(ticks_before.is_null()); | 98 EXPECT_FALSE(ticks_before.is_null()); |
98 | 99 |
99 // Then get a 32 bit timer that can be null when it wraps. | 100 // Then get a 32 bit timer that can be null when it wraps. |
100 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use | 101 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use |
101 // ThreadData::Now(). It can sometimes return the null time. | 102 // ThreadData::Now(). It can sometimes return the null time. |
102 TrackedTime now = ThreadData::Now(); | 103 TrackedTime now = ThreadData::Now(); |
103 | 104 |
104 // Then get a bracketing time. | 105 // Then get a bracketing time. |
105 base::TimeTicks ticks_after = base::TimeTicks::Now(); | 106 base::TimeTicks ticks_after = base::TimeTicks::Now(); |
106 EXPECT_FALSE(ticks_after.is_null()); | 107 EXPECT_FALSE(ticks_after.is_null()); |
107 | 108 |
108 // Now make sure that we bracketed our tracked time nicely. | 109 // Now make sure that we bracketed our tracked time nicely. |
109 Duration before = now - TrackedTime(ticks_before); | 110 Duration before = now - TrackedTime(ticks_before); |
110 EXPECT_LE(0, before.InMilliseconds()); | 111 EXPECT_LE(0, before.InMilliseconds()); |
111 Duration after = now - TrackedTime(ticks_after); | 112 Duration after = now - TrackedTime(ticks_after); |
112 EXPECT_GE(0, after.InMilliseconds()); | 113 EXPECT_GE(0, after.InMilliseconds()); |
113 } | 114 } |
114 | 115 |
115 } // namespace tracked_objects | 116 } // namespace tracked_objects |
OLD | NEW |