ptrace utility

Purpose

DMD's builtin profiler is a very useful tool to determine the performance of individual functions and their interactions (by means of a call graph). The output it generates however - in the form of a trace.log file - can be hard to read, mainly because it writes mangled symbols. ptrace can parse and demangle this output, and convert it to a friendlier html format. The conversion to html is done via the ddoc system.

Usage

ptrace can be used in two ways:

1. Generate html 'directly' from a trace.log file. The ddoc macro's are hardcoded in ptrace.

2. Generate a .d file, and then 'compile' this with the trace.ddoc macro definition file.

ad 1) Executing ptrace without arguments will result in ptrace looking for a trace.log file in the current directly to generate html from it. If you want to specify a different file as source, or a different filename as the target, use the '-x' option to let ptrace call dmd and skip the intermediate step of compiling a D file.

ad 2) The '-t=<file>' option can be used to name the target D file. trace.ddoc contains the macros definitions used for the ddoc system, via this route it's possible to customize the output a bit. The html generated currently doesn't look that pretty in some browsers.

Example

Some entries in a trace.log file:

    193       43885       32456         168     _D6ptrace5Words7opApplyMFDFKAaZiZi
   2536       11271        8590           3     _D5tango4text4Util11__T4trimTaZ4trimFAaZAa

Generated html:

Num calls Tree TimeFunc Time Per Call identifier type
193 43885 32456 168 ptrace.Words.opApply int function(int delegate(inout char[], void*), void*)
2536 11271 8590 3 tango.text.Util.trim!(char).trim char[] function(char[])

Call graph example. Here, lodepng.Encode._encode calls lodepng.Encode.writeChunk which calls lodepng.Encode.concatUint:

Functions that call measured function (fan in) Num calls
Measured function symbol Tree Time Func Time Num Calls
Functions called by measured function (fan out) Num calls
 
 
ubyte[] lodepng.Encode._encode(ubyte[], struct lodepng.Encode.Settings, inout ubyte[], inout struct lodepng.Common.Chunk[]) 4
void lodepng.Encode.writeChunk(inout ubyte[], inout struct lodepng.Common.Chunk) 3.47e+06 3.46e+06 4
void lodepng.Encode.concatUint(inout ubyte[], uint) 8
 

sourcefiles

ptrace needs tango