liunx systemtap install 遇到一些问题

原文地址:

https://my.oschina.net/u/155323/blog/375448


--------------------------------------------------------------------------------------------------------------------------------

摘要: liunx systemtap install 遇到一些问题

http://hushi55.github.io/2015/01/27/linux-systemtap-install/

安装

我的安装是在 centos 上实验的,我们可以使用

yum install systemtap systemtap-runtime

验证

安装完后我们可以是会用下面的命令来验证是否安装成功:

stap -v -e 'probe vfs.read {printf("read performed"); exit()}'

若是一切顺利,我们看到下面的输出,这表明成功安装了:

[root@perf01 ~]# stap -v -e 'probe vfs.read {printf("read performed"); exit()}'
Pass 1: parsed user script and 103 library script(s) using 201324virt/29240res/3140shr/26600data kb, in 430usr/40sys/469real ms.
Pass 2: analyzed script: 1 probe(s), 1 function(s), 3 embed(s), 0 global(s) using 293676virt/122532res/4116shr/118952data kb, in 3070usr/390sys/3464real ms.
Pass 3: translated to C into "/tmp/stap424ZlL/stap_58ea609bf05d2a52a3426004df9f777f_1424_src.c" using 293676virt/122864res/4448shr/118952data kb, in 10usr/10sys/16real ms.
Pass 4: compiled C into "stap_58ea609bf05d2a52a3426004df9f777f_1424.ko" in 14360usr/2790sys/17154real ms.
Pass 5: starting run.
read performed
Pass 5: run completed in 20usr/60sys/403real ms.
[root@perf01 ~]#

遇到的问题

kernel-devel 版本问题

我在实验时遇到的问题是,验证时出现下面的输出:

[root@perf01 ~]# stap -v -e 'probe vfs.read {printf("read performed"); exit()}'
Checking "/lib/modules/2.6.32-358.el6.x86_64/build/.config" failed with error: No such file or directory
Incorrect version or missing kernel-devel package, use: yum install kernel-devel-2.6.32-358.el6.x86_64
[root@perf01 ~]#

我们列出提示的目录:

[root@perf01 ~]# ll /lib/modules/2.6.32-358.el6.x86_64/
total 3408
lrwxrwxrwx.  1 root root     46 Sep 25 17:55 build -> ../../../usr/src/kernels/2.6.32-358.el6.x86_64
drwxr-xr-x.  2 root root   4096 Feb 22  2013 extra
drwxr-xr-x. 11 root root   4096 Sep 25 17:55 kernel
-rw-r--r--.  1 root root 566961 Sep 25 17:59 modules.alias
-rw-r--r--.  1 root root 546171 Sep 25 17:59 modules.alias.bin
-rw-r--r--.  1 root root   1369 Feb 22  2013 modules.block
-rw-r--r--.  1 root root     69 Sep 25 17:59 modules.ccwmap
-rw-r--r--.  1 root root 196799 Sep 25 17:59 modules.dep
-rw-r--r--.  1 root root 287191 Sep 25 17:59 modules.dep.bin
-rw-r--r--.  1 root root     68 Feb 22  2013 modules.drm
-rw-r--r--.  1 root root    665 Sep 25 17:59 modules.ieee1394map
-rw-r--r--.  1 root root    141 Sep 25 17:59 modules.inputmap
-rw-r--r--.  1 root root   1236 Sep 25 17:59 modules.isapnpmap
-rw-r--r--.  1 root root     29 Feb 22  2013 modules.modesetting
-rw-r--r--.  1 root root   1905 Feb 22  2013 modules.networking
-rw-r--r--.  1 root root     74 Sep 25 17:59 modules.ofmap
-rw-r--r--.  1 root root  74887 Feb 22  2013 modules.order
-rw-r--r--.  1 root root 405140 Sep 25 17:59 modules.pcimap
-rw-r--r--.  1 root root   6259 Sep 25 17:59 modules.seriomap
-rw-r--r--.  1 root root 215776 Sep 25 17:59 modules.symbols
-rw-r--r--.  1 root root 274276 Sep 25 17:59 modules.symbols.bin
-rw-r--r--.  1 root root 837314 Sep 25 17:59 modules.usbmap
lrwxrwxrwx.  1 root root      5 Sep 25 17:55 source -> build
drwxr-xr-x.  2 root root   4096 Feb 22  2013 updates
drwxr-xr-x.  2 root root   4096 Sep 25 17:55 vdso
drwxr-xr-x.  2 root root   4096 Feb 22  2013 weak-updates
[root@perf01 ~]#

可以看到 build 是各一个软连接,我们再列出来提示的目录:

[root@perf01 ~]# ll /usr/src/kernels/
total 4
drwxr-xr-x. 22 root root 4096 Jan 10 03:00 2.6.32-504.3.3.el6.x86_64
[root@perf01 ~]#

我们看看我们 kernel 的版本:

[root@perf01 ~]# uname -r
2.6.32-358.el6.x86_64
[root@perf01 ~]#

显然是版本对不上,安装的 kernel 源码要新,我们可以卸载掉,使用 rpm 包重新安装

yum remove kernel-devel

卸载之后,我们可以上 google 查找我们内核版本的 kernel-devel-2.6.32-358.el6.x86_64 rpm 包。下载以后使用命令安装:

rpm -ivh kernel-devel-2.6.32-358.el6.x86_64.rpm

内核符号信息

上面的内核版本安装完成后使用上面的检查命令检查

