TEST(Profiler, one_timer) { Profiler::initialize(); double wait_time = clock_resolution(); double total=0; { // uninitialize can not be in the same block as the START_TIMER START_TIMER("test_tag"); EXPECT_EQ( 1, AC); total += wait(wait_time); END_TIMER("test_tag"); START_TIMER("test_tag"); EXPECT_EQ( total, ACT); EXPECT_EQ( 2, AC); total += wait(wait_time); total += wait(wait_time); END_TIMER("test_tag"); START_TIMER("test_tag"); EXPECT_EQ( total, ACT); EXPECT_EQ( 3, AC); } // test add_call { START_TIMER("add_call"); ADD_CALLS(1000); EXPECT_EQ(1000, AC); } Profiler::uninitialize(); }
void ProfilerTest::test_one_timer() { const double TIMER_RESOLUTION = Profiler::get_resolution(); const double DELTA = TIMER_RESOLUTION*1000; double total=0; Profiler::initialize(); { // uninitialize can not be in the same block as the START_TIMER START_TIMER("test_tag"); // test that number of calls of current timer is EXPECT_EQ( 1, ACC); // wait a TIMER_RESOLUTION time total += wait_sec(TIMER_RESOLUTION); END_TIMER("test_tag"); START_TIMER("test_tag"); // test that number of calls of current timer is EXPECT_EQ( 2, ACC); // test whether difference between measured time and total time is within TIMER_RESOLUTION EXPECT_LE( abs(ACT-total), DELTA); cout << "difference: " << abs(total-ACT) << ", tolerance: " << DELTA << endl; // wait a TIMER_RESOLUTION time total += wait_sec (TIMER_RESOLUTION); total += wait_sec (TIMER_RESOLUTION); END_TIMER("test_tag"); START_TIMER("test_tag"); EXPECT_EQ( 3, ACC); EXPECT_LE( abs(ACT-total), DELTA); cout << "difference: " << abs(total-ACT) << ", tolerance: " << DELTA << endl; } // test add_call { START_TIMER("add_call"); ADD_CALLS(1000); EXPECT_EQ(1000, ACC); } // test absolute time { START_TIMER("one_second"); wait_sec(1); } std::stringstream sout; PI->output(MPI_COMM_WORLD, sout); PI->output(MPI_COMM_WORLD, cout); //EXPECT_NE( sout.str().find("\"tag\": \"Whole Program\""), string::npos ); Profiler::uninitialize(); }