6#include "cdm/utils/Logger.h"
12 using Clock = std::chrono::high_resolution_clock;
27 Clock::time_point
end;
33 Timer& GetTimer(
const std::string& label);
41 void Reset(
Timer& timer);
42 void Reset(
const std::string& label)
44 return Reset(GetTimer(label));
52 void Start(Timer& timer);
55 Timer& timer = GetTimer(label);
63 void Stop(Timer& timer);
64 void Stop(
const std::string& label)
66 return Stop(GetTimer(label));
72 Clock::duration GetDuration(Timer& timer);
75 return GetDuration(GetTimer(label));
83 double GetElapsedTime_s(Timer& timer);
86 return GetElapsedTime_s(GetTimer(label));
92 template<
typename Duration>
95 if (timer.
state == State::Running)
97 return std::chrono::duration_cast<Duration>(Clock::now() - timer.
start).count();
99 else if (timer.
state == State::Ran)
101 return std::chrono::duration_cast<Duration>(timer.
end - timer.
start).count();
105 return typename Duration::rep(0);
108 template<
typename Duration>
111 return GetElapsedTime<Duration>(GetTimer(label));
Definition: TimingProfile.h:11
virtual ~TimingProfile()
Definition: TimingProfile.h:15
double GetElapsedTime_s(const std::string &label)
Definition: TimingProfile.h:84
void Reset(const std::string &label)
Definition: TimingProfile.h:42
Duration::rep GetElapsedTime(const Timer &timer)
Definition: TimingProfile.h:93
Clock::duration GetDuration(const std::string &label)
Definition: TimingProfile.h:73
std::chrono::high_resolution_clock Clock
Definition: TimingProfile.h:12
TimingProfile()
Definition: TimingProfile.h:14
Timer & Start(const std::string &label)
Definition: TimingProfile.h:53
State
Definition: TimingProfile.h:18
std::map< std::string, Timer > m_timers
Definition: TimingProfile.h:115
Duration::rep GetElapsedTime(const std::string &label)
Definition: TimingProfile.h:109
void Stop(const std::string &label)
Definition: TimingProfile.h:64
Definition: TimingProfile.h:25
State state
Definition: TimingProfile.h:28
Clock::time_point end
Definition: TimingProfile.h:27
Clock::time_point start
Definition: TimingProfile.h:26