CPoorMansTimingAndProfiling  1.3.6
Instrument C apps simply to profile selected code paths.
 All Data Structures Functions Typedefs Pages
"C API"

Typedefs

typedef void stopWatch
 

Functions

void SWAddDelta (stopWatch *sw, double delta)
 
void SWClear (stopWatch *sw)
 
void SWClearAll ()
 
void SWConvertNanosToUIFriendly (double inputIntervalNanos, double *outputIntervalConverted, const char **outputIntervalUnits)
 
stopWatchSWCreate (const char *name)
 
stopWatchSWCreateStatistic (const char *name)
 
uint64_t SWCurrentTimeNanos ()
 
void SWDestroy (stopWatch *sw)
 
long SWDetermineNanosecondGranularity ()
 
void SWDisableAutoUnits (stopWatch *sw)
 
void SWDumpTimings (const char *msg)
 
long SWElapsedNanos (stopWatch *sw)
 
void SWEnableAutoUnits (stopWatch *sw)
 
void SWEnableMinMax (stopWatch *sw)
 
void SWEnableStdDev (stopWatch *sw)
 
double SWEstimateStartStopOverhead ()
 
double SWEstimateStartStopOverheadOfSW (stopWatch *sw)
 
void SWFDumpTimings (FILE *file, const char *msg)
 
void SWFPrintSummary (FILE *fout, stopWatch *sw)
 
double SWGetAvg (stopWatch *sw)
 
double SWGetCoefOfVariation (stopWatch *sw)
 
int SWGetCount (stopWatch *sw)
 
double SWGetCumulative (stopWatch *sw)
 
double SWGetMax (stopWatch *sw)
 
double SWGetMin (stopWatch *sw)
 
char * SWGetName (stopWatch *sw)
 
double SWGetStdDev (stopWatch *sw)
 
int SWIsStarted (stopWatch *sw)
 
void SWPrintSummary (stopWatch *sw)
 
void SWSetDefaultAutoUnits (int enableFlag)
 
void SWSetDumpNormalizationFactor (double factor)
 
void SWSetMaxNumThreadsToTrack (int n)
 
void SWSetNestedTiming (int enable)
 
void SWSleepMillis (unsigned long millis)
 
void SWStart (stopWatch *sw)
 
void SWStop (stopWatch *sw)
 
int SWStopIfStarted (stopWatch *sw)
 

Detailed Description

Typedef Documentation

typedef void stopWatch

An abstract stop watch structure used by the SW methods

Function Documentation

void SWAddDelta ( stopWatch sw,
double  delta 
)

Useful for testing or if you derive elapsed time some other way.

Parameters
swthe stop watch
deltatime 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.".

Parameters
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.

Parameters
nameof the stop watch - copied for internal use.
Returns
the newly instantiated stop watch
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.

Parameters
nameof the stop watch - copied for internal use.
Returns
the newly instantiated stop watch
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().

Parameters
swthe 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.

Returns
the resolution in nanoseconds.
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).

Parameters
msgis 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

Parameters
swthe 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

Parameters
swthe stop watch
void SWEnableStdDev ( stopWatch sw)

Enable computation of standard deviation on the specified stop watch

Parameters
swthe 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.

Returns
the estimated per-start-stop overhead in nanos.
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.

Parameters
swstop watch used
Returns
the estimated per-start-stop overhead in nanos.
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).

Parameters
fileto write to. Must already be open for write.
msgis 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.

Parameters
swthe stop watch
double SWGetCoefOfVariation ( stopWatch sw)

Get the coefficient of variation. See http://en.wikipedia.org/wiki/Coefficient_of_variation

Parameters
swthe stop watch
int SWGetCount ( stopWatch sw)

Get the total number of times the stopwatch has been started

Parameters
swthe stop watch
double SWGetCumulative ( stopWatch sw)

Get the total time,in ns., that the stopWatch was active.

Parameters
swthe stop watch
double SWGetMax ( stopWatch sw)

Get the maximum in ns.

Parameters
swthe stop watch
double SWGetMin ( stopWatch sw)

Get the minimum in ns.

Parameters
swthe stop watch
char* SWGetName ( stopWatch sw)

Get the name of the stop watch

Parameters
swthe stop watch
double SWGetStdDev ( stopWatch sw)

Get the standard deviation for the stop watch in ns.

Parameters
swthe stop watch
int SWIsStarted ( stopWatch sw)

Has the stop watch started?

Returns
non-zero if the stopwatch is 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.

Parameters
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.

Parameters
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.

Parameters
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.

Parameters
enableset 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

Parameters
swthe stop watch
void SWStop ( stopWatch sw)

Stop timing

Parameters
swthe 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().

Parameters
swthe stop watch
Returns
true if it was started and was stopped