Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Profiler Class Reference

A singleton class that manages timing for a set of profiling blocks. More...

#include <quickprof.h>

Public Member Functions

 Profiler ()
 Useful for creating multiple Profiler instances. More...
 
 ~Profiler ()
 
void init (double smoothing=0.0, const std::string &outputFilename="", size_t printPeriod=1, TimeFormat printFormat=MILLISECONDS)
 Initializes the profiler. More...
 
void beginBlock (const std::string &name)
 Begins timing the named block of code. More...
 
void endBlock (const std::string &name)
 Defines the end of the named timing block. More...
 
void endCycle ()
 Defines the end of a profiling cycle. More...
 
double getAvgDuration (const std::string &name, TimeFormat format) const
 Returns the average time used in the named block per profiling cycle. More...
 
double getTotalDuration (const std::string &name, TimeFormat format)
 Returns the total time spent in the named block since the profiler was initialized. More...
 
double getTimeSinceInit (TimeFormat format)
 Computes the elapsed time since the profiler was initialized. More...
 
std::string getSummary (TimeFormat format=PERCENT)
 Returns a summary of total times in each block. More...
 

Static Public Member Functions

static Profilerinstance ()
 Accesses the singleton instance. More...
 

Detailed Description

A singleton class that manages timing for a set of profiling blocks.

Constructor & Destructor Documentation

Profiler ( )
inline

Useful for creating multiple Profiler instances.

Normally the Profiler class should be accessed only through the singleton instance method, which provides global access to a single static Profiler instance. However, it is also possible to create several local Profiler instances, if necessary.

~Profiler ( )
inline

Member Function Documentation

void beginBlock ( const std::string &  name)
inline

Begins timing the named block of code.

Parameters
nameThe name of the block.
void endBlock ( const std::string &  name)
inline

Defines the end of the named timing block.

Parameters
nameThe name of the block.
void endCycle ( )
inline

Defines the end of a profiling cycle.

Use this regularly by calling it at the end of all timing blocks. This is necessary for smoothing and for file output, but not if you just want a total summary at the end of execution (i.e. from getSummary). This must not be called within a timing block.

double getAvgDuration ( const std::string &  name,
TimeFormat  format 
) const
inline

Returns the average time used in the named block per profiling cycle.

If smoothing is disabled (see init), this returns the most recent duration measurement.

Parameters
nameThe name of the block.
formatThe desired time format to use for the result.
Returns
The block's average duration per cycle.
std::string getSummary ( TimeFormat  format = PERCENT)
inline

Returns a summary of total times in each block.

Parameters
formatThe desired time format to use for the results.
Returns
The timing summary as a string.
double getTimeSinceInit ( TimeFormat  format)
inline

Computes the elapsed time since the profiler was initialized.

Parameters
formatThe desired time format to use for the result.
Returns
The elapsed time.
double getTotalDuration ( const std::string &  name,
TimeFormat  format 
)
inline

Returns the total time spent in the named block since the profiler was initialized.

Parameters
nameThe name of the block.
formatThe desired time format to use for the result.
Returns
The block total time.
void init ( double  smoothing = 0.0,
const std::string &  outputFilename = "",
size_t  printPeriod = 1,
TimeFormat  printFormat = MILLISECONDS 
)
inline

Initializes the profiler.

This must be called first. If this is never called, the profiler is effectively disabled, and all other functions will return immediately. This can be called more than once to re-initialize the profiler, which erases all previous profiling block names and their timing data.

Parameters
smoothingThe measured duration for each profile block can be averaged across multiple cycles, and this parameter defines the smoothness of this averaging process. The higher the value, the smoother the resulting average durations will appear. Leaving it at zero will essentially disable the smoothing effect. More specifically, this parameter is a time constant (defined in terms of cycles) that defines an exponentially-weighted moving average. For example, a value of 4.0 means the past four cycles will contribute 63% of the current weighted average. This value must be >= 0.
outputFilenameIf defined, enables timing data to be printed to a data file for later analysis.
printPeriodDefines how often data is printed to the file, in number of profiling cycles. For example, set this to 1 if you want data printed after each cycle, or 5 if you want it printed every 5 cycles. It is a good idea to increase this if you don't want huge data files. Keep in mind, however, that when you increase this, you might want to increase the smoothing parameter. (A good heuristic is to set the smoothing parameter equal to the print period.) This value must be >= 1.
printFormatDefines the format used when printing data to a file.
Profiler & instance ( )
inlinestatic

Accesses the singleton instance.

Returns
The Profiler instance.

The documentation for this class was generated from the following file: