• SystemTap 使用以及安装


    关于SystemTap的作用请参考这里:http://blog.yufeng.info/archives/855,网上还有很多很多类似的文章,大同小异,只要基本用法了解之后,剩下的就是多了解内核以及靠时间积累的各种灵感突发的用法。

    安装会把很多人吓住,因为似乎不是那么方便,以systemtap 1.8为例:

    1. 需要elfutil 151以上版本,这个可以在ChinaUnix找到,以153为例,下载后./configurate; make; make install 会发现如下问题:

        a. dwarf_begin_elf.c:175: warning: implicit declaration of function ‘be64toh’

            这个方法可以到MIT的一个站点下载,然后放入elfutils-0.153/libdw/mit_endian.h,然后修改libdw/dwarf_begin_elf.c包含该文件

        b. readelf.c:4521: warning: implicit declaration of function ‘qsort_r’

            这个方法是gnu的一个扩展,但是可以再google code上找到代码,然后保存为qsort_r.h,放到readelf.c中;

        c. readelf.c:4729: warning: comparison between signed and unsigned 自行转成int

        这样,elfutils应该没问题了。然后make distclean 一下,因为接下来systemtap可以指定elfutils目录。

    2. 到SystemTap官网下载1.8版本,https://sourceware.org/systemtap/ftp/releases/

        解压,./configrue --with-elfutils=$dir(刚刚解压的elf目录) --prefix=/usr/local/stap.1.8

        make -j10 && sudo make install

    3. 如果一切正常,那么

       

    #/usr/local/stap.1.8/bin/stap --vp 1111 -e 'probe vfs.read {printf("ok"); exit()}'
    Pass 1: parsed user script and 85 library script(s) using 138520virt/23616res/2768shr/21660data kb, in 210usr/0sys/215real ms.
    Pass 2: analyzed script: 1 probe(s), 1 function(s), 3 embed(s), 0 global(s) using 347096virt/118196res/7444shr/109456data kb, in 1540usr/70sys/1612real ms.
    Pass 3: translated to C into "/tmp/stapb0HGuZ/stap_d8b5d7f443363e7e8a74dc048d53345c_1162_src.c" using 338308virt/114748res/6208shr/109456data kb, in 0usr/10sys/5real ms.
    Pass 4: compiled C into "stap_d8b5d7f443363e7e8a74dc048d53345c_1162.ko" in 1280usr/280sys/1532real ms.
    ok
    

      但是也许你还会碰到各种问题,比如 Build-id mismatch: "kernel" vs. "vmlinux" byte 0 ,

       这是因为当前运行的内核build时间和debug info中时间不同导致,尽管看起来版本号完全一致,解释见这里

       这时候你需要重新删除或者安装新内核,务必使得当前运行内核版本与debug 符号版本保值完全一致,包括build时间。这时候也许你需要了解如何安装/卸载linux内核,类似文章一搜一大堆。

       

    最后,进阶就要靠文档和官网了。

    新手文档:https://sourceware.org/systemtap/SystemTap_Beginners_Guide.pdf

    官方示例脚本(非常丰富):https://sourceware.org/systemtap/examples/keyword-index.html

    注意上面说的User Space App需要的是RedHat6U以上操作系统,否则会发现system tap跟中应用程序的时候像hang住了一样。

  • 相关阅读:
    原理Lambda表达式
    关于Web.config的debug和release.config文件
    利用GeoIP数据库及API进行地理定位查询 Java
    JSONP跨域的原理解析
    如何处理JSON中的特殊字符
    IIS下防止mdb数据库被下载的实现方法
    点击文字选中radio
    关于微信40029错误
    nopcommerce的WidgetZones
    js判断移动终端(手机浏览器)
  • 原文地址:https://www.cnblogs.com/raymondshiquan/p/2643011.html
Copyright © 2020-2023  润新知