Centos6下通过 oprofile分析CPU性能

2014-01-18 10:55:15 bobpen 阅读数 2218更多

分类专栏: linux
 
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

环境

Centos 6.4 x86_64

oprofile-0.9.9

oprofile安装

#wget http://ncu.dl.sourceforge.net/project/oprofile/oprofile/oprofile-0.9.9/oprofile-0.9.9.tar.gz
#tar -zxvf oprofile-0.9.9.tar.gz
#cd oprofile-0.9.9
#./configure
#make
#make install

oprofile使用

常用命令:

使用oprofile检测CPU,需要经过初始化、启动、导出数据、查看结果四个步骤。

初始化

opcontrol --no-vmlinux : oprofile启动后,不记录内核模块、内核代码相关统计数据

opcontrol --init : 加载oprofile模块、oprofile驱动程序

oprofile控制

opcontrol --start : 指示oprofile启动检测

opcontrol --dump : 指示将oprofile检测到的数据写入文件

opcontrol --reset : 清空之前检测的数据记录

opcontrol --h : 关闭oprofile进程

查看结果

opreport :默认查看oprofile检测结果

opreport -l : 以函数的角度显示检测结果

opreport -l oprofile_test : 以函数的角度,针对oprofile_test进程显示检测结果

opannotate -s oprofile_test : 以代码的角度,针对oprofile_test进程显示检测结果

opannotate -s /lib64/libc-2.12.so : 以代码的角度,针对libc-2.4.so库显示检测结果

在oprofile安装完成后,第一步初始化oprofile

[root@compute oprofile-0.9.9]# opcontrol --init

而后启动oprofile

[root@compute oprofile-0.9.9]# opcontrol --start --no-vmlinux
ATTENTION: Use of opcontrol is discouraged. Please see the man page for operf.
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.

通过默认的方式查看CPU检测报告

[root@compute oprofile-0.9.9]# opreport | less
Using /var/lib/oprofile/samples/ for samples directory.
CPU: Intel Westmere microarchitecture, speed 2393.96 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
CPU_CLK_UNHALT...|
samples| %|
------------------
361031 83.4576 vmlinux
32789 7.5797 ext4
14667 3.3905 jbd2
10162 2.3491 no-vmlinux
3178 0.7346 libc-2.12.so
1798 0.4156 mptbase
1386 0.3204 oprofiled
1380 0.3190 oprofile
1267 0.2929 opannotate
1242 0.2871 libpython2.6.so.1.0
1102 0.2547 mptscsih
924 0.2136 bash
290 0.0670 ld-2.12.so
201 0.0465 kvm
159 0.0368 bnx2
159 0.0368 libstdc++.so.6.0.13
120 0.0277 sd_mod

通过函数方式显示检测结果

[root@compute oprofile-0.9.9]# opreport -l | less
CPU: Intel Westmere microarchitecture, speed 2393.96 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
samples % image name app name symbol name
107138 20.1679 no-vmlinux no-vmlinux /no-vmlinux
51905 9.7707 vmlinux vmlinux intel_idle
32789 6.1723 ext4 ext4 /ext4
32755 6.1659 vmlinux vmlinux port_inb
21769 4.0978 vmlinux vmlinux copy_user_generic_string
16469 3.1002 vmlinux vmlinux __clear_user
14667 2.7609 jbd2 jbd2 /jbd2
13871 2.6111 vmlinux vmlinux native_sched_clock
8691 1.6360 vmlinux vmlinux get_page_from_freelist
5864 1.1039 vmlinux vmlinux find_busiest_group
5701 1.0732 vmlinux vmlinux mark_page_accessed
2894 0.5448 vmlinux vmlinux __schedule
2888 0.5436 vmlinux vmlinux __list_del_entry
2817 0.5303 vmlinux vmlinux menu_select
2772 0.5218 vmlinux vmlinux kmem_cache_alloc
2652 0.4992 vmlinux vmlinux __alloc_pages_slowpath
2478 0.4665 vmlinux vmlinux __wake_up_bit
2438 0.4589 vmlinux vmlinux __hrtimer_start_range_ns
2428 0.4571 vmlinux vmlinux kmem_cache_free
2262 0.4258 vmlinux vmlinux __list_add

下同编写简单代码消耗CPU,通过opannotate来了解CPU的占用情况,代码如下:

#vi test.c
int main()
{
int a = 0, b = 0;
for (; a < 1000000000; a++ )
{
b++;
}
}
#gcc -o oprofile_test test.c

执行该代码

#./oprofile_test &

将检测数据写入文件

#opcontrol --dump

查看该代码的CPU检测数据

[root@compute ~]# opreport -l oprofile_test
Using /var/lib/oprofile/samples/ for samples directory.
CPU: Intel Westmere microarchitecture, speed 2393.96 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
samples % symbol name
492407 100.000 main

通过opannotate查看代码层CPU的占用情况

[root@compute ~]# opannotate -s oprofile_test
Using /var/lib/oprofile/samples/ for session-dir
/*
* Command line: opannotate -s oprofile_test
*
* Interpretation of command line:
* Output annotated source file with samples
* Output all files
*
* CPU: Intel Westmere microarchitecture, speed 2393.96 MHz (estimated)
* Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
*/
/*
* Total samples for file : "/root/test.c"
*
* 492407 100.000
*/ :int main()
:{ /* main total: 492407 100.000 */
: int a = 0, b = 0;
343285 69.7157 : for (; a < 1000000000; a++ )
: {
149122 30.2843 : b++;
: }
:}

最新文章

  1. js中bind、call、apply函数的用法
  2. 【Beta】Daily Scrum Meeting第一次
  3. Apache不重新编译,利用apxs工具给Apache添加模块,如cgi模块
  4. vb小程序浅析
  5. kali linux 、 windows、ubuntu三系统的引导问题
  6. Chrome的ERR_UNSAFE_PORT解决办法
  7. Objective-C 快速入门--基础(一)
  8. iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 &quot;Invalid escape sequence around character 586.&quot;
  9. pg强制删库
  10. jdk线程的同步问题
  11. 博客系统-3.0CodeIgniter系统SAE版本的配置 application/config/
  12. div+css的叫法是不正确的
  13. Windows单击右键没有共享选项怎么办
  14. 用mui框架开发手机app项目实践中的那些事儿
  15. Docker Compose 原理
  16. .NET复习笔记-泛型
  17. 【English】20190306
  18. 创建ssh 服务的镜像
  19. [转]Oracle存储过程给变量赋值的方法
  20. Apache Kafka 1.0.0正式发布!

热门文章

  1. 快速排序(QuickSort)Java版
  2. 五、python学习-面向对象
  3. Flowable中的Service
  4. k8s ingress-nginx
  5. Python基础之容易忘记的地方
  6. 三维 WebGIS 新玩具:OpenGlobus
  7. UC-Android逆向工程师 面试题1的分析
  8. Windows核心编程 第27章 硬件输入模型和局部输入状态
  9. node-util
  10. MAC地址格式