./samples/sample-bt-leaks.sxx 报错

100 views
Skip to first unread message

金海浪

unread,
Jul 5, 2018, 3:19:56 AM7/5/18
to openresty
你好,春哥!

我在尝试抓取内存泄露火焰图时,出出现以下错误:

root@debianvm:/home/jinhailang/stapxx# ./samples/sample-bt-leaks.sxx -x 30408 -v --arg time=5 > a.bt
Pass 1: parsed user script and 466 library scripts using 114076virt/46948res/6380shr/40724data kb, in 0usr/190sys/193real ms.
semantic error: while resolving probe point: identifier 'process' at <input>:17:7
        source: probe process("/usr/local/openresty/lualib/cjson.so").function("malloc").return,
                      ^

semantic error: no match (similar functions: die, _fini, _init, json_decode, json_encode)

semantic error: while resolving probe point: identifier 'process' at :18:7
        source:       process("/usr/local/openresty/lualib/cjson.so").function("calloc").return,
                      ^

semantic error: no match (similar functions: die, _fini, _init, json_decode, json_encode)

semantic error: while resolving probe point: identifier 'process' at :19:7
        source:       process("/usr/local/openresty/lualib/cjson.so").function("realloc").return
                      ^

semantic error: no match (similar functions: die, _fini, _init, decode_hex4, json_encode)

semantic error: while resolving probe point: identifier 'process' at :74:7
        source: probe process("/usr/local/openresty/lualib/cjson.so").function("free")
                      ^

semantic error: no match (similar functions: die, _fini, strbuf_free, _init, strbuf_new)

Pass 2: analyzed script: 2 probes, 186 functions, 3 embeds, 5 globals using 115792virt/49980res/7728shr/42440data kb, in 0usr/50sys/59real ms.
Pass 2: analysis failed.  [man error::pass2]
Tip: /usr/share/doc/systemtap/README.Debian should help you get started.



我找到类似的问题回复:https://groups.google.com/forum/#!msg/openresty/pVfoi5iV-2U/0DiD0GaQMfAJ

但是,我的 stapxx 是直接 git clone 下来的,是最新版的。

然后,我展开了脚本,看不太明白:

root@debianvm:/home/jinhailang/stapxx# ./samples/sample-bt-leaks.sxx -x 30408 -v --arg time=5  --dump-src
#!/usr/bin/env stap

# Copyright (C) Yichun Zhang (agentzh)

global ptr2bt
global ptr2size
global bt_stats
global quit
global free_misses

probe begin
{
    warn(sprintf("Start tracing %d (/usr/local/openresty/nginx/sbin/nginx)...", target()))
    warn("Wait for 5 sec to complete.\n")
}

probe process("/usr/local/openresty/lualib/cjson.so").function("malloc").return,
      process("/usr/local/openresty/lualib/cjson.so").function("calloc").return,
      process("/usr/local/openresty/lualib/cjson.so").function("realloc").return
{
    if (pid() == target()) {
        //printf("Hit %s\n", probefunc())
        if (quit) {
            if (free_misses) {
                warn(sprintf("free misses: %d", free_misses))
            }

            foreach (bt in bt_stats) {
                print_ustack(bt)
                printf("\t%d\n", @sum(bt_stats[bt]))
            }

            exit()

        } else {
            if (@defined($oldmem)) {
                //printf("free %p in realloc\n", $oldmem)
                ptr = $oldmem

                bt = ptr2bt[ptr]
                delete ptr2bt[ptr]

                bytes = ptr2size[ptr]
                delete ptr2size[ptr]

                bt_stats[bt] <<< -bytes
                if (@sum(bt_stats[bt]) == 0) {
                    delete bt_stats[bt]
                }
            }

            ptr = returnval()
            if (ptr) {
                // here we use a hack specific to glibc's implementation
                // to get the size of the memory block because we
                // may not get the value of the $bytes parameter reliably.

                p = ptr - &@cast(0, "size_t")[1]
                size = @cast(p, "size_t")[0] & ~(&@cast(0, "size_t")[1] - 1)

                //printf("alloc: %p (bytes %d)\n", ptr, size)
                bt = ubacktrace()
                ptr2bt[ptr] = bt
                ptr2size[ptr] = size
                bt_stats[bt] <<< size

            } else {
                warn("NULL returned")
            }
        }
    }
}


使用 /samples/lj-lua-bt.sxx --skip-badvars -x 30408 > tmp.bt 抓取 CPU 火焰图都是正常的,这个问题挺困扰我的,麻烦有空指点一下吧,感谢!


tokers

unread,
Jul 5, 2018, 3:23:06 AM7/5/18
to openresty
Hello!

从上面你贴出来的报错信息来看,应该是你的 cjson.so 编译的时候没有带上调试参数,可以尝试重新编译下 cjson.so。

金海浪

unread,
Jul 10, 2018, 2:41:46 AM7/10/18
to openresty
带上调试参数,重新编译后,问题解决。
Makefile 已经提供了调试选项,去掉注释就行:

```
 CFLAGS =            -g -Wall -pedantic -fno-inline
 #CFLAGS =            -O3 -Wall -pedantic -DNDEBUG
```

多谢 @tokers

在 2018年7月5日星期四 UTC+8下午3:23:06,tokers写道:
Reply all
Reply to author
Forward
0 new messages