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 <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 #include <process.h> | 7 #include <process.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 << "ticks=" << ticks << ", to be converted via logic path: " | 293 << "ticks=" << ticks << ", to be converted via logic path: " |
294 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); | 294 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 TEST(TimeDelta, ConstexprInitialization) { | 298 TEST(TimeDelta, ConstexprInitialization) { |
299 // Make sure that TimeDelta works around crbug.com/635974 | 299 // Make sure that TimeDelta works around crbug.com/635974 |
300 EXPECT_EQ(kExpectedDeltaInMilliseconds, kConstexprTimeDelta.InMilliseconds()); | 300 EXPECT_EQ(kExpectedDeltaInMilliseconds, kConstexprTimeDelta.InMilliseconds()); |
301 } | 301 } |
302 | 302 |
| 303 TEST(HighResolutionTimer, GetUsage) { |
| 304 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage()); |
| 305 |
| 306 Time::ResetHighResolutionTimerUsage(); |
| 307 |
| 308 // 0% usage since the timer isn't activated regardless of how much time has |
| 309 // elapsed. |
| 310 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage()); |
| 311 Sleep(10); |
| 312 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage()); |
| 313 |
| 314 Time::ActivateHighResolutionTimer(true); |
| 315 Time::ResetHighResolutionTimerUsage(); |
| 316 |
| 317 Sleep(20); |
| 318 // 100% usage since the timer has been activated entire time. |
| 319 EXPECT_EQ(100.0, Time::GetHighResolutionTimerUsage()); |
| 320 |
| 321 Time::ActivateHighResolutionTimer(false); |
| 322 Sleep(20); |
| 323 double usage1 = Time::GetHighResolutionTimerUsage(); |
| 324 // usage1 should be about 50%. |
| 325 EXPECT_LT(usage1, 100.0); |
| 326 EXPECT_GT(usage1, 0.0); |
| 327 |
| 328 Time::ActivateHighResolutionTimer(true); |
| 329 Sleep(10); |
| 330 Time::ActivateHighResolutionTimer(false); |
| 331 double usage2 = Time::GetHighResolutionTimerUsage(); |
| 332 // usage2 should be about 60%. |
| 333 EXPECT_LT(usage2, 100.0); |
| 334 EXPECT_GT(usage2, usage1); |
| 335 |
| 336 Time::ResetHighResolutionTimerUsage(); |
| 337 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage()); |
| 338 } |
| 339 |
303 } // namespace base | 340 } // namespace base |
OLD | NEW |