systemtap 脚本示例
.[root@localhost ~]# stap -v -e 'probe vfs.read {printf("read performed\n"); exit()}'
Pass : parsed user script and library script(s) using 146900virt/23668res/3024shr/21332data kb, in 130usr/40sys/183real ms.
Pass : analyzed script: probe(s), function(s), embed(s), global(s) using 257648virt/78000res/6100shr/71736data kb, in 510usr/870sys/2099real ms.
Pass : using cached /root/.systemtap/cache/e2/stap_e2a36f2dcc498d9e1b0e44a8fa8004fa_1020.c
Pass : using cached /root/.systemtap/cache/e2/stap_e2a36f2dcc498d9e1b0e44a8fa8004fa_1020.ko
Pass : starting run.
read performed
Pass : run completed in 10usr/40sys/344real ms.
.[root@localhost ~]# uname -m
x86_64
.[root@localhost ~]# uname -r
2.6.-.el5
.[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.-.el5 # SMP Wed Dec :: EST x86_64 x86_64 x86_64 GNU/Linux
.stap -r kernel_version script -m module_name
stap -r 2.6.-.el5 -e 'probe vfs.read {exit()}' -m simple
生成simple.ko
staprun simple.ko
. [root@localhost ~]# echo "probe timer.s(10) {exit()}" | stap -v -
说明:To instruct stap to read a SystemTap script from standard input, use the - switch instead of the file name
.stap -e 'probe module("ext3").function("*") {println(execname()," ",pid()) }'
.stap -e 'probe timer.s(4) {println(execname()," ",pid()) }'
.stap -e 'probe begin{printf ("hello world\n"); exit() }'
.stap -e 'probe syscall.open { printf("%s(%d) open\n", execname(), pid()) }'
.[root@localhost ~]# cat >thread_indent.stp
probe kernel.function("*@net/socket.c").call
{
printf ("%s -> %s\n", thread_indent(), probefunc())
}
probe kernel.function("*@net/socket.c").return
{
printf ("%s <- %s\n", thread_indent(-), probefunc())
}
[root@localhost ~]# stap thread_indent.stp
pcscd(): -> sock_poll
pcscd(): <- sock_poll
pcscd(): -> sock_poll
pcscd(): <- sock_poll
.
[root@localhost ~]# cat .stp
probe syscall.* {
if(pid() == target())
printf("%s\n", name)
}
stap .stp -x
.[root@localhost ~]# stap .stp -c "ls -a"
.[root@localhost ~]# stap -L 'kernel.function("vfs_read")'
kernel.function("vfs_read@fs/read_write.c:248") $file:struct file* $buf:char* $count:size_t $pos:loff_t*
.
stap -e 'probe kernel.function("vfs_read") {
printf ("current files_stat max_files: %d\n",
@var("files_stat@fs/file_table.c")->max_files);
exit(); }'
.打印刷 函数的(vfs_read)四个参数
[root@localhost ~]# stap -e 'probe kernel.function("vfs_read") {printf("%s\n", $$parms); exit(); }'
file=0xffff81005429d0c0 buf=0x7fff98a0c270 count=0x2004 pos=0xffff8100363d3f50
说明:There are four parameters passed into vfs_read: file, buf, count, and pos.
The $$parms generates a string for the parameters passed into the function.
In this case all but the count parameter are pointers.
.打印数据结构
stap -e 'probe kernel.function("vfs_read") {printf("%s\n", $$parms$); exit(); }'
file={ .f_u={...},
.f_dentry=0xffff81003492c660,
.f_vfsmnt=0xffff810047fb70c0,
.f_op=0xffffffff886594a0,
.f_count={...},
.f_flags=,
.f_mode=,
.f_pos=,
.f_owner={...},
.f_uid=,
.f_gid=,
.f_ra={...},
.f_version=,
.f_security=0x0,
.private_data=0x0,
.f_ep_links={...},
.f_ep_lock={...},
.f_mapping=0xffff8100346125c0
}
buf=""
count=
pos=-
.打印更详细的数据结构
stap -e 'probe kernel.function("vfs_read") {printf("%s\n", $$parms$$); exit(); }'
file={.f_u={.fu_list={.next=0xffff810057a3e0f8,
.prev=0xffff8100440d70c0},
.fu_rcuhead={.next=0xffff810057a3e0f8,
.func=0xffff8100440d70c0
}
},
.f_dentry=0xffff810032dbb150,
.f_vfsmnt=0xffff810047fb70c0,
.f_op=0xffffffff8865b040,
.f_count={.counter=},
.f_flags=,
.f_mode=,
.f_pos=,
.f_owner={.lock={.raw_lock={.lock=}},
.pid=,
.uid=,
.euid=,
.security=0x0,
.signum=},
.f_uid=,
.f_gid=,
.f_ra={.start=,
.size=,
.flags=,
.cache_hit=,
.prev_page=,
.ahead_start=,
.ahea
说明:With the “$” suffix fields that are composed of data structures are not expanded.
The “$$” suffix will print the values contained within the nested data structures
.@cast:类型转换
function task_state:long (task:long)
{
return @cast(task, "task_struct", "kernel<linux/sched.h>")->state
}
The function returns the value of the state field from a task_struct pointed to by the long task.
The first argument of the @cast operator, task, is the pointer to the object.
The second argument is the type to cast the object to, task_struct.
The third argument lists what file that the type definition information comes from and is optional.
.命令行参数传递
Use $ if you are expecting the user to enter an integer as a command-line argument,
and @ if you are expecting a string.
cat >.stp
probe kenel.function(@)
{
printfln( execname(),@)
}
[root@localhost ~]# stap stap .stp vfs_read
.
foo["tom"] =
foo["dick"] =
foo["harry"] =
device[pid(),execname(),uid(),ppid(),"W"] = devname
All associate arrays must be declared as global,
regardless of whether the associate array is used in one or multiple probes
.
global reads
probe vfs.read
{
reads[execname()] ++
}
probe timer.s()
{
foreach (count in reads)
printf("%s : %d \n", count, reads[count])
}
.
probe timer.s()
{
foreach (count in reads- limit )
printf("%s : %d \n", count, reads[count])
}
reads:数组
limit :
The limit option instructs the foreach to only process the first ten iterations
(that is, print the first , starting with the highest value).
-:in descending order
cat >.stp
global reads
probe vfs.read
{
reads[execname()] ++
}
probe timer.s()
{
printf("=======\n")
foreach (count in reads-)
printf("%s : %d \n", count, reads[count])
if(["stapio"] in reads) {
printf("stapio read detected, exiting\n")
}
.
global reads
probe vfs.read
{
reads[execname(),pid()] <<<
}
probe timer.s()
{
foreach([var1,var2] in reads)
printf("%s (%d) : %d \n", var1, var2, @count(reads[var1,var2]))
}
@count(reads[execname()]) will return how many values are stored in each unique key in array reads.
@sum(reads[execname()]) will return the total of all values stored in each unique key in array reads.
the operator <<< $count stores the amount returned by $count to
the associated value of the corresponding execname() in the reads array
systemtap 脚本示例的更多相关文章
- MeteoInfoLab脚本示例:闪电位置图
这个脚本示例读取文本格式的闪电数据,读出每条闪电记录的经纬度和强度,在地图上绘制出每个闪电的位置,并用符号和颜色区分强度正负.数据格式如下:0 2009-06-06 00:01:16.6195722 ...
- MeteoInfoLab脚本示例:FY-3C全球火点HDF数据
FY-3C全球火点HDF数据包含一个FIRES二维变量,第一维是火点数,第二维是一些属性,其中第3.4列分别是火点的纬度和经度.下面的脚本示例读出所有火点经纬度并绘图.脚本程序: #Add data ...
- MeteoInfo脚本示例:GrADS to netCDF
这里给出一个将GrADS数据文件转为netCDF数据文件的脚本示例程序,其它格式数据转netCDF可以参考: #-------------------------------------------- ...
- MeteoInfoLab脚本示例:AMSR-E卫星数据投影
AMSR-E(http://nsidc.org/data/amsre/index.html)数据中的Land3数据是HDF-EOS4格式,投影是Cylindrical_Equal_Area.这里示例读 ...
- MeteoInfoLab脚本示例:创建netCDF文件(合并文件)
在MeteoInfoLab中增加了创建netCDF文件并写入数据的功能,这里利用合并多个netCDF文件为一个新的netCDF文件为例.1.创建一个可写入的netCDF文件对象(下面用ncfile表示 ...
- MeteoInfoLab脚本示例:Trajectory
示例读取HYSPLIT模式输出的气团轨迹数据文件,生成轨迹图层,并显示轨迹各节点的气压图.脚本程序: f = addfile_hytraj('D:/MyProgram/Distribution/jav ...
- MeteoInfoLab脚本示例:Hamawari-8 netCDF data
示例数据:ftp://ftp.bom.gov.au/anon/sample/catalogue/Satellite/IDE00220.201507140300.nc 该数据的分辨率很高(22000*2 ...
- MeteoInfoLab脚本示例:读取文本文件绘制散度图
MeteoInfoLab中读取文本文件数据的函数是asciiread,获取文本文件行.列数的函数是numasciirow和numasciicol,和NCL中函数名一致,但都是小写字母.本例中的示例数据 ...
- MeteoInfoLab脚本示例:站点数据绘制等值线
站点数据绘制等值线需要首先将站点数据插值为格点数据,MeteoInfo中提供了反距离权法(IDW)和cressman两个方法,其中IDW方法可以有插值半径的选项.这里示例读取一个MICAPS第一类数据 ...
随机推荐
- 树莓派编译安装opencv3 (2019.1.6更新)
一.更新系统 sudo apt-get update sudo apt-get upgrade sudo rpi-update #重启系统 sudo reboot 二.安装依赖库及程序 sudo ap ...
- System.Web.Routing入门及进阶 下篇
上面介绍的是最简单的一种定义方式.当然我们可以建立更复杂的规则.其中就包括设定规则的默认值以及设定规则的正则表达式. UrlRouting高级应用 预计效果: 当我访问/a/b.aspx时就会转到De ...
- net MongoDB安装
Mongo服务器端下载链接:https://www.mongodb.com/download-center?jmp=nav 客户端查看工具Mongovue工具下载链接:http://pan.baidu ...
- Linux 生产实习01
Linux 生产实习01 标签(空格分隔): Linux 2018.07.02 相关软件下载地址:Linux Study 0x01. 安装 VMware Workstation VMware Work ...
- 001_Eclipse编写第一个Java程序
1 下载并安装jdk 2 下载较新版本的eclipse,eclipse都是非安装版的,解压缩即可. 3 双击eclipse.exe,打开elipse软件 4 FileàNewàProject 5 选择 ...
- 如何用NAnt管理单文件程序仓库
因为学习C#各种特性和使用方法的需要,常常会编写和收集一些例子代码.一段时间之后,这种代码的数量就增加到无法通过简单粗暴的方式进行管理了.采用NAnt进行管理是一个不错的选择,虽然部分特性只有MSBu ...
- 《MySQL技术内幕 InnoDB存储引擎 》学习笔记
第1章 MySQL体系结构和存储引擎 1.3 MySQL存储引擎 数据库和文件系统最大的区别在于:数据库是支持事务的 InnoDB存储引擎: MySQL5.5.8之后默认的存储引擎,主要面向OLTP ...
- codewar 上做练习的一些感触
废话 在[codewar][1]上做练习,每次都是尽量快速地做完,然后赶着去看排名里面clever分最高的solution,看完每次都要感叹一下人家怎么可以写得这么简洁,甚至有一次我用了一段大约七八行 ...
- application/json 四种常见的 POST 提交数据方式
四种常见的 POST 提交数据方式 HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 ...
- P1417 烹调方案 背包DP
题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...