Fork me on GitHub

Search archive

Date:

Keyword:


Simple profiling

10/02/2014

So I've been doing some simple profiling of Chaotic Rage recently. I've previously done full profiling using tools like valgrind, but it's often too much data and slows down the game too much. So I built a simple profiler tool and added that to the game engine.

The code looks something like this:

#define PROFILE_START(sect) int _p_##sect = SDL_GetTicks();
#define PROFILE_END(sect) profile_write(#sect, _p_##sect, SDL_GetTicks());

Those defines are only compiled-in for debug builds - release builds don't have this feature.

The macros are called something like this:

PROFILE_START(render);
st->render->render();
PROFILE_END(render);

And when profiling is enabled, you end up with a tsv file something like this:

Event      StartTime   EndTime   Elapsed
entities   12097       12097     0
physics    12097       12135     38
render     12135       12142     7
entities   12144       12144     0
physics    12144       12146     2
render     12146       12148     2

Which can then be run through a processing tool I wrote which calculates totals and averages, and you get something like this:

 === test.tsv === 
Event          Total     Min       Max       Count     Mean      
entities       44ms      0ms       1ms       1432      0.0307ms  
physics        167ms     0ms       38ms      1432      0.1166ms  
render         2152ms    1ms       8ms       1432      1.5028ms

I think it's pretty cool. You can find the code in commit aaaca0c of the GitHub repo.

Article comments (0)