ImFusion SDK 4.3
MultiTimer Class Reference

#include <ImFusion/Core/Timer.h>

This class can be used to help the developer to profile the run time of different parts of the same process. More...

Detailed Description

This class can be used to help the developer to profile the run time of different parts of the same process.

Each time startTaskTimer is called, it will start registering the run time of that specific task, and it stops the timer of any other running task. the report which contains run time of each task is logged periodically in order to prevent flooding the logs.

calling startTaskTimer searches if the provided task name has been run before. If yes, then it will add the run time to its total run time, if not it will create an new entry for the task name. this search need a small overhead, but since we use unordered_map to store the tasks names, this should not slow down the execution of the process.

See also
Timer, LoggingTimer

The following code shows a use case example:

MultiTimer timer("my algorithm");
for (int i = 0; i < 10; ++i)
{
timer.startTaskTimer("task 1");
timer.startTaskTimer("task 2");
timer.startTaskTimer("task 3");
}
timer.stopCurrentTaskTimer();
MultiTimer(std::string_view component, int logIntervalsSeconds=5, Log::Level logLevel=Log::Level::Info)
constructor of the class
T sleep_for(T... args)

here is the resulting report from the code above:

[my algorithm] task 1 => Avg. time: 100.076 ms | num: 10 | total: 1.001 s
[my algorithm] task 2 => Avg. time: 150.103 ms | num: 10 | total: 1.501 s
[my algorithm] task 3 => Avg. time: 85.082 ms | num: 10 | total: 850.821 ms

Public Member Functions

 MultiTimer (std::string_view component, int logIntervalsSeconds=5, Log::Level logLevel=Log::Level::Info)
 constructor of the class
 
 ~MultiTimer ()
 the deconstructor will automatically log the run time report
 
void startTaskTimer (std::string_view taskName)
 starts the timer the specified tasks, it also stops the timer of the previous task if it is still running
 
void stopCurrentTaskTimer (bool forcePrint=false)
 stops the timer of the current task
 

Constructor & Destructor Documentation

◆ MultiTimer()

MultiTimer ( std::string_view component,
int logIntervalsSeconds = 5,
Log::Level logLevel = Log::Level::Info )

constructor of the class

Parameters
componentthe name of the process, which will be printed on each line of the report
logIntervalsSecondsthe time interval between two consecutive logs (in seconds)
logLevelleg level used to print the report

Member Function Documentation

◆ stopCurrentTaskTimer()

void stopCurrentTaskTimer ( bool forcePrint = false)

stops the timer of the current task

Parameters
forcePrintprints the run time report without taking in consideration logIntervalsSeconds

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close