55 PROF_TIMER(
const std::string& aName,
bool aAutostart =
true ) :
103 void Show( std::ostream& aStream = std::cerr )
105 using DURATION = std::chrono::duration<double, std::nano>;
107 const auto duration = SinceStart<DURATION>();
108 const double cnt = duration.count();
112 aStream <<
m_name <<
" took ";
116 aStream << cnt <<
"ns";
118 aStream << cnt / 1e3 <<
"µs";
120 aStream << cnt / 1e6 <<
"ms";
122 aStream << cnt / 1e9 <<
"s";
124 aStream << std::endl;
132 template <
typename DURATION>
140 return std::chrono::duration_cast<DURATION>( stoptime - starttime );
147 double msecs(
bool aSinceLast =
false )
149 using DUR_MS = std::chrono::duration<double, std::milli>;
150 return SinceStart<DUR_MS>( aSinceLast ).count();
156 snprintf( tmp,
sizeof( tmp ),
"%s: %-6.1fms",
m_name.c_str(),
msecs() );
164 using CLOCK = std::chrono::high_resolution_clock;
189template <
typename DURATION>
255 void Show( std::ostream& aStream = std::cerr )
258 aStream <<
m_name <<
": ";
261 aStream << std::endl;
A thread-safe event counter.
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
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)
A simple RAII class to measure the time of an operation.
SCOPED_PROF_TIMER(DURATION &aDuration)
PROF_TIMER m_counter
< The counter to use to do the profiling
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.