SystemTap accepts script as command line option or external file, for example:
SystemTap command line arguments may be passed to a script, but it distingushes their types: numerical arguments are accessible with `$` prefix: `$1`, `$2` … `$n` while string arguments have `@` prefix: `@1`, `@2` … `@n`
Here are some useful `stap(1)` options:
When SystemTap needs to resolve address into a symbol (for example, instruction pointer to a corresponding function name), it doesn’t look into libraries or kernel modules.
Here are some useful command-line options that enable that:
# SystemTap example
Here is sample SystemTap script:
#!/usr/sbin/stap
probe syscall.write { if(pid() == target())
printf(“Written %d bytes”, $count); }
Save it to `test.stp` and run like this:
root@host# stap /root/test.stp -c “dd if=/dev/zero of=/dev/null count=1”
_Q__: Run SystemTap with following options: `# stap -vv -k -p4 /root/test.stp `, find generated directory in `/tmp` and look into created C source.
__Q__: Calculate number of probes in a `syscall` provider and number of variables provided by `syscall.write` probe:
运行SystemTap。
运行SystemTap首先需要root权限。
运行SystemTap有三种形式:
1. 从文档(通常以.stp作为文档名后缀)中读入并运行脚本:stap [选项] 文档名。
2. 从标准输入中读入并运行脚本: stap [选项]。
3. 运行命令行中的脚本:stap [选项] -e 脚本。
4. 直接运行脚本文档(需要可执行属性并且第一行加上#!/usr/bin/stap):./脚本文档名用”Ctrl C”中止SystemTap的运行。
systemtap的选项还在不断的扩展和更新中,其中最常用的选项包括:
-v — 打印中间信息;
-p NUM — 运行完Pass Num后停止(缺省是运行到Pass 5);
-k — 运行结束后保留临时文档不删除;
-b — 使用RelayFS文档系统来将数据从内核空间传输到用户空间;
-M — 仅当使用-b选项时有效,运行结束时不合并每个CPU的单独数据文档;
-o FILE — 输出到文档,而不是输出到标准输出;
-c CMD — 启动探测后,运行CMD命令,直到命令结束后退出;
-g — 采用guru模式,允许脚本中嵌入C语句;
转载于:https://www.cnblogs.com/zengkefu/p/4803362.html
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208042.html原文链接:https://javaforall.net
