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第一类数据 ...
随机推荐
- 关于gb2312编码和utf8码的一个问题
ANSI(注意拼写不是ASCII)并不是“一种”编码,而是“多种”编码的统称.在简体中文Windows上,ANSI指GBK编码:在繁体中文Windows上,ANSI指Big5编码:在英文Windows ...
- aliyun EC2配置利用filezilla配置ftp服务
项目需要在阿里云EC2虚拟主机上配置ftp服务器,看了阿里云的教程可以使用filezilla配置,但一直遇到了一些问题.现记录一些步骤,避免以后出现类似问题. 1安装filezilla server ...
- 『实践』Yalmip+Ipopt+Cplex使用手册
Yalmip+Ipopt+Cplex使用手册 1.软件版本 Cplex 12.6.2,Matlab R2014a,Ipopt 3.12.9,Yalmip 2.Cplex添加方法 官方下载地址: htt ...
- TcxGrid标题头 字体加粗
- laravel5.3之后可以使用withCount()这个方法
比如:文章控制器ArticleController.php查询文章列表数据的时候用withCount连接Comment,Zan模型直接统计每篇文章的评论和点赞数量. 使用之前需要在文章模型文件Arti ...
- 《剑指offer》写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。
弱菜刷题还是刷中文题好了,没必要和英文过不去,现在的重点是基本代码能力的恢复. [题目] 剑指offer 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. [思路] 直觉 ...
- 1 、在Linux(centos6.8)系统下的JDK安装与配置
一.解压jdk安装包: 附上jdk1.8的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-21 ...
- Java编程的逻辑 (71) - 显式锁
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...
- Error:Makefile:452: target 'config' given more than once in the same rule
在解压的 linux2.6.15 文件夹下 make menuconfig 的时候出现下面的错误: Makefile:452: target 'config' given more than once ...
- jenkins 2:用ssh agent插件在pipeline里实现scp和远程执行命令
昨晚测试成功了. 现在ssh agent的认证,已不支持明文用户密码,而只能用加密方式实现. 所以我先在jenknis和nginx服务器之后,实现ssh免密码rsa证书登陆. 私钥放jenkins,公 ...