centos7上Systemtap的安装

6 篇文章 0 订阅
2 篇文章 0 订阅
  1. 查看环境:
  2. uname -r
  3. yum install kernel-devel
  4. yum install systemtap
  5. install kernel/glib debug:
    glibc-debuginfo-2.17-106.el7_2.8.x86_64.rpm
    glibc-debuginfo-common-2.17-106.el7_2.8.x86_64.rpm
    kernel-debuginfo-3.10.0-327.28.3.el7.x86_64.rpm
    kernel-debuginfo-common-x86_64-3.10.0-327.28.3.el7.x86_64.rpm
    ref: http://debuginfo.centos.org/7
  6. 测试是否安装ok:
    6.1 测试stap
    stap -V
    Systemtap translator/driver (version 3.0/0.163/0.166, rpm 3.0-7.el7)
    Copyright (C) 2005-2015 Red Hat, Inc. and others
    This is free software; see the source for copying conditions.
    enabled features: AVAHI BOOST_SHARED_PTR BOOST_STRING_REF DYNINST JAVA LIBRPM LIBSQLITE3 LIBVIRT LIBXML2 NLS NSS TR1_UNORDERED_MAP READLINE
    6.2 测试kernel-debuginfo
    stap -L ‘kernel.function(“printk”)’
    kernel.function(“printk@kernel/printk.c:1717”)
    fmt:charconst args:va_list
    6.3 测试glibc-debuginfo
    stap -L ‘process(“/lib64/libc.so.6”).function(“malloc”)’
    process(“/usr/lib64/libc2.17.so”).function(“__libc_malloc@/usr/src/debug/glibc-2.17-c758a686/malloc/malloc.c:2883”) $bytes:size_t
  7. 一个测试例子:查找内存泄露
# # C 源文件:
# cat t.c
#include <stdlib.h>

void fun() {
    malloc(1000);
}

int main(int argc, char *argv[]) {
    fun();
    return 0;
}
#
# # systemtap 脚本:
# cat m.stp 
probe process("/lib64/libc.so.6").function("malloc") {
    if (target()== pid()) {
        print_ubacktrace();
        exit();
    }
}
probe begin {
    println("~");
}
#
# # 编译t.cat:
# gcc -g t.c
#
# # 查看 a.out 的函数调用栈:
# stap -L 'process("./a.out").function("*")'
process("/root/systemtap/test/a.out").function("__do_global_dtors_aux")
process("/root/systemtap/test/a.out").function("__libc_csu_fini")
process("/root/systemtap/test/a.out").function("__libc_csu_init")
process("/root/systemtap/test/a.out").function("_fini")
process("/root/systemtap/test/a.out").function("_init")
process("/root/systemtap/test/a.out").function("_start")
process("/root/systemtap/test/a.out").function("deregister_tm_clones")
process("/root/systemtap/test/a.out").function("frame_dummy")
process("/root/systemtap/test/a.out").function("fun@/root/systemtap/test/t.c:3")
process("/root/systemtap/test/a.out").function("main@/root/systemtap/test/t.c:7") $argc:int $argv:char**
process("/root/systemtap/test/a.out").function("register_tm_clones")
#
# # 查看 malloc 调用情况:
# stap m.stp -c ./a.out 
~
 0x7fed3b435890 : __libc_malloc+0x0/0xe0 [/usr/lib64/libc-2.17.so]
 0x40053e [/root/systemtap/test/a.out+0x53e/0x1000]
WARNING: Missing unwind data for module, rerun with 'stap -d /root/systemtap/test/a.out'
#
# # 查看调用 malloc 的代码
# addr2line ./a.out 0x40053e
??:0
/root/systemtap/test/t.c:5
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值