Simple Profiler

A simple profiler for C++ on Win32

This page is now obsolete; I added a GUI to the profiler, and put the whole thing up at The profiler is now called 'Sleepy'.

version 0.2

Well I rewrote the profiler to use the Windows DbgHelp API. Now it's a bit more powerful. It uses debugging info symbol files to do the address -> procedure name resolution. If you have symbol files for other modules then addresses in them can be resolved as well. Also the ProcCounts.txt now gives you the module name the procedure is from.

version 0.2
6th March 2005

(Old version 0.1)

This profiler uses a really cool technique where the profiler runs in a different thread from the main program. Every 1ms or so, the profiler thread suspends the main thread, and pulls out the current instruction pointer value from the thread context. These mem addresses are resolved into procedure names by using .map files produced by the linker. This allows procedure-level resolution, without making any changes to the target program source apart from code to start the profiler.

The profiler only works on win32 code, and only with compilers that produce map files (.map), ie. the MS Visual C++ compiler.

The profiler is available as a full source code package. It has to be compiled into your program to be used. The source is free to do anything you want with it.

There are two pieces of output: IPCounts.txt, which gives a breakdown of values found in the instruction pointer register, and which looks like this:

0x401082 4
0x40139d 2
0x402b10 5
0x402b17 3
0x402b21 1
0x402b26 74
0x402b28 7
0x402b36 2
0x402b38 9
0x402b3b 193
0x402b45 369
0x402b47 198

The second piece of output is ProcCounts.txt, which looks like this:

testFunc2                                         1420  (28.40%)
_rand 1347 (26.94%)
testFunc 1164 (23.28%)
[Kernel] 373 (7.46%)
_main 347 (6.94%)
__getptd 343 (6.86%)
[Unknown] 6 (0.12%)

version 0.1
2nd March 2005

Written by Nik Chapman a.k.a. Ono-Sendai, 2005.
Based around some code from a forum (of all places):

: Main

: Projekts

: Code

: Articles

: Links