CPoorMansTimingAndProfiling
1.3.6
Instrument C apps simply to profile selected code paths.
|
Typedefs | |
typedef void | stopWatch |
typedef void stopWatch |
An abstract stop watch structure used by the SW methods
void SWAddDelta | ( | stopWatch * | sw, |
double | delta | ||
) |
Useful for testing or if you derive elapsed time some other way.
sw | the stop watch |
delta | time to add in nanoseconds |
void SWClear | ( | stopWatch * | sw | ) |
Resets the cumulative, count, avg, etc.
void SWClearAll | ( | ) |
Clear all stop watches
void SWConvertNanosToUIFriendly | ( | double | inputIntervalNanos, |
double * | outputIntervalConverted, | ||
const char ** | outputIntervalUnits | ||
) |
Provide ui/human friendly units for the specified interval in nanoseconds. Generally, speaking the units are "ns.", "ms.", "us." "sec.".
inputIntervalNanos | |
outputIntervalConverted | |
outputIntervalUnits |
stopWatch * SWCreate | ( | const char * | name | ) |
Create a simple stop watch .
A unique name should be used. If it is NULL or "" then a name is synthesized using the source file name and the line number where the macro is invoked.
Note that this "method" is a actually macro. It is documented as a function to document the argument and return type.
name | of the stop watch - copied for internal use. |
stopWatch * SWCreateStatistic | ( | const char * | name | ) |
Create a stop watch with standard deviation enabled. This is the same as calling SWCreate() followed by SWEnableStdDev().
A unique name should be used. If it is NULL or "" then a name is synthesized using the source file name and the line number where the macro is invoked.
Note that this "method" is a actually macro. It is documented as a function to document the argument and return type.
name | of the stop watch - copied for internal use. |
uint64_t SWCurrentTimeNanos | ( | ) |
Return the current time as a 64 bit int in nanoseconds.
void SWDestroy | ( | stopWatch * | sw | ) |
Destroy the stop watch.
Beware that if you have nested timing enabled then there may be references from the call graph to this stop watch – so it should not be destroyed.
Also note that if you plan to use SWDumpTimings() to print the summary of this stop watch then you cannot destroy the stop watch until after the call to SWDumpTimings().
sw | the stop watch |
long SWDetermineNanosecondGranularity | ( | ) |
Determines the granularity of your system's nanosecond clock by "spinning" in a loop looking for rollover in the time reported by the time methods.
void SWDisableAutoUnits | ( | stopWatch * | sw | ) |
Disable automatic selection of output units (such as "ns.", "ms.", etc.). By default automatic units are enabled.
void SWDumpTimings | ( | const char * | msg | ) |
Simple way to dump the statistics to the console for all stop watches that have been created (and not destroyed).
msg | is output as informative part of the "dump". It may be "" or NULL. |
long SWElapsedNanos | ( | stopWatch * | sw | ) |
The number of nanoseconds that have elapsed since the stopWatch was started
sw | the stop watch |
void SWEnableAutoUnits | ( | stopWatch * | sw | ) |
Enable automatic selection of output units (such as "ns.", "ms.", etc.). By default automatic units are enabled.
void SWEnableMinMax | ( | stopWatch * | sw | ) |
Enable min max tracking for the specified stop watch
sw | the stop watch |
void SWEnableStdDev | ( | stopWatch * | sw | ) |
Enable computation of standard deviation on the specified stop watch
sw | the stop watch |
double SWEstimateStartStopOverhead | ( | ) |
Iteratively (2,000,000 times) invokes SWStart() followed by SWStop() to determine the average overhead for these calls. An internal stop watch with no min-max tracking and no standard deviation computation is used.
If you enable nested timing that should be done before this method is invoked so that the effect of tracking nesting can be taken into account.
double SWEstimateStartStopOverheadOfSW | ( | stopWatch * | sw | ) |
Iteratively (2,000,000 times) invokes SWStart() followed by SWStop() to determine the average overhead for these calls. This method uses the stopWatch to accumulate statistics. The statistics are not cleared when done. Thus if standard deviation is enabled the stopwatch can be queried after the fact to estimate measurement jitter as well.
If you enable nested timing that should be done before this method is invoked so that the effect of tracking nesting can be taken into account.
sw | stop watch used |
void SWFDumpTimings | ( | FILE * | file, |
const char * | msg | ||
) |
Simple way to dump the statistics to a file for all stop watches that have been created (and not destroyed).
file | to write to. Must already be open for write. |
msg | is output as informative part of the "dump". It may be "" or NULL. |
void SWFPrintSummary | ( | FILE * | fout, |
stopWatch * | sw | ||
) |
Print a summary of the measured time (and statistics) to a file. If the file argument is null then this prints to the console.
double SWGetAvg | ( | stopWatch * | sw | ) |
Compute the average time in ns.
sw | the stop watch |
double SWGetCoefOfVariation | ( | stopWatch * | sw | ) |
Get the coefficient of variation. See http://en.wikipedia.org/wiki/Coefficient_of_variation
sw | the stop watch |
int SWGetCount | ( | stopWatch * | sw | ) |
Get the total number of times the stopwatch has been started
sw | the stop watch |
double SWGetCumulative | ( | stopWatch * | sw | ) |
Get the total time,in ns., that the stopWatch was active.
sw | the stop watch |
double SWGetMax | ( | stopWatch * | sw | ) |
Get the maximum in ns.
sw | the stop watch |
double SWGetMin | ( | stopWatch * | sw | ) |
Get the minimum in ns.
sw | the stop watch |
char* SWGetName | ( | stopWatch * | sw | ) |
Get the name of the stop watch
sw | the stop watch |
double SWGetStdDev | ( | stopWatch * | sw | ) |
Get the standard deviation for the stop watch in ns.
sw | the stop watch |
int SWIsStarted | ( | stopWatch * | sw | ) |
Has the stop watch started?
void SWPrintSummary | ( | stopWatch * | sw | ) |
Print a summary of the measured time (and statistics) to the console.
void SWSetDefaultAutoUnits | ( | int | enableFlag | ) |
Sets the global default for NEW stopwatches.
enableFlag | == 0 means disable; enableFlag != 0 means enable |
void SWSetDumpNormalizationFactor | ( | double | factor | ) |
Enable/disable dump statistic normalization. If factor == 0.0 then disable. Otherwise add an output clause to the summaries printed by SWDumpTimings() that lists the total time normalized by the factor. The default value is 0.0.
factor |
void SWSetMaxNumThreadsToTrack | ( | int | n | ) |
Set the max number of threads to track. Default is 32. This method is only supported if library is compiled with pthreads support. If there is no pthreads support this method is a NOP.
n |
void SWSetNestedTiming | ( | int | enable | ) |
Enable/disable nested timing. Nesting is disabled by default.
This is intended to be either enabled or disabled for the entire application session. If needed it should be enabled prior to starting any stop watches. The effect of turning this on and off during parts of a run have not been tested.
enable | set to 1 to enable or 0 to disable |
void SWSleepMillis | ( | unsigned long | millis | ) |
Sleep the specified number of milliseconds
void SWStart | ( | stopWatch * | sw | ) |
Start accumulating time on the specified stop watch
sw | the stop watch |
void SWStop | ( | stopWatch * | sw | ) |
Stop timing
sw | the stop watch |
int SWStopIfStarted | ( | stopWatch * | sw | ) |
Stops the stop watch if it has been started, advances the count by one, and adds to the accumulated time. This must be invoked in the same Thread that did the start().
sw | the stop watch |