php 监控文件夹是否有文件更新,文件操作监控

#! /usr/bin/env stap

/*

* Copyright (C) 2006-2007 Red Hat Inc.

*

* This copyrighted material is made available to anyone wishing to use,

* modify, copy, or redistribute it subject to the terms and conditions

* of the GNU General Public License v.2.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

* Print out the amount of time spent in the read and write systemcall

* when each file opened by the process is closed. Note that the systemtap

* script needs to be running before the open operations occur for

* the script to record data.

*

* This script could be used to to find out which files are slow to load

* on a machine. e.g.

*

* stap iotime.stp -c 'firefox'

*

* Output format is:

* timestamp pid (executabable) info_type path ...

*

* 200283135 2573 (cupsd) access /etc/printcap read: 0 write: 7063

* 200283143 2573 (cupsd) iotime /etc/printcap time: 69

*

*/

global start

global time_io

function timestamp:long() { return gettimeofday_us() - start }

function proc:string() { return sprintf("%d (%s)", pid(), execname()) }

probe begin { start = gettimeofday_us() }

global filehandles, fileread, filewrite

probe syscall.open.return {

filename = user_string($filename)

if ($return != -1) {

filehandles[pid(), $return] = filename

} else {

printf("%d %s access %s fail\n", timestamp(), proc(), filename)

}

}

probe syscall.read.return {

p = pid()

fd = $fd

bytes = $return

time = gettimeofday_us() - @entry(gettimeofday_us())

if (bytes > 0)

fileread[p, fd] += bytes

time_io[p, fd] <<< time

}

probe syscall.write.return {

p = pid()

fd = $fd

bytes = $return

time = gettimeofday_us() - @entry(gettimeofday_us())

if (bytes > 0)

filewrite[p, fd] += bytes

time_io[p, fd] <<< time

}

probe syscall.close {

if ([pid(), $fd] in filehandles) {

printf("%d %s access %s read: %d write: %d\n",

timestamp(), proc(), filehandles[pid(), $fd],

fileread[pid(), $fd], filewrite[pid(), $fd])

if (@count(time_io[pid(), $fd]))

printf("%d %s iotime %s time: %d\n", timestamp(), proc(),

filehandles[pid(), $fd], @sum(time_io[pid(), $fd]))

}

delete fileread[pid(), $fd]

delete filewrite[pid(), $fd]

delete filehandles[pid(), $fd]

delete time_io[pid(),$fd]

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值