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

Unified Diff: base/time/time_win_unittest.cc

Issue 2951413003: Add UMA for High Resolution Timer Usage (Closed)
Patch Set: Removed NaCl changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time_win.cc ('k') | base/timer/hi_res_timer_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_win_unittest.cc
diff --git a/base/time/time_win_unittest.cc b/base/time/time_win_unittest.cc
index 17c722300d681d67d0010503bace12773b236585..d8ee7e38388639380ddd82df45613a34383f7b7a 100644
--- a/base/time/time_win_unittest.cc
+++ b/base/time/time_win_unittest.cc
@@ -300,4 +300,41 @@ TEST(TimeDelta, ConstexprInitialization) {
EXPECT_EQ(kExpectedDeltaInMilliseconds, kConstexprTimeDelta.InMilliseconds());
}
+TEST(HighResolutionTimer, GetUsage) {
+ EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
+
+ Time::ResetHighResolutionTimerUsage();
+
+ // 0% usage since the timer isn't activated regardless of how much time has
+ // elapsed.
+ EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
+ Sleep(10);
+ EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
+
+ Time::ActivateHighResolutionTimer(true);
+ Time::ResetHighResolutionTimerUsage();
+
+ Sleep(20);
+ // 100% usage since the timer has been activated entire time.
+ EXPECT_EQ(100.0, Time::GetHighResolutionTimerUsage());
+
+ Time::ActivateHighResolutionTimer(false);
+ Sleep(20);
+ double usage1 = Time::GetHighResolutionTimerUsage();
+ // usage1 should be about 50%.
+ EXPECT_LT(usage1, 100.0);
+ EXPECT_GT(usage1, 0.0);
+
+ Time::ActivateHighResolutionTimer(true);
+ Sleep(10);
+ Time::ActivateHighResolutionTimer(false);
+ double usage2 = Time::GetHighResolutionTimerUsage();
+ // usage2 should be about 60%.
+ EXPECT_LT(usage2, 100.0);
+ EXPECT_GT(usage2, usage1);
+
+ Time::ResetHighResolutionTimerUsage();
+ EXPECT_EQ(0.0, Time::GetHighResolutionTimerUsage());
+}
+
} // namespace base
« no previous file with comments | « base/time/time_win.cc ('k') | base/timer/hi_res_timer_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698