My open source C++ performance profiler

Started by
26 comments, last by renqilin 15 years, 2 months ago
Hi everyone, I wrote a simple C++ performance profiler these days. Any suggestion is welcome. You can download it at: https://sourceforge.net/project/showfiles.php?group_id=249996 Homepage: http://freeprofiler.sourceforge.net/ ==============================================================================

Introduction

1. Basic Information

FreeProfiler is a light weighted C++ code performance profiler. It provides utility macros for users to insert into their code. After recompiling and running their application, user can watch the performance result. Unix name: freeprofiler CVS anonymous access: :pserver:anonymous@freeprofiler.cvs.sourceforge.net:/cvsroot/freeprofiler

2. Why Use FreeProfiler?

2.1 Compared to other performance profilers, FreeProfiler has smaller granularity. It focuses on code block times and message processing times, not functions. So user can know exactly how much time is consumed by a specific part of a function, or how much time is consumed by a specific windows message. Here is a typical case where FreeProfiler is useful: You have a window callback procedure function, and you want to know which message consumes much time. So you simply add FreeProfiler macros at the beginning of your windows callback procedure, like this:

LRESULT CALLBACK AppWndProc(HWND hwnd, int message, WPARAM wParam, LPARAM lParam) 
{ 
        FreeProfilerRecordMessageBlock(message); 
        switch (message) 
        { 
        case WM_CREATE: 
                ...... 
        ...... 
        } 
        ...... 
}

And you can view the xml-format result after you exit your application. 2.2 It is light-weighted. FreeProfiler has minimal impact on the performance of the application. 2.3 It is thread-safe. So you don’t need to worry if your function will be called by multiple-threads simultaneously. 2.4 It is open source and free. You can use it for any purposes. [Edited by - renqilin on January 19, 2009 4:15:53 AM]
Advertisement
It would be nice if you would reformat your code: tags. (C++ is default).
Thank you. phresnel.
I made some modifications to the package. Now there are two zip files: One is binary zip, the other is source zip.

If you don't want to compile FreeProfiler by yourself, you can just download binary zip.

I just realized that there are the following bugs in my package:

1. __declspec(thread) does not work well with LoadLibrary. (This is fixed now).
2. rdtsc does not work well on a multi-core CPU.




Will it also work without inserting any of those macros into my code?
Hi Rattenhirn, Thanks for your comment. I'm sorry that FreeProfiler won't work if you don't insert the macros into your code. I have logged this as a future feature. Ideally FreeProfiler should analyze your source code and insert those detecting macros into your code automatically.

For now, you need to insert macros by yourself. However, one benefit of this is that you can detecting the performance of a small part of an algorithm.
Nice tool. Thanks for making this open source.

I browsed the source and noticed that you use construction and destruction to start and stop the high performance timer. I've been using this technique at work to do ad-hoc profiling and found it extremely useful in hunting down bottlenecks without pulling out the the big guns (like BoundsChecker). This is much more mature, cheers for putting it together. It may find it's way into my hobby projects.
To Valere:
Thanks, and yes, high resolution timer is fast. However it does not work well on a multi-core CPU. This is something I need to improve.
You should add the ability to output to a real time debug render, like iprof. Writing to a text file(xml or otherwise) is pretty useless imo. It's hugely more useful to see real time timer stats on screen so performance issues can be examined in real time. I don't mean add rendering code, something much simpler, like a lightweight render interface the application user can implement that will let the profiler optionally draw to the screen.

This topic is closed to new replies.

Advertisement