Profile

From Nocturnal Initiative

Jump to: navigation, search

Profile is a simple instrumenting profiler library. It can report its data to standard out on program shutdown as well as trace profile output data to a log file.

Profile has two main modes of operation: Accumulation and Instrumentation. Either can be compiled into your code, but Instrumentation requires Accumulation be compiled in. We (Insomniac) typically compile in Accumulation, and only compile in Instrumentation for the modules we wish to scrutinize.

Accumulation

Accumulation is the addition of time taken for some operation added to a global Accumulator:

Profile::Accumulator g_DoWorkAccum ("Do Some Work");

To add increments of work to the accumulator, use a macro:

void DoWork()
{
  PROFILE_SCOPE_ACCUM( g_DoWorkAccum ); 
}

Any scope that has an instance of that macro will add the time taken in its scope to the Accumulator. The Accumulator will track the number of timers that added time to it and the total time taken. If you run your program with '-profile' it will reports the stats from all the Accumulators in the process that had time added to them.

Instrumentation

Instrumentation goes one step further and adds an Accumulator per instance macro. This means that each scope has its own time accumulation. As well as this, each instance logs its time taken to the trace output. This is for later scrutiny in a stand alone profile viewing tool (implementation to come). For now the trace file is a relatively human readable text file. In later implementations it will be a binary file with pages of instance information that will be loaded into a dedicated tool.

void DoWork()
{
  PROFILE_SCOPE_TIMER( ("DoWork") );
}

Note the extra pair of parenthesis. These inner parenthesis denote the parameter list of a sprintf()-style function call. You can sprintf any extra information that may be instance-specific in this macro like this:

void DoWork( const char* info )
{
  PROFILE_SCOPE_TIMER( ("DoWork '%s'", info) );
}
Personal tools
Navigation
projects