quickprof::Profiler Class Reference

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

#include <quickprof.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

static Profilerinstance ()
 Accesses the singleton instance.


Detailed Description

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

Definition at line 212 of file quickprof.h.


Constructor & Destructor Documentation

quickprof::Profiler::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.

Definition at line 416 of file quickprof.h.

quickprof::Profiler::~Profiler (  )  [inline]

Definition at line 429 of file quickprof.h.


Member Function Documentation

Profiler & quickprof::Profiler::instance (  )  [inline, static]

Accesses the singleton instance.

Returns:
The Profiler instance.

Definition at line 437 of file quickprof.h.

void quickprof::Profiler::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:
smoothing The 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.
outputFilename If defined, enables timing data to be printed to a data file for later analysis.
printPeriod Defines 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.
printFormat Defines the format used when printing data to a file.

Definition at line 466 of file quickprof.h.

void quickprof::Profiler::beginBlock ( const std::string &  name  )  [inline]

Begins timing the named block of code.

Parameters:
name The name of the block.

Definition at line 516 of file quickprof.h.

void quickprof::Profiler::endBlock ( const std::string &  name  )  [inline]

Defines the end of the named timing block.

Parameters:
name The name of the block.

Definition at line 548 of file quickprof.h.

void quickprof::Profiler::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.

Definition at line 570 of file quickprof.h.

double quickprof::Profiler::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:
name The name of the block.
format The desired time format to use for the result.
Returns:
The block's average duration per cycle.

Definition at line 665 of file quickprof.h.

double quickprof::Profiler::getTotalDuration ( const std::string &  name,
TimeFormat  format 
) [inline]

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

Parameters:
name The name of the block.
format The desired time format to use for the result.
Returns:
The block total time.

Definition at line 712 of file quickprof.h.

double quickprof::Profiler::getTimeSinceInit ( TimeFormat  format  )  [inline]

Computes the elapsed time since the profiler was initialized.

Parameters:
format The desired time format to use for the result.
Returns:
The elapsed time.

Definition at line 761 of file quickprof.h.

std::string quickprof::Profiler::getSummary ( TimeFormat  format = PERCENT  )  [inline]

Returns a summary of total times in each block.

Parameters:
format The desired time format to use for the results.
Returns:
The timing summary as a string.

Definition at line 793 of file quickprof.h.


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

Generated on Wed Mar 26 10:40:47 2008 for QuickProf by  doxygen 1.5.5