uint64_t Timer::get_elapsed_cpu_time_microseconds() const { CPUTime e; GetCPUTimeMicroSeconds(&e); return (e.user_time - m_start_time.user_time) + (e.sys_time - m_start_time.sys_time); }
void Timer::restart(const char* msg) { if (msg) { TRACE_ERR(msg << std::endl); } m_wall = GetTimeOfDayMicroSeconds(); GetCPUTimeMicroSeconds(&m_start_time); }
void Timer::start(const char* msg) { // Print an optional message, something like "Starting timer t"; if (msg) TRACE_ERR( msg << std::endl); if (m_is_running) return; m_is_running = true; m_wall = GetTimeOfDayMicroSeconds(); GetCPUTimeMicroSeconds(&m_start_time); }
std::string Timer::ToString() const { std::string res; const double wall = get_elapsed_wall_time(); CPUTime e; GetCPUTimeMicroSeconds(&e); const double utime = (e.user_time - m_start_time.user_time) * 1e-6; const double stime = (e.sys_time - m_start_time.sys_time) * 1e-6; std::stringstream ss; ss << "wall " << wall << " sec. user " << utime << " sec. sys " << stime << " sec. total " << utime + stime << " sec."; res.append(ss.str()); return res; }