以前写过一篇, 关于使用Inspector XE 工具抓取某个时间段(或运行于某段代码)的内存上升(Memory Growth)的数据, 以了解此时间段(代码段)中系统的开销. 用户需要在Inspector对内存访问查错过程中, 按 “Set Transition Start” 按钮和 “Set Transition End”按钮, 详见此文
http://software.intel.com/zh-cn/blogs/2012/06/08/inspector-xe/
问题是用户较难判断运行到何时才是相应的起始(结束)代码,从而开始(结束)检测。Inspector XE 2013在ittnotify.h 定义了相应的接口,以代替按钮操作:
void ITTAPI __itt_heap_record_memory_growth_begin(void);
void ITTAPI __itt_heap_record_memory_growth_end(void);
以下示例中给出了一个简单的应用。
#include <stdio.h>
#include <memory.h>
#include <ittnotify.h>
#define MAX_NUM 60 /* total 60 times to allocate memory, elapsed time 120s */
int main()
{
char *str[MAX_NUM];
int i;
/* click "Set Transition Start" button */
__itt_heap_record_memory_growth_begin();
for (i=0; i<MAX_NUM; i++) {
str[i] = (char *) malloc (16*sizeof(char));
sleep (2); /* wait 2 seconds, each time */
}
/* click "Set Transition End" button */
__itt_heap_record_memory_growth_end();
return 1;
}
编译测试示例
# gcc -g mem_growth.c -I/opt/intel/inspector_xe_2013/include /opt/intel/inspector_xe_2013/lib64/libittnotify.a -lpthread -ldl -o mem_growth
运行内存检测
# inspxe-cl -collect mi3 -- ./mem_growth
Used suppression file(s): []
2 new problem(s) found
1 Memory growth problem(s) detected
1 Memory leak problem(s) detected
