rrerre的个人博客分享 http://blog.sciencenet.cn/u/rrerre

博文

cache hit/miss profiling

已有 5270 次阅读 2011-5-16 16:46 |个人分类:tools|系统分类:科研笔记

     关于cache hit/miss profiling, 最近尝试过3个工具:papi, oprofile 以及valgrind
1. papi 
       papi (Performance Application Programming Interface in Computer Science),顾名思义,为访问CPU上的硬件性能计数器提供一系列机器独立和操作系统独立的编程接口。可直接用于访问本机器的profiling信息:内容包括TLB,cache,branch,instruction counting等方面。既然是跨平台的,也就说明,根据硬件的不同,可以访问的性能计数器也不一样。
2. oprofile
      oprofile 是一个专用于linux操作系统的profiling工具,能够监测所有运行中的程序。
3. valgrind
      valgrind提供了一个用于编写动态分析工具的框架。该框架目前已经提供了一些标准的动态分析工具,包括:
  • MemCheck, 用于检测内存错误。
  • Cachegrind, 用于分析cahce和分支预测情况。
  • Callgrind, 可以用于交互式地分析函数的动态调用过程。
  • Helgrind和DRD, 用于检测线程错误。
  • Massif和DHAT, 用于分析堆的使用。
  • Ptrcheck,用于检测heap、stack和全局数组的overflow。
  • BBV,是一个类似SimPoint的分析工具,可以辅助系统体系结构的研究。
4. papi的例子
#include <string.h>
#include <papi.h>

#define SCALE 0x8000 
#define U_SCALE 2
#define EVENT PAPI_L1_ICM
void loop(int)
{
...
}
int main()
{
int retval;
unsigned long length;
PAPI_exe_info_t *prginfo;
long long *profbuf;
unsigned long start = 0, end = 0;
int EventSet = PAPI_NULL;
PAPI_event_info_t evinfo;
FILE *file = fopen("histogram.txt", "w");

// initilize the PAPI_library
retval = PAPI_library_init(PAPI_VER_CURRENT); 
// obtain info about progress
prginfo = PAPI_get_executable_info();
start = ( caddr_t ) loop;
end = (caddr_t) error;
length = (unsigned long) ( end - start ) *(SCALE)/65536/2;

// allocate buffer for histogram
profbuf = (unsigned long *)malloc(length*sizeof(long long));
memset(profbuf,0x00,length);

// create event
if ((retval = PAPI_create_eventset(&EventSet) ) != PAPI_OK)
error(3, retval);
// add event
if ((retval = PAPI_add_event(EventSet, EVENT) ) != PAPI_OK)
error(4, retval);
// profile event
if ((retval = PAPI_profil(profbuf, length, start, U_SCALE, EventSet, EVENT, 1000000, PAPI_PROFIL_BUCKET_64|PAPI_PROFIL_POSIX|PAPI_PROFIL_COMPRESS )) != PAPI_OK)
error(5,retval);
if ((retval = PAPI_start(EventSet) )!= PAPI_OK)
error(6, retval);
loop(SCALE);
if( (retval = PAPI_stop(EventSet, profbuf) ) )
error(7, retval);
return 0;
}


https://wap.sciencenet.cn/blog-385122-444758.html

上一篇:Paper writing notes
下一篇:Worst-Case Execution Time and Energy Analysis 1
收藏 IP: 144.214.120.*| 热度|

0

发表评论 评论 (1 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-19 23:08

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部