大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
IO相关
ioblock.request–没有参数,当产生IO请求时出发
ioblock.end–没有参数,在1个IO块请求transfer后出发
ioblock_trace.request–对bio产生一个IO请求时触发
ioblock_trace.end–IO块传输完毕后触发
vfs.read
vfs.write
例1
io/eatmydata.stp
禁止fsync/fdatasync调用
# stap -g eatmydata.stp -c ‘strace ls || true’
global dummy_fd =1 #stdout,也可通过stap -G dummy_fd=xxx覆盖此设置
global guilt,agony,piety
probe syscall.fsync, syscall.fdatasync {
#实际上我们无法禁止调用这两个函数,但可以通过改变其fd间接达到这一效果
if( pid() == target()) {
try {
$fd = dummy_fd
guilt ++
} catch {
agnoy ++
}
}
else
piety ++
}
probe syscall.fsync.return, syscall.fdatasync.return {
#在函数调用返回时覆盖其返回状态
if (pid() == target())
try {$return =0} catch{}
}
probe begin {
printf(“redirecting f*sync by pid %d to fd %d\n”, target(), dummy_fd)
}
probe error,end {
printf(“redirected f*sync by pid %d to fd %d, success %d times, failed %d times.\n”, target(),dummy_fd,guilt,agnoy)
printf(“preserved f*sync by other processes %d times.\n”, piety)
}
注:target()用于返回进程id,通常和-x PID或-c CMD一起使用
例2
io/inodewatch.stp
检测设备的读写
stap inodewatch.stp 0x08 0x01 100 -c “sleep 0.2”
#! /usr/bin/env stap
probe vfs.write, vfs.read
{
# dev and ino are defined by vfs.write and vfs.read
if (dev == MKDEV($1,$2) && ino == $3)
printf (“%s(%d) %s 0x%x/%u\n”, execname(), pid(), probefunc(), dev, ino)
}
例3
io/iodevstats.stp
按读写数据量列举设备名
# stap iodevstats.stp -c “sleep 0.2”
#! /usr/bin/env stap
global reads, writes, totals
global vfs.read.return {
if($return > 0) {
reads[execname(),dev] <<
totals[execname(),dev] += $retrun
}
}
global vfs.write.return {
if($return > 0) {
writes[execname(),dev] <<
totals[execname(),dev] += $return
}
}
probe end {
printf(“\n%16s %8s %8s %8s %8s %8s %8s %8s\n”,””, “”, “”, “read”, “read”, “”, “write”, “write”)
printf(“%16s %8s %8s %8s %8s %8s %8s %8s\n”,”name”, “device”, “read”, “KB tot”, “B avg”, “write”, “KB tot”, “B avg”)
foreach([name,dev] in totals- limit 20) {
printf(“%16s %3d, %4d %8d %8d %8d %8d %8d %8d\n”,name, MAJOR(dev), MINOR(dev),
@count(reads[name,dev]),(@count(reads[name,dev]) ? @sum(reads[name,dev])>>10 : 0 ),(@count(reads[name,dev]) ? @avg(reads[name,dev]) : 0 ),
@count(writes[name,dev]),(@count(writes[name,dev]) ? @sum(writes[name,dev])>>10 : 0 ),(@count(writes[name,dev]) ? @avg(writes[name,dev]) : 0 ))
}
}
例4
io/ioblktime.stp
IO请求在队列的等待时间,如果系统当前IO过于繁忙可能会超过maxmapentries设置,调用时可指定参数-DMAXMAPENTRIES=10000
# stap ioblktime.stp -c “sleep 0.2”
#! /usr/bin/env stap
global req_time, etimes
probe ioblock.request {
req_time[$bio] = gettimeofday_us()
}
probe ioblock.end {
t = gettimeofday_us()
s = req_time[$bio]
delete req_time[$bio] –如果系统IO繁忙则req_time数组会很大,因此每次处理完都将其释放
if (s) {
etimes[devname, bio_rw_str(rw)] <
}
}
/* for time being delete things that get merged with others */
probe kernel.trace(“block_bio_frontmerge”),kernel.trace(“block_bio_backmerge”)
{
delete req_time[$bio]
}
probe timer.s(10), end {
ansi_clear_screen()
printf(“%10s %3s %10s %10s %10s\n”,”device”, “rw”, “total (us)”, “count”, “avg (us)”)
foreach ([dev,rw] in etimes – limit 20) {
printf(“%10s %3s %10d %10d %10d\n”, dev, rw, @sum(etimes[dev,rw]), @count(etimes[dev,rw]), @avg(etimes[dev,rw]))
}
delete etimes
}
例5
io/disktop.stp
每5秒总结IO读写信息,包括平均每秒读写KB数量以及调用次数排名前10的进程
# stap disktop.stp -c “sleep 0.2”
global readbytes,writebytes
global io_stat,device
probe vfs.read.return {
if ($return > 0) {
if (devname != “N/A” ) { /* 跳过cache read */
io_stat[pid(),execname(),uid(),ppid(),”R”] += $return
device[pid(),execname(),uid(),ppid(),”R”] = devname
readbytes += $return
}
}
}
–vfs.write.return处理逻辑类似
probe vfs.write.return {
if($return > 0) {
if(devname != “N/A”) {/*跳过cache write*/
io_stat[pid(),execname(),uid(),ppid(),”W”] += $return
device[pid(),execname(),uid(),ppid(),”W”] += devname
writebytes += $return
}
}
}
probe timer.ms(5000) {–每5秒调用一次
if ( readbytes + writebytes ) {
printf(“%-25s,%4dKb/sec,%6dKb,%6dkb\n”,ctime(gettimeofday_s()),(readbytes+writebytes)/5,readbytes/1024,writebytes/1024)
}
foreach ([process,cmd,userid,parent,action] in io_stat- limit 10) /* 打印前10位*/
printf(“%8d %8d %8d %25s %8s %4s %12d\n”,
userid,process,parent,cmd,
device[process,cmd,userid,parent,action],
action,io_stat[process,cmd,userid,parent,action])
–删除数组
delete io_stat
delete device
read_bytes = 0
write_bytes = 0
}
probe end{
delete io_stat
delete device
delete read_bytes
delete write_bytes
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15480802/viewspace-762765/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15480802/viewspace-762765/
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/234856.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...