diff options
Diffstat (limited to 'lldb/unittests/Utility/TimerTest.cpp')
-rw-r--r-- | lldb/unittests/Utility/TimerTest.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lldb/unittests/Utility/TimerTest.cpp b/lldb/unittests/Utility/TimerTest.cpp index 28d8d050b3e..53d0ff12d89 100644 --- a/lldb/unittests/Utility/TimerTest.cpp +++ b/lldb/unittests/Utility/TimerTest.cpp @@ -61,7 +61,9 @@ TEST(TimerTest, CategoryTimes2) { StreamString ss; Timer::DumpCategoryTimes(&ss); double seconds1, seconds2; - ASSERT_EQ(2, sscanf(ss.GetData(), "%lf sec for CAT1%*[\n ]%lf sec for CAT2", + ASSERT_EQ(2, sscanf(ss.GetData(), + "%lf sec (total: %*lfs; child: %*lfs; count: %*d) for " + "CAT1%*[\n ]%lf sec for CAT2", &seconds1, &seconds2)) << "String: " << ss.GetData(); EXPECT_LT(0.01, seconds1); @@ -69,3 +71,38 @@ TEST(TimerTest, CategoryTimes2) { EXPECT_LT(0.001, seconds2); EXPECT_GT(0.1, seconds2); } + +TEST(TimerTest, CategoryTimesStats) { + Timer::ResetCategoryTimes(); + { + static Timer::Category tcat1("CAT1"); + Timer t1(tcat1, "."); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + static Timer::Category tcat2("CAT2"); + { + Timer t2(tcat2, "."); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + { + Timer t3(tcat2, "."); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + } + // Example output: + // 0.105202764 sec (total: 0.132s; child: 0.027s; count: 1) for CAT1 + // 0.026772798 sec (total: 0.027s; child: 0.000s; count: 2) for CAT2 + StreamString ss; + Timer::DumpCategoryTimes(&ss); + double seconds1, total1, child1, seconds2; + int count1, count2; + ASSERT_EQ( + 6, sscanf(ss.GetData(), + "%lf sec (total: %lfs; child: %lfs; count: %d) for CAT1%*[\n ]" + "%lf sec (total: %*lfs; child: %*lfs; count: %d) for CAT2", + &seconds1, &total1, &child1, &count1, &seconds2, &count2)) + << "String: " << ss.GetData(); + EXPECT_NEAR(total1 - child1, seconds1, 0.002); + EXPECT_EQ(1, count1); + EXPECT_NEAR(child1, seconds2, 0.002); + EXPECT_EQ(2, count2); +} |