OPROFILE安装试用
OPROFILE是一个开源的profiling工具,类似于vtune和gprof。但不需要像gprof一样,必须优雅退出才可以剖分。今天在看HandlerSocket文章时,想重复一下作者的oprofile结果,因此,安装试用了一下,遇到一些问题,过程记录如下。
1. 连到服务器开发机上,发现已经安装了oprofile。尝试初始化: sudo opcontrol –init 出现错误:kernel doesn’t support oprofile. 看着很吓人,以为需要重新编译内核。但仔细看了看介绍,说2.6的内核已经以module的方式支持oprofile。因此,只需要sudo modprobe oprofile一下,如果正常就可以继续,否则就说明没有安装这个module,需要重编内核,在menuconfig时选择是否添加。。
如果modprobe正确,仍出现这个错误,那说明opcontrol没有对应的kernel driver. 解决方案是重新编译安装oprofile。
2. 安装
wget http://prdownloads.sourceforge.net/oprofile/oprofile-0.9.6.tar.gz
tar xvfz oprofile.*.gz ./configure --prefix=/home/work/software/output/ --with-kernel-support
出现
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../lib64/libbfd.a(archures.o): relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with –fPIC
./configure --prefix=/home/work/software/output/ --with-kernel-support --enable-shared=no
再make

服务器用的是64位的系统,而它默认依赖到32位的库.因此,导出LDFLAGS=-L/usr/lib64后,make clean后再make,就成功通过了.

最后还出个waring,提示要添加用户,如果不调试JIT,直接忽略,不用添加用户。
3. 这就可以开始使用oprofile了,不过需要注意的是,需要有root权限才可以运行,请向系统管理员索要sudo权限。
4. 对mysqld进行profile为例:
sudo opcontrol --reset sudo opcontrol --separate=lib --no-vmlinux --start --image=/home/software/output/libexec/mysqld 在其他机器起压力,压力停止后再进行后续操作 sudo opcontrol --dump sudo opcontrol --shutdown opreport -l /home/software/output/libexec/mysqld opannotate -s /home/software/output/libexec/mysqld