Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15314826
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2009-09-29 10:23:27

使用oprofile分析性能瓶颈
用OProfile彻底了解性能
luther@gliethttp:~$ sudo apt-get install oprofile

oprofile对应的内核驱动位于drivers/oprofile/目录
luther@gliethttp:/vobs/works/linux-2.6.31.1/drivers/oprofile$ ll
total 80K
-rw-r--r-- 1 luther luther  822 2009-09-24 23:45 timer_int.c
-rw-r--r-- 1 luther luther  663 2009-09-24 23:45 oprofile_stats.h
-rw-r--r-- 1 luther luther 2.2K 2009-09-24 23:45 oprofile_stats.c
-rw-r--r-- 1 luther luther 6.4K 2009-09-24 23:45 oprofilefs.c
-rw-r--r-- 1 luther luther 3.5K 2009-09-24 23:45 oprofile_files.c
-rw-r--r-- 1 luther luther  907 2009-09-24 23:45 oprof.h
-rw-r--r-- 1 luther luther 3.7K 2009-09-24 23:45 oprof.c
-rw-r--r-- 1 luther luther  858 2009-09-24 23:45 event_buffer.h
-rw-r--r-- 1 luther luther 4.1K 2009-09-24 23:45 event_buffer.c
-rw-r--r-- 1 luther luther 2.9K 2009-09-24 23:45 cpu_buffer.h
-rw-r--r-- 1 luther luther  12K 2009-09-24 23:45 cpu_buffer.c
-rw-r--r-- 1 luther luther  432 2009-09-24 23:45 buffer_sync.h
-rw-r--r-- 1 luther luther  14K 2009-09-24 23:45 buffer_sync.c

luther@gliethttp:~$ sudo opcontrol --no-vmlinux //表示不检测内核
luther@gliethttp:~$ sudo opcontrol --start
Using default event: CPU_CLK_UNHALTED:100000:0:1:1
Using 2.6+ OProfile kernel interface.
Using log file /var/lib/oprofile/samples/oprofiled.log
Daemon started.
Profiler running.

luther@gliethttp:~$ opcontrol --list-events 列出支持的所有event

luther@gliethttp:~$ sudo opcontrol -h // shutdown关闭
luther@gliethttp:~$ sudo opcontrol --init
luther@gliethttp:~$ sudo opcontrol --no-vmlinux
luther@gliethttp:~$ sudo opcontrol --event= CPU_CLK_UNHALTED:5000 --event=DATA_CACHE_MISSES:1000 --event=INSTRUCTION_CACHE_MISSES:1000 --event=MEMORY_REQUESTS:1000
luther@gliethttp:~$ sudo opcontrol --start
luther@gliethttp:~$ sudo opcontrol --dump
luther@gliethttp:~$ opreport
luther@gliethttp:~$ opcontrol --deinit // 卸载模块

或者直接
luther@gliethttp:~$ sudo opcontrol -h // shutdown关闭
luther@gliethttp:~$ sudo opcontrol --init
luther@gliethttp:~$ sudo opcontrol --start
luther@gliethttp:~$ gcc -o gliethttp_test main.c // 生成测试程序gliethttp_test
luther@gliethttp:~$ ./gliethttp_test // 运行被测试程序
luther@gliethttp:~$ sudo opcontrol --dump // 取出监控数据
luther@gliethttp:~$ sudo opcontrol --stop // 停止监控
luther@gliethttp:~$ opreport -l ./gliethttp_test // 取出和测试程序gliethttp_test相关的监控报告
luther@gliethttp:~$ opreport // 取出全部监控报告
如果加入-g编译,即gcc -g -o gliethttp_test main.c 那么我们可以使用opannotate --source分析源码
luther@gliethttp:~$ opannotate --source ./gliethttp_test

luther@gliethttp:~$ sudo opcontrol --stop // 停止数据收集
luther@gliethttp:~$ sudo opcontrol -h // 停止数据收集,同时退出daemon程序

luther@gliethttp:~$ sudo opcontrol --reset // 清空当前会话数据
luther@gliethttp:~$ sudo opcontrol --status // 查看你自己配置了的事件

《source性能分析工具Oprofile详细解析》



阅读(3790) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

2011-05-22 15:37:01

学习了,多谢楼主分享哦!也欢迎广大linux爱好者来我的论坛一起讨论arm哦!www.lt-net.cn