From c1f7a8464fa9054e6ee06e05451f555b5504dd71 Mon Sep 17 00:00:00 2001 From: ddomingo Date: Thu, 4 Dec 2008 10:44:40 +1000 Subject: revised as per wcohen, added new section iotime --- .../en-US/extras/inodewatch-simple.stp | 3 +- .../en-US/extras/iotime-simple.stp | 82 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 doc/SystemTap_Beginners_Guide/en-US/extras/iotime-simple.stp (limited to 'doc/SystemTap_Beginners_Guide/en-US') diff --git a/doc/SystemTap_Beginners_Guide/en-US/extras/inodewatch-simple.stp b/doc/SystemTap_Beginners_Guide/en-US/extras/inodewatch-simple.stp index d1cbf6f6..80d1ca8e 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/extras/inodewatch-simple.stp +++ b/doc/SystemTap_Beginners_Guide/en-US/extras/inodewatch-simple.stp @@ -1,5 +1,4 @@ -probe kernel.function ("vfs_write"), - kernel.function ("vfs_read") +probe vfs.write, vfs.read { dev_nr = $file->f_dentry->d_inode->i_sb->s_dev inode_nr = $file->f_dentry->d_inode->i_ino diff --git a/doc/SystemTap_Beginners_Guide/en-US/extras/iotime-simple.stp b/doc/SystemTap_Beginners_Guide/en-US/extras/iotime-simple.stp new file mode 100644 index 00000000..a14f7731 --- /dev/null +++ b/doc/SystemTap_Beginners_Guide/en-US/extras/iotime-simple.stp @@ -0,0 +1,82 @@ +global start +global entry_io +global fd_io +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 filenames +global filehandles +global fileread +global filewrite + +probe syscall.open { + filenames[pid()] = user_string($filename) +} + +probe syscall.open.return { + if ($return != -1) { + filehandles[pid(), $return] = filenames[pid()] + fileread[pid(), $return] = 0 + filewrite[pid(), $return] = 0 + } else { + printf("%d %s access %s fail\n", timestamp(), proc(), filenames[pid()]) + } + delete filenames[pid()] +} + +probe syscall.read { + if ($count > 0) { + fileread[pid(), $fd] += $count + } + t = gettimeofday_us(); p = pid() + entry_io[p] = t + fd_io[p] = $fd +} + +probe syscall.read.return { + t = gettimeofday_us(); p = pid() + fd = fd_io[p] + time_io[p,fd] <<< t - entry_io[p] +} + +probe syscall.write { + if ($count > 0) { + filewrite[pid(), $fd] += $count + } + t = gettimeofday_us(); p = pid() + entry_io[p] = t + fd_io[p] = $fd +} + +probe syscall.write.return { + t = gettimeofday_us(); p = pid() + fd = fd_io[p] + time_io[p,fd] <<< t - entry_io[p] +} + +probe syscall.close { + if (filehandles[pid(), $fd] != "") { + 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 fd_io[pid()] + delete entry_io[pid()] + delete time_io[pid(),$fd] +} \ No newline at end of file -- cgit