SystemTap accepts script as command line option or external file, for example:

* Command-line script is passed with `-e` option
   `# stap -e 'probe syscall.write { printf("%d\n", $fd); }' [arguments]`
 * External file as first argument:
   `# stap syscalls. [arguments]`

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:

* `-l PROBESPEC` accepts probe specifier without `probe` keyword (but with wildcards) and prints all matching probe names (more on wildcards in [Probes][lang/probes]). `-L` will also print probe arguments and their types. For example:
`# stap -l 'scsi.*'`
* `-v` -- increases verbosity of SystemTap. The more letters you passed, the more diagnostic information will be printed. If only one `-v` was passed, `stap` will report only finishing of each stage.
* `-p STAGE` -- ends stap process after _STAGE_, represented with a number starting with 1 (_parse_).
* `-k` -- stap tool won't delete SystemTap temporary files created during compilation (sources and kernel modules kept in `/tmp/stapXXXX` directory),
* `-g` -- enables Guru-mode, that allows to bind to blacklisted probes and write into kernel memory along with using Embedded C in your scripts. Generally speaking, it allows dangerous actions.
* `-c COMMAND` and `-x PID` -- like those in DTrace, they allow to bind SystemTap to a specific process
* `-o FILE` -- redirects output to a file. If it already exists, SystemTap __rewrites__ it.
* `-m NAME` -- when compiling a module, give it meaningful name instead of `stap_<gibberish>`.

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:

* `-d MODULEPATH` -- enables symbol resolving for a specific library or kernel module. Note that in case it is not provided, `stap` will print a warning with corresponding `-d` option.
* `--ldd` -- for tracing process -- use `ldd` to add all linked libraries for a resolving.
* `--all-modules` -- enable resolving for all kernel modules

#### 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:

# stap -l 'syscall.*' | wc -l
# stap -L 'syscall.write'

运行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语句;

stap 命令的更多相关文章

  1. SystemTap知识(一)

    SystemTap是一个系统的跟踪探测工具.它能让用户来跟踪和研究计算机系统在底层的实现. 安装SystemTap需要为你的系统内核安装-devel,-debuginfo,-debuginfo-com ...

  2. XtraBackup原理4

    MySQL · 答疑解惑 · 物理备份死锁分析 背景 本文对 5.6 主备场景下,在备库做物理备份遇到死锁的case进行分析,希望对大家有所帮助. 这里用的的物理备份工具是 Percona-XtraB ...

  3. SystemTap----将SystemTap脚本编译成内核模块

      当运行SystemTap脚本时,会根据脚本生成一个内核模块,然后插入到系统中执行后退出.这个过程总共分为5个阶段:parse, elaborate, translate, compile, run ...

  4. 【技术干货】听阿里云CDN安防技术专家金九讲SystemTap使用技巧

    ​1.简介 SystemTap是一个Linux非常有用的调试(跟踪/探测)工具,常用于Linux 内核或者应用程序的信息采集,比如:获取一个函数里面运行时的变 量.调用堆栈,甚至可以直接修改变量的值, ...

  5. PostgreSQL SystemTap on Linux 转

    PostgreSQL 支持动态跟踪, 可以通过dtrace或者systemtap工具统计相关探针的信息. 安装systemtap yum install systemtap kernel-debugi ...

  6. [译] SystemTap

    SystemTap 什么是system Tap ? SystemTap 提供环境用来获得更多关于内核几乎所有组件的信息,用以被进一步分析.SystemTap也可以被当作一种工具,为用户研究和监控内核详 ...

  7. Linux性能优化实战学习笔记:第四十二讲

    一.上节回顾 上一节,我们学习了 NAT 的原理,明白了如何在 Linux 中管理 NAT 规则.先来简单复习一下. NAT 技术能够重写 IP 数据包的源 IP 或目的 IP,所以普遍用来解决公网 ...

  8. 高效Linux用户需要了解的命令行技能

    最近在Quora上看到一个问答题目,关于在高效率Linux用户节省时间Tips. 将该题目的回答进行学习总结,加上自己的一些经验,记录如下,方便自己和大家参考. 下面介绍的都是一些命令行工具,这些工具 ...

  9. Mac命令行

    参考:http://www.cnblogs.com/-ios/p/4949923.html 必读 涵盖范围: 这篇文章对刚接触命令行的新手以及具有命令行使用经验的人都有用处.本文致力于做到覆盖面广(尽 ...

随机推荐

  1. vue需要注意的事宜

    1.Vue在进行点击事件的时候大部分是在标签上进行添加的,一般在标签上添加@click: 如果需要在组件上面进行点击事件的时候,直接写@click是木有变化的,需要在后面添加一个.native就如@c ...

  2. Requests中出现大量ASYNC_NETWORK_IO等待

    七夕活动,网页显示异常:504 Gateway Time-out The server didn't respond in time.开发询问数据库是否正常,当时正连接在实例上查询数据,感觉响应确实慢 ...

  3. centos6.5环境通过shell脚本备份php的web及mysql数据库并做远程备份容灾

    centos6.5环境通过shell脚本备份php的web及mysql数据库并做远程备份容灾 系统:centos6.5 1.创建脚本目录 mkdir -p /usr/local/sh/ 创建备份web ...

  4. Android方法引用数超过65535优雅解决

    随着应用不断迭代更新,业务线的扩展,应用越来越大(比如:集成了各种第三方SDK或者公共开源的Library文件.jar文件)这样一来,项目耦合性就很高,重复作用的类就越来越多了,SO:问题就来了.相信 ...

  5. 浅谈js设计模式之代理模式

    代理模式是一种非常有意义的模式,在生活中可以找到很多代理模式的场景.比如,明星都有经纪人作为代理.如果想请明星来办一场商业演出,只能联系他的经纪人.经纪人会把商业演出的细节和报酬都谈好之后,再把合同交 ...

  6. JS模块化编程(二):require.js基本用法

    require.config() 接受一个配置对象 常用属性: paths: shim: 配置不兼容的模块 baseUrl: 引用模块的文件基目录

  7. android短信验证

    短信验证demo http://download.csdn.net/detail/crazy1235/8315279#comment 使用MOB平台开发,用法详见: http://blog.csdn. ...

  8. VMware下三种网络连接模式

    VMware下三种网络连接模式 Bridged(桥接模式) 在桥接模式下,VMware虚拟出来的操作系统就像是局域网中的一独立的主机,它可以访问该类网段内任何一台机器. 桥接网络环境下需要做到: 手动 ...

  9. #JS 窗口resize避免触发多次

    window窗口改变时触发resize,如何避免多次执行,设置一个300ms定时器即可. //窗口变化监听,避免resize多次执行卡顿 var resizeTimer = null; $(windo ...

  10. norbert-构建服务器集群感知的 Java 应用程序

    http://www.ibm.com/developerworks/cn/java/j-zookeeper/index.html