Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: base/time/time_win_unittest.cc

Issue 2951413003: Add UMA for High Resolution Timer Usage (Closed)
Patch Set: Added suspend / resume logic Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
gab 2017/06/28 16:39:33 Why is this guaranteed? Can't Now() tick between R
stanisc 2017/06/28 22:28:35 Since the high resolution timer isn't activated ye
308
309 Sleep(10);
310 // 0% usage since the timer isn't activated.
311 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
312
313 Time::ActivateHighResolutionTimer(true);
314 Time::ResetHighResolutionTimerUsage();
315
316 Sleep(20);
317 // 100% usage since the timer has been activated entire time.
318 EXPECT_EQ(100.0, Time::GetHighResolutionTimerUsage());
319
320 Time::ActivateHighResolutionTimer(false);
321 Sleep(20);
322 double usage1 = Time::GetHighResolutionTimerUsage();
323 // usage1 should be about 50%.
324 EXPECT_LT(usage1, 100.0);
325 EXPECT_GT(usage1, 0.0);
gab 2017/06/28 16:39:33 Precise enough to use EXPECT_NEAR? (and below)
stanisc 2017/06/28 22:28:35 In my experience anything involving time checks is
326
327 Time::ActivateHighResolutionTimer(true);
328 Sleep(10);
329 Time::ActivateHighResolutionTimer(false);
330 double usage2 = Time::GetHighResolutionTimerUsage();
331 // usage2 should be about 60%.
332 EXPECT_LT(usage2, 100.0);
333 EXPECT_GT(usage2, usage1);
334
335 Time::ResetHighResolutionTimerUsage();
336 EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
337 }
338
303 } // namespace base 339 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698