欢迎各位大侠提出您的宝贵意见。
下载地址:https://sourceforge.net/project/showfiles.php?group_id=249996
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 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.
3. How to use FreeProfiler?
To use FreeProfiler, you have three steps:
3.1 Copy the folder “Application” to your program working directory, and rename it to "FreeProfiler".
3.2 In one cpp file of the module that you want to test its performance, add: FreeProfilerImport("your_module_name", "FreeProfiler\\");
Then, you can add time record macros in your functions. FreeProfilerRecordMessageBlock(messagevalue) is used for windows message procedure. FreeProfilerRecordCodeBlock(blockId, blockName) is used for C++ code blocks.
Example:
FreeProfilerImport("testFreeProfiler.exe -- some comments could also be added here.", "FreeProfiler\\");
LRESULT CALLBACK WndProc(HWND hwnd, int message, ......)
{
FreeProfilerRecordCodeBlock(0, "main.cpp WndProc()");
FreeProfilerRecordMessageBlock(message);
switch (message)
{
......
}
{
FreeProfilerRecordCodeBlock(0, "main.cpp WndProc() time cost in default windows procedure");
return DefWindowsProc(hwnd, message, wParam, lParam);
}
}
3.3 Run FreeProfiler\Binary\CodeBlockCollector.bat. Notice you should modify the bat file according to your source code path.
This tool will assign an unique Id for each FreeProfilerRecordCodeBlock. So your code will be changed to:
FreeProfilerRecordCodeBlock(1, "main.cpp WndProc()");
This tool will also generate a file named "FreeProfilerBlocks.txt".
If you have specific message definitions, run FreeProfiler\Binary\WinMsgCollector.bat. You should also notice the source code path in the bat file.
3.4 Recompile your application, run your application, and exit your application. You will find a file named “FreeProfilerResult.xml” in FreeProfiler\Configuration\.

Enjoy!