linux - systemtap 全局变量分配失败

标签 linux linux-kernel systemtap

我想使用 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/

相关文章:

regex - 基于空行的新文本文件

linux-kernel - Linux 设备驱动程序代码中是否需要自旋锁?

linux - 查找应用程序在什么状态或 OOM 分数值时被杀死

linux - 在哪里可以找到 ubuntu 12.04 的调试信息内核 rpm?

Linux:在 shell 脚本中导出环境变量,使其在任何服务器上都灵活

linux - qvfb 编译错误 - 对 `png_create_write_struct' 的 undefined reference

linux - 为什么Linux内核函数filp_close中posix线程id可以为NULL?

linux-kernel - 用于生产服务器的 Systemtap

linux - .function() 和 .function().call 在 systemtap 中的区别

linux - 如何根据第 6 个字段内容 grep 行