FreeProfiler ---- 一个开源的C++性能测试工具

renqilin 2009-01-19 04:37:57
欢迎各位大侠提出您的宝贵意见。

下载地址: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!
...全文
896 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyang2009sheng 2011-09-07
  • 打赏
  • 举报
回复
太感谢了!

567

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