58 PROF_TIMER(
const std::string& aName,
bool aAutostart =
true ) :
107 void Show( std::ostream& aStream = std::cerr )
109 using DURATION = std::chrono::duration<double, std::nano>;
112 const double cnt = duration.count();
116 aStream <<
m_name <<
" took ";
120 aStream << cnt <<
"ns";
122 aStream << ( cnt / 1e3 ) <<
"µs";
124 aStream << ( cnt / 1e6 ) <<
"ms";
126 aStream << ( cnt / 1e9 ) <<
"s";
128 aStream << std::endl;
136 template <
typename DURATION>
144 return std::chrono::duration_cast<DURATION>( stoptime - starttime );
151 double msecs(
bool aSinceLast =
false )
153 using DUR_MS = std::chrono::duration<double, std::milli>;
159 using DURATION = std::chrono::duration<double, std::nano>;
162 const double cnt = duration.count();
174 std::stringstream time;
179 time << ( cnt / 1e3 ) <<
"µs";
181 time << ( cnt / 1e6 ) <<
"ms";
183 time << ( cnt / 1e9 ) <<
"s";
197 using CLOCK = std::chrono::high_resolution_clock;
222template <
typename DURATION>
288 void Show( std::ostream& aStream = std::cerr )
291 aStream <<
m_name <<
": ";
294 aStream << std::endl;
305 using CLOCK = std::chrono::high_resolution_clock;
349 using DUR_MS = std::chrono::duration<double, std::milli>;
350 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)
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.