Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2098324
  • 博文数量: 333
  • 博客积分: 10161
  • 博客等级: 上将
  • 技术积分: 5238
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-19 08:59
文章分类

全部博文(333)

文章存档

2017年(10)

2014年(2)

2013年(57)

2012年(64)

2011年(76)

2010年(84)

2009年(3)

2008年(37)

分类: LINUX

2012-12-10 13:00:40

oprofile起源于John Levon (Victoria U of Manchester)的一篇硕士论文,最初它以DCPI(DEC Continuous Profiling Infrastructure)为模型,并最先支持Intel Pentium Pro和AMD Athlon。oprofile主要是通过采样,利用CPU上的性能计数器(perfomance counter,在龙芯上分别为CP0的24和25号寄存器)统计某些事件的发生次数。它由内核模块和用户空间守护进程两部分组成,前者可以访问性能计数器,后者则负责从性能计数器收集数据。

    oprofile有两种采样方式:基于事件的采样(performance counter)和基于事件的采样(timer)。前者需要CPU上性能计数器的支持,可以人为选择要profiling的事件类型。后者适用于无性能计数器的CPU,记录每一个时钟周期。

oprofile使用(事件模式):
1、在2.6及其以后版本的Linux中都以模块方式集成了
oprofile,如要使用,首先加载。
   opcontrol --init
2、清除
oprofile中的历史数据。
   opcontrol --reset
3、配置
   opcontrol --setup --event=name:count:unitmask:kernal:user
   name:事件名
   count:计数器值,即事件发生多少次后,oprofile记录一次
   unitmask:硬件单元任务
   kernal:cpu在OS内核运行时是否统计(0或者1)
   user:cpu在OS用户级是否统计(0或者1)
   其中oprfile所支持的事件类型可以通过使用命令opcontrol -l获取。
例:opcontrol --setup --event=CYCLES:1000::0:1 --event=ITLB_MISSES:1000::0:1
    性能计数器0和1分别统计时钟和ITLB缺失事件,事件每发生1000次oprofile记录一次,硬件单元任务为0x0f,cpu处    于内核级不计数,处于用户级则计数。
4、启动
   opcontrol --start/-s
5、运行要检测的程序
   ./a.out
6、由用户级守护进程取出统计数据
   opcontrol --dump/-d
7、停止
   opcontrol --stop/-t      停止核心模块
   opcontrol --shutdown/-h  停止用户级守护进程
8、读取数据
   opreport -l -o data.txt   将整体统计数据存入data.txt
   opannotate -s --output-dir=an/    在源程序中添加注释,并按照源文件的目录结构生成目录an

系统级别的:
opreport --long-filenames

模块级别的:
opreport image:foo -l

源码级别的:
opannotate image:foo -s

oprofile使用手册:
阅读(2326) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~