ScopedTimer#
Fully qualified name: usd_optimize::ScopedTimer
-
class ScopedTimer#
Manual timer that can be started, paused, and stopped. Useful for accumulating time spent on a section of code.
Timers can have a log level which controls whether they are printed to the console.
Public Functions
-
ScopedTimer(const std::string &label, bool paused = false)#
Create a timer with a label.
When the timer is stopped the duration will be printed along with the label. This timer defaults to a logging level of Info.
- Parameters:
label – Label to print when the timer finishes.
paused – Whether the timer will be initialised in a paused state
- ScopedTimer(
- const std::string &label,
- const std::string &category,
- LogLevel level,
- bool paused = false,
Create a timer with a category and logging level.
This constructor creates a scoped timer with a reporting category, if required, and also takes a logging level. This allows controlling whether the timer will print based on the current verbosity.
- Parameters:
label – The label to log when the timer finishes.
category – The category (used for reporting)
level – The log level of messages from this timer.
paused – Whether the timer will be initialised in a paused state
-
virtual ~ScopedTimer()#
Destructor.
-
ScopedTimer(const ScopedTimer&) = delete#
Disable copying.
-
ScopedTimer &operator=(const ScopedTimer&) = delete#
-
void start()#
(Re)start timing.
-
void pause()#
Temporarily pause timing.
When paused, the accumulated duration is updated. Timing can be restarted with
start.
-
void stop()#
Stop timing.
This will also print/log the duration of the timer to stdout/reports.
-
void setLabel(const std::string &label)#
Change the label printed when the timer stops.
Useful when the outcome being timed is only known partway through the scope (e.g. a write that may fail), so the final message can reflect success or failure without giving up the timer’s scoped behavior.
-
ScopedTimer(const std::string &label, bool paused = false)#