40.2. 使用 SystemTap 的追踪功能调用
您可以使用 para-callgraph.stp SystemTap 脚本来跟踪函数调用和函数返回。
先决条件
- 如安装 Systemtap 所述,已安装了 SystemTap。
流程
- 运行 para-callgraph.stp 脚本。
# stap --example para-callgraph.stp 'argument1' 'argument2'
脚本 para-callgraph.stp 有两个命令行参数:
- 您需要跟踪其 entry/exit 的功能名称。
- 可选的触发器功能,用于在每个线程上启用或禁用追踪。只要触发器功能还没有退出,每个线程中的追踪将继续。
考虑以下示例:
# stap -wv --example para-callgraph.stp 'kernel.function("*@fs/proc.c*")' 'kernel.function("vfs_read")' -c "cat /proc/sys/vm/* || true"
其中:
- -w : 压制警告。
- -v :使启动内核的输出可见。
-
-c 命令 : 告知 Tells SystemTap 在执行命令期间用于计数功能调用,在这个示例中是
/bin/true。
输出应类似于以下内容:
[...]
267 gnome-terminal(2921): <-do_sync_read return=0xfffffffffffffff5
269 gnome-terminal(2921):<-vfs_read return=0xfffffffffffffff5
0 gnome-terminal(2921):->fput file=0xffff880111eebbc0
2 gnome-terminal(2921):<-fput
0 gnome-terminal(2921):->fget_light fd=0x3 fput_needed=0xffff88010544df54
3 gnome-terminal(2921):<-fget_light return=0xffff8801116ce980
0 gnome-terminal(2921):->vfs_read file=0xffff8801116ce980 buf=0xc86504 count=0x1000 pos=0xffff88010544df48
4 gnome-terminal(2921): ->rw_verify_area read_write=0x0 file=0xffff8801116ce980 ppos=0xffff88010544df48 count=0x1000
7 gnome-terminal(2921): <-rw_verify_area return=0x1000
12 gnome-terminal(2921): ->do_sync_read filp=0xffff8801116ce980 buf=0xc86504 len=0x1000 ppos=0xffff88010544df48
15 gnome-terminal(2921): <-do_sync_read return=0xfffffffffffffff5
18 gnome-terminal(2921):<-vfs_read return=0xfffffffffffffff5
0 gnome-terminal(2921):->fput file=0xffff8801116ce980