Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Static Public Member Functions | Static Public Attributes | List of all members
drwnCodeProfiler Class Reference

Static class for providing profile information on functions. More...

Static Public Member Functions

static int getHandle (const char *name)
 return a handle for profiling a code block called name
static void clear (int handle)
 clear all profiling information for handle
static void tic (int handle)
 starting timing execution of handle
static void toc (int handle)
 stop timing execution of handle (and update number of calls)
static double walltime (int handle)
 return total real-world running time of handle (in seconds)
static double time (int handle)
 return total CPU running time of handle (in seconds)
static int calls (int handle)
 return number of times handle has been profiled
static void print ()
 display profile information for all handles (to message logger)

Static Public Attributes

static bool enabled = false
 set true to enable profiling

Detailed Description

Static class for providing profile information on functions.

drwnCodeProfiler is typically used to accumulate information on entire functions (or within subroutines). Wrap the function or code block in

drwnCodeProfiler::tic(handle = getHandle("functionName"));

to accumulate timing and number of calls for a given function. The timer accumulates the amount of processor and real (wall clock) time used between tic and toc calls (child processes, such as file I/O, are not counted in this time). Processor times may be inaccurate for functions that take longer than about 1 hour.

By default profiling is turned off and must be enabled in main() with

Most Darwin applications use the standard command line option -profile to enable profiling. Call the function drwnCodeProfiler::print() before exiting main() to log profiling information.

The code can also be used to setting time limits or recursive call limits within instrumented functions. Use time and calls to get the total running time or total number of calls for a given handle.

The macros DRWN_FCN_TIC and DRWN_FCN_TOC can be used at the entry and exit of your functions to instrument the entire function. Make sure you put DRWN_FCN_TOC before all return statements within the function.

Profiling provided by drwnCodeProfiler should be used as an estimate only. Specifically it is not accurate for small functions. In those cases you are better off using gprof and the "gcc -pg" option or Microsoft's Visual C++ profiling software. Note also that instrumenting code for profiling will unavoidably add a small overhead to a function's running time, so do not use tic and toc within tight loops. Unlike compiling with -pg for gprof, functions tic and toc are always compiled into the code.

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