![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/Timer.h>
Scope guard-like stopwatch class to automatically log measured execution time on destruction of the guard object. More...
Scope guard-like stopwatch class to automatically log measured execution time on destruction of the guard object.
Example:
Also, this class can be used to log the average execution time of a code snippet without flooding the logs, as illustrated in the example below:
Public Types | |
using | msec = std::chrono::milliseconds |
Public Member Functions | |
LoggingTimer (const std::string &name="", const std::string &component="", bool start=true, Log::Level logLevel=Log::Level::Info, bool resetStatsAfterLogging=true) | |
Create a new LoggingTimer instance, make sure to capture it in a variable. | |
~LoggingTimer () | |
destructor, also calls pause() which logs the run time | |
void | resume () |
starts or resumes the timer | |
void | pause (msec logSilencePeriod=msec(0)) |
it pauses the timer and logs the output unless 'logSilencePeriod' is set non zero value | |
Utils::ScopeGuard< std::function< void()> > | startScopedTimer (msec logSilencePeriod=msec(0)) |
returns ScopeGuard stopwatch to automatically calls pause() on destruction of the guard object. | |
void | reset () |
Stop and reset timer. | |
|
explicit |
Create a new LoggingTimer instance, make sure to capture it in a variable.
name | Name of the section, will be appended to the log message. |
component | Logger component to use |
start | If true then it starts the timer upon class construction |
logLevel | Log level to use. |
resetStatsAfterLogging | If set to true, then the stats used for the average run time calculation are reset after each time we log a message |
it pauses the timer and logs the output unless 'logSilencePeriod' is set non zero value
logSilencePeriod | if not set to zero, then the run time is only logged once during this duration |
Utils::ScopeGuard< std::function< void()> > startScopedTimer | ( | msec | logSilencePeriod = msec(0) | ) |
returns ScopeGuard stopwatch to automatically calls pause() on destruction of the guard object.
logSilencePeriod | if not set to zero, then the run time is only logged once during this duration Example: auto timerScope = m_timer.startScopedTimer(); // m_timer is a member variable in this case
|