- 论坛徽章:
- 0
|
简介
oprofile和Intel的VTune类似,都是利用CPU提供的性能计数功能对系统进行profiling. CPU提供一些性能计数器,经过配置可以对各种事件进行计数,当超过一定的threshold,会发出NMI中断,中断处理程序可以记录下当前的PC,current task等信息。用户可以对其dump进行分析。
oprofile主要用于系统调优,对于程序员和系统管理员都是一个找hotspot的很不错的工具。top只能采样到进程一级,你可以知道哪个进程占用CPU资源最多,但是top无法回答以下这些问题:
- bash的哪个函数占用资源最多?
- 内核中哪一部分最忙?
oprofile可以深入到指令一级,这是它最大的优势。
采样往往会对系统性能带来一些影响(想想测不准原理),oprofile带来的影响为1%-8%,还好。特别是考虑到它可能是唯一能提供你所需要的信息的工具。
oprofile包括核心模块和上层工具两部分,VTune的上层工具做得要比oprofile好得多,虽然功能基本差不多。和其他*nix工具一样,oprofile不提供一个集成的工具界面,而是把配置,管理,信息查看等功能分解为opcontrol, opreport, opannotate等几个小工具实现。说好听些,这是受了*nix的"Small Power Tools"哲学的影响,说难听些,就是对用户不负责任,认为只要提供足够的功能就可以了,对易用性和界面不予重视。
oprofile目前已经集成到2.6核心中,作为模块按需加载。
使用方法
- 加载 oprofile
- opcontrol --init
- 完成加载模块,mount /dev/oprofile文件系统,启动oprofiled等功能。
- 启动采样
- dump采样数据
- 停止采样
- 卸载 oprofile
- opcontrol --deinit
- opposite to '--init'
分析dump结果# opreport -fl
CPU: CPU with timer interrupt, speed 0 MHz (estimated)
Profiling through timer interrupt
samples % app name symbol name
1594269 86.5630 /processor (no symbols)
33485 1.8181 /home/root/kernel/linux-2.6.11.6-pczou/vmlinux kmem_cache_free
29735 1.6145 /home/root/kernel/linux-2.6.11.6-pczou/vmlinux kfree
5615 0.3049 /usr/lib/firefox/components/libgklayout.so (no symbols)
4687 0.2545 /lib/i686/libc-2.3.2.so memmove
4494 0.2440 /home/root/kernel/linux-2.6.11.6-pczou/vmlinux finish_task_switch
4140 0.2248 /usr/lib/libstdc++.so.5.0.3 (no symbols)
3395 0.1843 /usr/lib/libkdeinit_konsole.so TEScreen::addHistLine()
3306 0.1795 /usr/lib/libkdecore.so.4.2.0 malloc
3186 0.1730 /usr/lib/libkdecore.so.4.2.0 free
2842 0.1543 /usr/lib/firefox/libmozjs.so (no symbols)
......
# opannotate --source /home/pczou/learn/oprofile/ --output-dir=annotated /home/pczou/learn/oprofile/walk
# cat /home/pczou/learn/oprofile/annotated/walk.c
:#include
:
:int foo()
3 1.7964 :{ /* foo total: 86 51.4970 */
7 4.1916 : printf("i am foo\n");
76 45.5090 :}
:
:int bar()
8 4.7904 :{ /* bar total: 73 43.7126 */
: int i;
1 0.5988 : printf("i am bar\n");
60 35.9281 : for (i = 0; i # opstack /home/root/learn/oprofile/walk
self % child % symbol name
1 0.5988 0 0 anonymous symbol from section .plt
-------------------------------------------------------------------------------
86 51.4970 0 0 foo
-------------------------------------------------------------------------------
73 43.7126 0 0 bar
-------------------------------------------------------------------------------
7 4.1916 0 0 main
-------------------------------------------------------------------------------
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30686/showart_264903.html |
|