技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> Linux --> systemtap函数调用栈信息不齐的原因和解决方法

systemtap函数调用栈信息不齐的原因和解决方法

浏览:2122次  出处信息
    有时候在看系统代码的时候,我们很难从源码中看出我们感兴趣的函数是如何被调用的,因为调用路径有可能太多。用户空间的程序gdb设断点是个好的方法,内核的就麻烦了。这时候systemtap可以帮忙, 比如:
$uname -r
2.6.18-164.el5

$stap -V
SystemTap translator/driver (version 1.5/0.137 non-git sources)
Copyright (C) 2005-2011 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
enabled features: LIBRPM LIBSQLITE3 NSS BOOST_SHARED_PTR TR1_UNORDERED_MAP NLS

$sudo stap -e \'probe vfs.add_to_page_cache {print_backtrace();println("")}\'
 0xffffffff8000c633 : add_to_page_cache+0x0/0xc1 [kernel]
 0xffffffff800c4565 : add_to_page_cache_lru+0xe/0x22 [kernel]
 0xffffffff80025a10 : find_or_create_page+0x4b/0x72 [kernel]
 0xffffffff80019b72 : __getblk+0x105/0x236 [kernel]
 0xffffffff8803826a
 0xffff811838293600 (inexact)
...

    但是有时候我们并没能得到全部的符号信息, 比如# 0xffffffff8803826a 这行是谁没打印出来吧。 原因是我们的模块可能被未知的模块所调用,这些模块的符号信息没有自动加载,所以systemtap当然就不知道谁是谁了!

    解决方法 man stap 文档写的很清楚:

     -d MODULE

     Add symbol/unwind information for the given module into the kernel object module. This may enable symbolic tracebacks from those mod-

     ules/programs, even if they do not have an explicit probe placed into them.

     -ldd Add symbol/unwind information for all shared libraries suspected by ldd to be necessary for user-space binaries being probe or listed

     with the -d option. Caution: this can make the probe modules considerably larger.

     -all-modules

     Equivalent to specifying “-dkernel” and a “-d” for each kernel module that is currently loaded. Caution: this can make the probe modules

     considerably larger.

$sudo stap --all-modules -e \'probe vfs.add_to_page_cache {print_backtrace();println("")}\'
 0xffffffff8000c633 : add_to_page_cache+0x0/0xc1 [kernel]
 0xffffffff800c4565 : add_to_page_cache_lru+0xe/0x22 [kernel]
 0xffffffff80025a10 : find_or_create_page+0x4b/0x72 [kernel]
 0xffffffff80019b72 : __getblk+0x105/0x236 [kernel]
 0xffffffff8803826a : journal_get_descriptor_buffer+0x30/0x0 [jbd]
 0xffff81183f50c000 (inexact)

    0xffffffff8803826a 这行我们知道是谁了把, jbd. 知道了这个模块我们就可以这样:

$sudo stap -d jbd -e \'probe vfs.add_to_page_cache {print_backtrace();println("")}\'
 0xffffffff8000c633 : add_to_page_cache+0x0/0xc1 [kernel]
 0xffffffff800c4565 : add_to_page_cache_lru+0xe/0x22 [kernel]
 0xffffffff80025a10 : find_or_create_page+0x4b/0x72 [kernel]
 0xffffffff80019b72 : __getblk+0x105/0x236 [kernel]
 0xffffffff8803826a : journal_get_descriptor_buffer+0x30/0x0 [jbd]
 0xffff81183f50c000 (inexact)
...

    二个一样的的运行效果,只是生成的模块大小不一样,我们来看下:

$sudo stap -d jbd -m demo -p4 -e \'probe vfs.add_to_page_cache {print_backtrace();println("")}\'
demo.ko
$ll demo.ko
-rw-r--r-- 1 root root 2943293 Mar 26 22:14 demo.ko

$sudo stap --all-modules -m demo -p4 -e \'probe vfs.add_to_page_cache {print_backtrace();println("")}\'
demo.ko
$ll demo.ko
-rw-r--r-- 1 root root 3890409 Mar 26 22:15 demo.ko

     -all-modules的生成要大不少,不过很适合我们这样的懒人!

    用户空间的程序用-ldd来搞定!

建议继续学习:

  1. Linux下如何知道文件被那个进程写    (阅读:4700)
  2. 在Ubuntu上使用SystemTap    (阅读:2882)
  3. 突破systemtap脚本对资源使用的限制    (阅读:2316)
  4. systemtap全局变量自动打印的原因和解决方法    (阅读:1708)
  5. systemtap观察page_cache的使用情况    (阅读:1659)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1