性能调试工具——oprofile

oprofile利用cpu硬件层面提供的性能计数器(performance counter),通过计数采样,帮助我们从进程、函数、代码层面找出占用cpu的"罪魁祸首"。

常用命令

使用oprofile进行cpu使用情况检测,需要经过初始化、启动检测、导出检测数据、查看检测结果等步骤,以下为常用的oprofile命令。

初始化

  • opcontrol --no-vmlinux : 指示oprofile启动检测后,不记录内核模块、内核代码相关统计数据
  • opcontrol --init : 加载oprofile模块、oprofile驱动程序

检测控制

  • opcontrol --start : 指示oprofile启动检测
  • opcontrol --stop : 指示oprofile启动检测
  • opcontrol --dump : 指示将oprofile检测到的数据写入文件
  • opcontrol --reset : 清空之前检测的数据记录
  • opcontrol -h : 关闭oprofile进程

查看检测结果

  • opreport : 以镜像(image)的角度显示检测结果,进程、动态库、内核模块属于镜像范畴
  • opreport -l : 以函数的角度显示检测结果
  • opreport -l test : 以函数的角度,针对test进程显示检测结果
  • opannotate -s test : 以代码的角度,针对test进程显示检测结果
  • opannotate -s /lib64/libc-2.4.so : 以代码的角度,针对libc-2.4.so库显示检测结果
原文地址:https://www.cnblogs.com/westfly/p/4907748.html