我想使用 systemtap 来提取我的 linux 生产服务器的详细信息。我的 systemtap 脚本是
global bt;
global quit = 0
probe begin {
printf("start profiling...\n")
}
probe timer.profile {
if (pid() == target()) {
if (!quit)
{
bt[backtrace(), ubacktrace()] <<< 1
}
else
{
foreach ([sys, usr] in bt- limit 1000)
{
print_stack(sys)
print_ustack(usr)
printf("\t%d\n", @count(bt[sys, usr]))
}
exit()
}
}
}
probe timer.s(20) {
quit = 1
}
当我开始使用命令运行这个脚本时
sudo stap --ldd -d $program_name --all-modules \
-D MAXMAPENTRIES=10240 -D MAXACTION=20000 -D MAXTRACE=40 \
-D MAXSTRINGLEN=4096 -D MAXBACKTRACE=40 -x $program_pid \
profile.stp --vp 00001 > profile.out
失败,并打印以下错误:
ERROR: error allocating hash
ERROR: global variable 'bt' allocation failed
WARNING: /usr/bin/staprun exited with status: 1
我的生产服务器内存信息是
total used free shared buffers cached
Mem: 16008 15639 368 0 80 3090
-/+ buffers/cache: 12468 3539
我觉得够用了,因为在我的测试服务器上,只有2G内存,systemtap脚本在另一台服务器上运行的很好
最佳答案
不幸的是,这是有意为之的行为,请在此处查看我的讨论:https://sourceware.org/ml/systemtap/2015-q1/msg00033.html
问题在于 SystemTap 一次分配关联数组(以防止将来分配失败)并在每个 CPU 的基础上分配(以防止锁定),这意味着 bt
将需要 ( 2 * MAXSTRINGLEN + sizeof(statistic)) * MAXMAPENTRIES * NR_CPU
=~ 2 Gb 如果 NR_CPU == 128
。
减少 MAXSTRINGLEN
(在您的情况下设置为 4k)或 bt
数组的大小:
global bt[128];
关于linux - systemtap 全局变量分配失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30367388/