1

我想使用 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脚本运行良好

4

1 回答 1

1

不幸的是,这是预期的行为,请参阅我的讨论:https ://sourceware.org/ml/systemtap/2015-q1/msg00033.html

bt问题是SystemTap一次分配关联数组(以防止将来分配失败)和基于每个 CPU(以防止锁定),这意味着(2 * MAXSTRINGLEN + sizeof(statistic)) * MAXMAPENTRIES * NR_CPU如果NR_CPU == 128.

减少MAXSTRINGLEN(在您的情况下设置为 4k)或bt数组大小:

global bt[128];
于 2015-05-21T07:55:25.783 回答