A singleton class that manages timing for a set of profiling blocks.
More...
#include <quickprof.h>
A singleton class that manages timing for a set of profiling blocks.
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.
void beginBlock |
( |
const std::string & |
name | ) |
|
|
inline |
Begins timing the named block of code.
- Parameters
-
name | The name of the block. |
void endBlock |
( |
const std::string & |
name | ) |
|
|
inline |
Defines the end of the named timing block.
- Parameters
-
name | The name of the block. |
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
-
name | The name of the block. |
format | The desired time format to use for the result. |
- Returns
- The block's average duration per cycle.
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.
Computes the elapsed time since the profiler was initialized.
- Parameters
-
format | The 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
-
name | The name of the block. |
format | The 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
-
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. |
Accesses the singleton instance.
- Returns
- The Profiler instance.
The documentation for this class was generated from the following file: