I need to performance analyse some real-time code on Windows.
I can't use any of the regular profilers (Vtune,Codeanalyst) because I can't slow the executable down. So I'm using my own timing class based on QueryPerformanceCounter().
Are then any existing (free) C++ libs to log the results - BUT I need them to be buffered to the end of a run, I can't afford the time to write to a file or event log while I'm collecting data.
Easy enough to roll my own, but if there is a way of making log4cplus / qDebug or similar log to a buffer and dump later it would save some effort.
I wrote a class that does this, too, because I couldn't find anything that did what I wanted but was still easy to incorporate in to existing code with copy-paste coding techniques.
(edit) Note that as mentioned in the comments, the act of timing itself changes the nature of what you're timing. But then I'm sure you understand this all too well. This class has still been very useful to me in finding hotspots & bottlenecks, in addition to giving me at least a rough high-side estimate of how long certain code takes to run. The code I present here was never intended to be production-worthy. Use it as such.
Here's a sample output of my class:
Each "Item" is one section of code I wanted to time. The
Timer
object uses RAII (viaauto_ptr
) to allow automatic start & stop. Here's some sample client-side code demonstrating how to use it:Sample Code:
The implementation of this class is in an include library. You don't need to compile anything. I use Boost.Format to do the string formatting, but this could be replaced simply enough.
Here is the implementation (my actual implementation splits this in to two files,
core.h
andcore_dbg.hpp
; the latter is#include
ed directly from the former).Implementation: