Systemtap 使用指导一

2.跟踪

2.1 设置探针的位置

  Systemtap支持一系列嵌入事件。安装Systemtap时一起安装上的脚本库(每个叫做一个tapset:http://sourceware.org/systemtap/tapsets/)定义了附加的事件。所有的事件都使用统一的点分隔符来命名。

beginThe startup of the systemtap session.
endThe end of the systemtap session.
kernel.function("sys_open")The entry to the function named sys_open in the kernel.
syscall.close.returnThe return from the close system call.
module("ext3").statement(0xdeadbeef)The addressed instruction in the ext3 filesystem driver.
timer.ms(200)A timer that fires every 200 milliseconds.
timer.profileA timer that fires periodically on every CPU.
perf.hw.cache_missesA particular number of CPU cache misses have occurred.
procfs("status").readA process trying to read a synthetic file.
process("a.out").statement("*@main.c:200")Line 200 of the a.out program.
假如你要追踪一个源文件所有函数的进入和退出,比如内核中的net/socket.c.由于systemtap 为了把目标代码和源代码关联起来,它回去检测内核的编译信息,所以你使用kernel.function探针就很容易实现你的目的。

它像一个调试器:只要你能指出它的名字,它就可以探测到。使用kernel.function("*@net/socket.c").call来跟踪进入,kernel.function("*@net/socket.c").return 来探测退出。(*是通配符。)你甚至可以具体到行号,就像这样:("*@main.c:200")。

probe kernel.function("*@net/socket.c"){}

probe关键字表示植入一个探针,具体的处理函数写在花括号中。


在控制台中直接使用 stap FIFE.stp运行。

stap可以加参数:

-v 会打印出运行过程中的详细信息

-h去查看stap有哪些参数。


2.2打印什么

systemtap提供了很多例程来打印所需要的信息。包括一些排版。

比如:

tid()The id of the current thread.
pid()The process (task group) id of the current thread.
uid()The id of the current user.
execname()The name of the current process.
cpu()The current cpu number.
gettimeofday_s()Number of seconds since epoch.
get_cycles()Snapshot of hardware cycle counter.
pp()A string describing the probe point being currently handled.
probefunc()If known, the name of the function in which this probe was placed.
$$varsIf available, a pretty-printed listing of all local variables in scope.
print_backtrace()If possible, print a kernel backtrace.
print_ubacktrace()If possible, print a user-space backtrace.
probefunc()返回探针被植入的函数名。

这些函数的返回值可以是string或者是数值型。可以使用c语言型的格式化输出函数printf。用%s输出字符串,%d输出数值。包括换行/n.systemtap提供了一个函数thread_indent(n)来进行缩排。

见:http://sourceware.org/systemtap/tutorial/Tracing.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值