大家好
看了Brendan D. Gregg CPU Flame Graphs 的文章。有一个问题是用systemtap 要产生怎么样格式的数据,才能用 https://github.com/brendangregg/FlameGraph 此工具生成Flame Graphs图?
参照agentzh sample-bt 代码写了一个简单例子
global bts;
global quit = 0;
probe timer.profile {
if (1) {
if (!quit) {
bts[ubacktrace()] <<< 1;
} else {
foreach (bt in bts- limit 10) {
print_ustack(bt);
printf("%d", @count(bts[bt]));
}
exit()
}
}
}
probe timer.s(10) {
nstacks = 0
foreach (bt in bts limit 1) {
nstacks++
}
if (nstacks == 0) {
warn("No backtraces found. Quitting now...\\n")
exit()
} else {
warn("Time's up. Quitting now...(it may take a while)\\n")
quit = 1
}
}
去掉警告信息
ARNING: Missing unwind data for module, rerun with 'stap -d /lib64/libc-2.5.so'
WARNING: Missing unwind data for module, rerun with 'stap -d /bin/dd'
WARNING: too many pending (warning) messages
WARNING: Missing unwind data for module, rerun with 'stap -d /bin/bash'
WARNING: Missing unwind data for module, rerun with 'stap -d /lib64/ld-2.5.so'
WARNING: Missing unwind data for module, rerun with 'stap -d /lib64/libpthread-2.5.so'
WARNING: Missing unwind data for module, rerun with 'stap -d /lib64/libcrypto.so.0.9.8e'
WARNING: Time's up. Quitting now...(it may take a while)\n
执行的结果如下保存到文件a.bt
4153 0x3c5eec6050
318 0x3c5eec67d0
211 0x3c5eec6750
48 0x3c5eecd722
6 0x3c60a044eb
3 0x3c5eed48ac
3 0x7fae009b67a9
3 0x3c5f60e38f
3 0x402722
生成图
[@FlameGraph]$ ./stackcollapse-stap.pl a.bt > a.cbt
[@FlameGraph]$ ./flamegraph.pl a.cbt > a.svg
ERROR: No stack counts found
要怎么样才生成Flame Graphs图?
sudo apt-get install linux-image-debug-generic
sudo ln -s /boot/vmlinux-debug-$(uname -r) /lib/modules/$(uname -r)/vmlinux