有关VTune API的接口使用 – 由用户来控制性能数据的收集
Pause 和 Resume API 给了C/C++程序员机会去控制VTune Analyzer 样本的收集。例如,用户可以在程序中调用VTuneAPI以选择保存想要的数据(一个Benchmark程序不是所有部分都做测量)。这个功能支持IA32,Intel64,安腾,在
• VTune Performance Analyzer for Windows*
• VTune Performance Analyzer for Linux*
怎样让Pause, Resume API 工作?
VTune API 有二类”暂停/恢复”数据采集:VTPause() and VTResume(), 工作于 sampling, counter-monitor, 和 call-graph.而另一类,VTPauseSampling() and VTResumeSampling() 仅工作于sampling.
使用这些APIs,在你的C/C++源代码作以下修改
#include “vtuneapi.h”
Insert calls to VTResume() to resume
recording data:
VTResume();
Insert calls to VTPause() to pause recording data:
VTPause();
如:
void RecordData() { for (int i=0; i<10000000L; i++); }
void DontRecordData() { for (int i=0; i<10000000L; i++); }
int _tmain(int argc, _TCHAR* argv[])
{
// must start with vtune paused here!
VTResume();
RecordData();
VTPause();
DontRecordData();
VTResume();
Record();
VTPause();
return 0;
}
在 Visual Studio*, 用 /I 选项设定 <VTune installation directory>\Analyzer\Include 作为编译环境的”include directory”. 用 <VTune installation directory>\Analyzer\Lib作为编译环境的/libpath. 最后, 增加 VTuneAPI.lib 到<linker input modules> 列表.
VTune 项目创建的改变
避免在应用程序初始化时记录性能数据,设定暂停状态-检查Start with data collection paused 选项在Advanced Activity Configuration对话框, [img=http://photo12.hexun.com/p/2008/0410/187175/b_4C67DC32A2BD722E164E3B8D2FB42435.jpg]看下图[/img].