public

Inheritance Graph

graph BT
	Profiler
	click Profiler "classUtil_1_1Profiling_1_1Profiler"

Description

Profiling code (measure running time, memory consumption and log it)

The profiler manages actions. An action is an extendable object that can be annotated by arbitrary attributes. The profile contains convenience functions to create actions and to annotate some standard attributes. Different loggers can be attached to the profiler that are used to write the actions to streams (e.g. a file, stdout). For example, the profiler can be used to measure the duration and memory consumption of a code section:

Util::Profiling::Profiler profiler;
Util::Profiling::LoggerPlainText logger(std::cout);

profiler.registerLogger(&logger);

auto prepareAction = profiler.beginTimeMemoryAction("My preparation code");
...
My preparation code
...
profiler.endTimeMemoryAction(prepareAction);
auto executeAction = profiler.beginTimeMemoryAction("My execute code");
...
My execute code
...
profiler.endTimeMemoryAction(executeAction);

profiler.unregisterLogger(&logger);

Public Functions

   
   
  Profiler()
   
  ~Profiler()
   
Action createAction(const std::string & description) const
   
void logAction(const Action & action) const
   
void annotateTime( Action & action, const Util::StringIdentifier & attribute) const
   
void annotateMemory( Action & action, const Util::StringIdentifier & attribute) const
   
Action beginTimeMemoryAction(const std::string & description) const
   
void endTimeMemoryAction( Action & action) const
   
void registerLogger( Logger * output)
   
void unregisterLogger( Logger * output)

Documentation

function
Util::Profiling::Profiler::Profiler

public
   
   
Profiler( )

Defined in Util/Profiling/Profiler.h:101


function
Util::Profiling::Profiler::~Profiler

public
   
   
~Profiler( )

Defined in Util/Profiling/Profiler.h:102


function
Util::Profiling::Profiler::createAction

public const
     
     
Action createAction( const std::string & description ) const

Create a new action and set its description.

Parameters

description
Human-readable description of the action

Returns

The created action

Defined in Util/Profiling/Profiler.h:110


function
Util::Profiling::Profiler::logAction

public const
     
     
void logAction( const Action & action ) const

Output an action to the associated loggers.

Parameters

action
Action that will be logged

Defined in Util/Profiling/Profiler.h:117


function
Util::Profiling::Profiler::annotateTime

public const
     
     
void annotateTime( Action & action,
  const Util::StringIdentifier & attribute
) const    

Measure the current time and store it in an attribute of an action.

Parameters

action
Action that will be annotated
attribute
Attribute name that will be added to the action

Defined in Util/Profiling/Profiler.h:125


function
Util::Profiling::Profiler::annotateMemory

public const
     
     
void annotateMemory( Action & action,
  const Util::StringIdentifier & attribute
) const    

Measure the current memory consumption and store it in an attribute of an action.

Parameters

action
Action that will be annotated
attribute
Attribute name that will be added to the action

Defined in Util/Profiling/Profiler.h:135


function
Util::Profiling::Profiler::beginTimeMemoryAction

public const
     
     
Action beginTimeMemoryAction( const std::string & description ) const

Create a new action, set its description, and store current time and memory consumption of the process.

Parameters

description
Human-readable description of the action

Returns

The created action containing time and memory

Defined in Util/Profiling/Profiler.h:145


function
Util::Profiling::Profiler::endTimeMemoryAction

public const
     
     
void endTimeMemoryAction( Action & action ) const

Finish an action. The current time and memory consumption will be stored to allow comparison with the beginning of the action. The action will be logged.

Parameters

action
Action that will be annotated and logged

Defined in Util/Profiling/Profiler.h:154


function
Util::Profiling::Profiler::registerLogger

public
     
     
void registerLogger( Logger * output )

Register a logger that will be used to output profiling information. The information will be formatted internally by the logger.

Parameters

output
Logger that will be used to write profiling output. The given logger has to stay writeable at least until this object is destroyed or the logger is removed with* unregisterLogger() *.

Defined in Util/Profiling/Profiler.h:164


function
Util::Profiling::Profiler::unregisterLogger

public
     
     
void unregisterLogger( Logger * output )

Remove the registered logger.

Parameters

output
Logger that will be removed

Defined in Util/Profiling/Profiler.h:171