• 12
• 14
• 13
• 10
• 11

# My open source C++ performance profiler

This topic is 3378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites
It would be nice if you would reformat your code: tags. (C++ is default).

##### Share on other sites
Thank you. phresnel.

##### Share on other sites
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.

##### Share on other sites

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.

##### Share on other sites
Will it also work without inserting any of those macros into my code?

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.