54 PROF_TIMER(
const std::string& aName,
bool aAutostart =
true ) :
104 void Show( std::ostream& aStream = std::cerr )
106 using DURATION = std::chrono::duration<double, std::nano>;
109 const double cnt = duration.count();
113 aStream <<
m_name <<
" took ";
117 aStream << cnt <<
"ns";
119 aStream << ( cnt / 1e3 ) <<
"µs";
121 aStream << ( cnt / 1e6 ) <<
"ms";
123 aStream << ( cnt / 1e9 ) <<
"s";
125 aStream << std::endl;
133 template <
typename DURATION>
141 return std::chrono::duration_cast<DURATION>( stoptime - starttime );
148 double msecs(
bool aSinceLast =
false )
150 using DUR_MS = std::chrono::duration<double, std::milli>;
156 using DURATION = std::chrono::duration<double, std::nano>;
159 const double cnt = duration.count();
171 std::stringstream time;
176 time << ( cnt / 1e3 ) <<
"µs";
178 time << ( cnt / 1e6 ) <<
"ms";
180 time << ( cnt / 1e9 ) <<
"s";
194 using CLOCK = std::chrono::high_resolution_clock;
221template <
typename DURATION>
287 void Show( std::ostream& aStream = std::cerr )
290 aStream <<
m_name <<
": ";
293 aStream << std::endl;
304 using CLOCK = std::chrono::high_resolution_clock;
348 using DUR_MS = std::chrono::duration<double, std::milli>;
349 return static_cast<DUR_MS
>( a - b ).count();
void AddTimer(PROF_TIMER &aTimer)
void Checkpoint(const std::string &aName)
std::chrono::high_resolution_clock CLOCK
std::vector< CHECKPOINT > m_checkpoints
double delta_ms(TIME_POINT a, TIME_POINT b)
std::chrono::time_point< CLOCK > TIME_POINT
LATENCY_PROBE(const std::string &aName, int aStages=8)
unsigned long long operator++(int)
PROF_COUNTER(const std::string &aName)
unsigned long long Count() const
void Show(std::ostream &aStream=std::cerr)
std::atomic_ullong m_count
A small class to help profiling.
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
std::chrono::high_resolution_clock CLOCK
const std::string & GetName() const
DURATION SinceStart(bool aSinceLast=false)
void Start()
Start or restart the counter.
PROF_TIMER()
Create a PROF_COUNTER for measuring an elapsed time in milliseconds.
std::chrono::time_point< CLOCK > TIME_POINT
PROF_TIMER(const std::string &aName, bool aAutostart=true)
Create a PROF_COUNTER for measuring an elapsed time in milliseconds.
double msecs(bool aSinceLast=false)
DURATION & m_duration
The duration to update at the end of the scope.
SCOPED_PROF_TIMER(DURATION &aDuration)
PROF_TIMER m_counter
The counter to use to do the profiling.
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.