oprofile抓不到采样数据问题和解决方法
在一些新机器上用 oprofile 做性能调优时经常抓不到采样数据:opcontrol 启动后一切正常,但 /var/lib/oprofile/samples/current/ 目录下 0 个文件,opreport 报 No sample file found。排查发现根源在于 oprofile 对这些 CPU 的识别有问题,会退化进 timer interrupt 模式——dmesg 中能看到 oprofile 相关的 timer 中断字样,ophelp 显示 Using timer interrupt,此时 opcontrol --setup -e 指定任何性能计数器事件都会被拒绝(You cannot specify any performance counter events because OProfile is in timer mode),这种状态自然采不到数据。
解决办法是 oprofile 模块加载时强制 timer=1:先 opcontrol --deinit 卸载模块,再 sudo modprobe oprofile timer=1,此时 dmesg 显示 "oprofile: using timer interrupt." 即表明生效。之后重新 opcontrol --init/--reset/--start,采样数据便能正常落地,opreport 可以看到 TIMER:0 下各模块(no-vmlinux、ha_innodb_plugin、libc、mysqld 等)的采样分布,samples 目录里也有对应的样本文件。