Class Profiler

Nested Relationships

Nested Types

Class Documentation

class Profiler

This is a simple thread-safe tool for counting time spent in various chunks of code. This is different from external profiling tools in that it allows the user to count time spent in various bits of code (sub-function granularity) or count how many times certain pieces of code are executed.

Public Functions

Profiler(const Profiler&) = delete
Profiler &operator=(const Profiler&) = delete
inline Profiler(bool printOnDestroy = false, bool autoStart = false)

Constructor. It is allowed to separately instantiate this class (not only as a singleton)

inline ~Profiler()

Destructor.

void start()

Start counting time.

void stop()

Stop counting time.

void clear()

Clear counted time and events.

void event(const std::string &name, const unsigned int times = 1)

Count a specific event for a number of times.

void average(const std::string &name, const double value)

Maintain the average of a specific value.

void begin(const std::string &name)

Begin counting time for a specific chunk of code.

void end(const std::string &name)

Stop counting time for a specific chunk of code.

void status(std::ostream &out = std::cout, bool merge = true)

Print the status of the profiled code chunks and events. Optionally, computation done by different threads can be printed separately.

void console()

Print the status of the profiled code chunks and events to the console (using msg::Console)

inline bool running() const

Check if the profiler is counting time or not.

Public Static Functions

static Profiler &Instance()

Return an instance of the class.

static inline void Start()

Start counting time.

static inline void Stop()

Stop counting time.

static inline void Clear()

Clear counted time and events.

static inline void Event(const std::string &name, const unsigned int times = 1)

Count a specific event for a number of times.

static inline void Average(const std::string &name, const double value)

Maintain the average of a specific value.

static inline void Begin(const std::string &name)

Begin counting time for a specific chunk of code.

static inline void End(const std::string &name)

Stop counting time for a specific chunk of code.

static inline void Status(std::ostream &out = std::cout, bool merge = true)

Print the status of the profiled code chunks and events. Optionally, computation done by different threads can be printed separately.

static inline void Console()

Print the status of the profiled code chunks and events to the console (using msg::Console)

static inline bool Running()

Check if the profiler is counting time or not.

class ScopedBlock

This instance will call Profiler::begin() when constructed and Profiler::end() when it goes out of scope.

Public Functions

inline ScopedBlock(const std::string &name, Profiler &prof = Profiler::Instance())

Start counting time for the block named name of the profiler prof.

inline ~ScopedBlock()
class ScopedStart

This instance will call Profiler::start() when constructed and Profiler::stop() when it goes out of scope. If the profiler was already started, this block’s constructor and destructor take no action.

Public Functions

inline ScopedStart(Profiler &prof = Profiler::Instance())

Take as argument the profiler instance to operate on (prof)

inline ~ScopedStart()