[root@perf01 ~]# stap -v -e 'probe vfs.read {printf("read performed"); exit()}'
Pass 1: parsed user script and 103 library script(s) using 201324virt/29244res/3140shr/26600data kb, in 450usr/30sys/508real ms.
semantic error: while resolving probe point: identifier 'kernel' at /usr/share/systemtap/tapset/linux/vfs.stp:768:18
        source: probe vfs.read = kernel.function("vfs_read")
                                 ^

semantic error: missing x86_64 kernel/module debuginfo [man warning::debuginfo] under '/lib/modules/2.6.32-358.el6.x86_64/build'
semantic error: while resolving probe point: identifier 'vfs' at :1:7
        source: probe vfs.read {printf("read performed"); exit()}
                      ^

semantic error: no match
Pass 2: analyzed script: 0 probe(s), 0 function(s), 0 embed(s), 0 global(s) using 206720virt/34572res/5136shr/29892data kb, in 110usr/410sys/529real ms.
Pass 2: analysis failed.  [man error::pass2]
[root@perf01 ~]#

出现 semantic error 表明是系统没有符号信息,我们需要手动的安装符号 rpm,我们可以上 http://debuginfo.centos.org 查找

  • kernel-debuginfo-common-`uname -r`
  • kernel-debuginfo-`uname -r`

下载好,使用 rpm 命令安装即可:

rpm -ivh kernel-debuginfo-*.rpm

其他问题

安装完后可能还会有这样的错误:

	...
/usr/src/kernels/2.6.32-358.el6.x86_64/arch/x86/include/asm/atomic_64.h:21: note: expected ‘const struct atomic_t *’ but argument is of type ‘int/tmp/stapsc5jB6/stap_828df21dec234dbb5079577b35750b2c_1424_src.c:848: error: implicit declaration of function ‘skipped_count_reentrant’
/tmp/stapsc5jB6/stap_828df21dec234dbb5079577b35750b2c_1424_src.c:848: error: passing argument 1 of ‘atomic_read’ makes pointer from integer without a cast
/usr/src/kernels/2.6.32-358.el6.x86_64/arch/x86/include/asm/atomic_64.h:21: note: expected ‘const struct atomic_t *’ but argument is of type ‘int/tmp/stapsc5jB6/stap_828df21dec234dbb5079577b35750b2c_1424_src.c:849: error: passing argument 1 of ‘atomic_read’ makes pointer from integer without a cast
/usr/src/kernels/2.6.32-358.el6.x86_64/arch/x86/include/asm/atomic_64.h:21: note: expected ‘const struct atomic_t *’ but argument is of type ‘int’
	...

这是因为我们使用

yum remove kernel-devel

  • systemtap-2.5-5.el6.x86_64.rpm
  • systemtap-devel-2.5-5.el6.x86_64.rpm

这两个 rpm 包也给卸载了,我们只需要使用上面的命令重新安装 systemtap 即可。

参考

  • https://www.sourceware.org/systemtap/SystemTap_Beginners_Guide/using-systemtap.html


------------------------------------------------------------------------------------------------------------其他遇到的问题

原文:

https://7byte.github.io/2016/10/02/trytouse-FlameGraph/

遇到的问题:


1
2
3
4
5
6
7
8
9
10
11
12

$ sudo nginx-systemtap-toolkit/./ngx-sample-lua-bt -p 2039 --luajit20 -t 5 > svg/a.bt
WARNING: cannot find module /usr/local/openresty/luajit/lib/libluajit-5.1.so.2.1.0 debuginfo: No DWARF information found [man warning::debuginfo]
WARNING: Bad $context variable being substituted with literal 0: identifier '$L' at :17:30
source: lua_states[my_pid] = $L
^
semantic error: type definition 'TValue' not found in '/usr/local/openresty/luajit/lib/libluajit-5.1.so.2.1.0': operator '@cast' at :62:12
source: return @cast(tvalue, "TValue", "/usr/local/openresty/luajit/lib/libluajit-5.1.so.2.1.0")->fr->tp->ftsz
^
Pass 2: analysis failed. [man error::pass2]
Number of similar warning messages suppressed: 100.
Rerun with -v to see them.

在使用 ngx-sample-lua-bt 探测lua级别的火焰图时遇到了失败的情况,从错误信息来看是找不到 DWARF 调试信息。查找官网资料,貌似在很早以前 openresty 自带的 LuaJIT 2.0 默认就会启用 DWARF 调试信息,那我用的最新版怎么就是没有调试信息呢?折腾了好久,最后我到 luajit 官网下载了当前 openresty 版本对应的 luajit 源码,然后编译


1

$ make CCDEBUG=-g -B -j8

备份然后替换 /usr/local/openresty/luajit 目录下的两个文件,重启 openresty之后问题解决。


1
2
3
4
5
6
7

$ cd /usr/local/openresty/luajit/bin/
$ sudo cp luajit-2.1.0-beta2 luajit-2.1.0-beta2_20160829
$ sudo cp ~/LuaJIT-2.1.0-beta2/src/luajit/luajit luajit-2.1.0-beta2
$ cd /usr/local/openresty/luajit/lib/
$ sudo cp libluajit-5.1.so.2.1.0 libluajit-5.1.so.2.1.0_20160829
$ sudo cp ~/LuaJIT-2.1.0-beta2/src/libluajit.so libluajit-5.1.so.2.1.0

你可能感兴趣的:(linux)