2.跟踪
2.1 设置探针的位置
Systemtap支持一系列嵌入事件。安装Systemtap时一起安装上的脚本库(每个叫做一个tapset:http://sourceware.org/systemtap/tapsets/)定义了附加的事件。所有的事件都使用统一的点分隔符来命名。
begin | The startup of the systemtap session. |
end | The end of the systemtap session. |
kernel.function("sys_open") | The entry to the function named sys_open in the kernel. |
syscall.close.return | The 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.profile | A timer that fires periodically on every CPU. |
perf.hw.cache_misses | A particular number of CPU cache misses have occurred. |
procfs("status").read | A process trying to read a synthetic file. |
process("a.out").statement("*@main.c:200") | Line 200 of the a.out program. |
它像一个调试器:只要你能指出它的名字,它就可以探测到。使用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. |
$$vars | If 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. |
这些函数的返回值可以是string或者是数值型。可以使用c语言型的格式化输出函数printf。用%s输出字符串,%d输出数值。包括换行/n.systemtap提供了一个函数thread_indent(n)来进行缩排。
见:http://sourceware.org/systemtap/tutorial/Tracing.html