Home > Linux, 工具介绍 > 再谈systemtap在ubuntu 10.10下的安装

再谈systemtap在ubuntu 10.10下的安装

March 11th, 2011

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: 再谈systemtap在ubuntu 10.10下的安装

NinGoo的这篇文章写的很明白了:http://www.ningoo.net/html/2010/use_systemtap_on_ubuntu.html
原始出处:http://sourceware.org/systemtap/wiki/SystemtapOnUbuntu

安装的时候有几个地方需要注意:

在做步骤2的时候:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"

$ uname -a
Linux yufeng-laptop 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:45:36 UTC 2010 x86_64 GNU/Linux

下载debug包的时候要注意核对好版本, 包括后面的小版本号,以及你的系统是amd64还是i386版本.

在做步骤4的时候:

rm -fr /usr/lib/debug/.build-id #最好添加这句
mkdir -p /usr/lib/debug/.build-id/$dir

模块符号信息安装成功的标志是:

$ stap -l 'module("*").function("*")'

不墨迹啥bad news.

但是我在ubuntu下安装还是有点麻烦,

$ sudo stap -e 'probe begin{printf("hello"); exit();}'
ERROR: module release mismatch (2.6.35.4 vs 2.6.35-22-generic)

通过分析stap -vvvv -k 告诉你的模块所在的目录, 生成的模块代码如stap_xxx.c:

...
static int systemtap_module_init (void) {
...
{
const char* release = UTS_RELEASE;
if (strcmp (release, "2.6.35-22-generic")) {
_stp_error ("module release mismatch (%s vs %s)", release, "2.6.35-22-generic");
rc = -EINVAL;
}
if (_stp_module_check()) rc = -EINVAL;
}
...

我们可以看到这个模块初始化要比对于 UTS_RELEASE 和 `uname -r` 是否相同.

明显在我的机器上这二个东西是不同的,原因是我的系统多次升级 UTS_RELEASE估计没升上去, 知道原因了,就很好办了, 不比对就好了.

下载源码:
$ apt-get source systemtap

修改 translate.cxx 中的代码:

o->newline() << "if ( 0 && strcmp (release, ”
<< lex_cast_qstring (session->kernel_release) << ")) {"; [shell] $ ./configure --prefix=/usr && make && sudo make install [/shell] 收获的时间: [shell] $ sudo stap -k -e 'probe begin{printf("hello"); exit();}' hello [/shell] 玩得开心!

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Linux, 工具介绍 Tags: , ,
  1. March 11th, 2011 at 20:48 | #1

    应该是“玩得开心”,嗯。

    Yu Feng Reply:

    谢谢纠正,已修改!

  2. xbz
    July 8th, 2011 at 10:08 | #2

    rm -f /usr/lib/debug/.build-id #最好添加这句

    应该是rm -rf吧,/usr/lib/debug/.build-id是个目录。

    Yu Feng Reply:

    多谢指正!

  3. fuyou001
    May 3rd, 2012 at 17:02 | #3

    hi yu feng
    我按NinGoo blog 在ubuntu12.04安装systemtap ,可以成功执行sudo stap -k -e ‘probe begin{printf(“hello”); exit();}’
    但我从SystemTap_Beginners_Guide.pdf 里copy 出这句执行,却报错(如下)

    yubaofu@tools$sudo stap -ve ‘probe begin { log(“hello world”) exit() }’
    [sudo] password for yubaofu:
    Pass 1: parsed user script and 76 library script(s) using 24468virt/13564res/2272shr kb, in 100usr/10sys/298real ms.
    Pass 2: analyzed script: 1 probe(s), 2 function(s), 0 embed(s), 0 global(s) using 24732virt/14300res/2552shr kb, in 0usr/0sys/33real ms.
    Pass 3: translated to C into “/tmp/stapnOxlIn/stap_e49f5800b047e9c20335ef5ad2f69701_767.c” using 24732virt/14392res/2640shr kb, in 0usr/0sys/0real ms.
    Pass 4: compiled C into “stap_e49f5800b047e9c20335ef5ad2f69701_767.ko” in 3100usr/520sys/9391real ms.
    Pass 5: starting run.
    hello world
    Pass 5: run completed in 10usr/20sys/613real ms.

    环境信息
    3.2.0-24-generic-pae #37-Ubuntu SMP Wed Apr 25 10:47:59 UTC 2012 i686 i686 i386 GNU/Linux
    ubuntu 12.04

    fuyou001 Reply:

    执行这个却是成功的
    yubaofu@~$cat test.stp
    probe timer.s(4)
    {
    printf(“hello world\n”)
    }

    yubaofu@~$sudo stap test.stp
    [sudo] password for yubaofu:
    hello world

    Yu Feng Reply:

    把-ve去掉你就会发现是可以运行的 Pass 5: starting run.
    hello world

Comments are closed.