Visual C++ Profile的简单使用方法
上次说到C++函数计时,但是自从VC6以后,Profile功能便从Team Server Editions以外的版本中去掉了,如果没有此版本的VC,只能自己动手了。这是另一种使用Profile的方法,根据MSDN关于/callcap 的说明,编译WinCE应用程序时可以使用这个开关,试过后在Win32平台上也可以。这里需要注意的是在_CAP函数中,最好不修改寄存器,那样可能导致被调用的函数产生错误。参考:
http://www.google.com/codesearch?hl=zh-CN&q=/callcap+show:XEUTuTjJJm4:ODErFHofTDk:XEUTuTjJJm4&sa=N&cd=1&ct=rc&cs_p=http://google-gears.googlecode.com/svn&cs_f=gears/base/common/trace_buffers_win32/trace_buffers_win32.cc#l91
另外,如果直接把函数实现和调试的程序放在一个项目中编译,将会使CAP函数产生递归调用而导致堆栈溢出,处理方法是在一个静态库中不使用/callcap编译,然后再联接到调试的程序中。这种方式调试函数仍然不太方便,只能知道一个函数指针,无法知道函数名称。
extern "C" {
//void __stdcall _CAP_Profiling(void* func);
//void __stdcall _CAP_Start_Profiling(void* func, void* called);
//void __stdcall _CAP_End_Profiling(void* func);
void __stdcall _CAP_Enter_Function(void* func);
void __stdcall _CAP_Exit_Function(void* func);
}
![](/Images/OutliningIndicators/None.gif)
void __stdcall _CAP_Enter_Function(void* func)
{
![](/Images/OutliningIndicators/InBlock.gif)
__asm
{
pushad //堆栈中按顺序压入寄存器: EAX,ECX,EDX,EBX,ESP,EBP,ESI和EDI
pushfd
}
![](/Images/OutliningIndicators/InBlock.gif)
//这里添加代码
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
__asm
{
popfd
popad
}
![](/Images/OutliningIndicators/InBlock.gif)
}
void __stdcall _CAP_Exit_Function(void* func)
{
__asm
{
pushad
pushfd
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
__asm
{
popfd
popad
}
![](/Images/OutliningIndicators/InBlock.gif)
}
http://www.google.com/codesearch?hl=zh-CN&q=/callcap+show:XEUTuTjJJm4:ODErFHofTDk:XEUTuTjJJm4&sa=N&cd=1&ct=rc&cs_p=http://google-gears.googlecode.com/svn&cs_f=gears/base/common/trace_buffers_win32/trace_buffers_win32.cc#l91
另外,如果直接把函数实现和调试的程序放在一个项目中编译,将会使CAP函数产生递归调用而导致堆栈溢出,处理方法是在一个静态库中不使用/callcap编译,然后再联接到调试的程序中。这种方式调试函数仍然不太方便,只能知道一个函数指针,无法知道函数名称。
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)