summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.examples/io/disktop.stp
diff options
context:
space:
mode:
authorDave Brolley <brolley@redhat.com>2008-08-08 15:15:19 -0400
committerDave Brolley <brolley@redhat.com>2008-08-08 15:15:19 -0400
commit71906647386a9684086b0542318b536d95ae089c (patch)
treefb0348d7bb34095e95ad830da8e832bad9187a55 /testsuite/systemtap.examples/io/disktop.stp
parentd5658775da9fa0ac792eb3f874df9f7c4d60de7e (diff)
parentf1118e1032612170cae8cd979cd529722ad95fdb (diff)
downloadsystemtap-steved-71906647386a9684086b0542318b536d95ae089c.tar.gz
systemtap-steved-71906647386a9684086b0542318b536d95ae089c.tar.xz
systemtap-steved-71906647386a9684086b0542318b536d95ae089c.zip
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap
Conflicts: ChangeLog testsuite/ChangeLog
Diffstat (limited to 'testsuite/systemtap.examples/io/disktop.stp')
-rw-r--r--testsuite/systemtap.examples/io/disktop.stp69
1 files changed, 69 insertions, 0 deletions
diff --git a/testsuite/systemtap.examples/io/disktop.stp b/testsuite/systemtap.examples/io/disktop.stp
new file mode 100644
index 00000000..2637d735
--- /dev/null
+++ b/testsuite/systemtap.examples/io/disktop.stp
@@ -0,0 +1,69 @@
+#!/usr/bin/env stap
+#
+# Copyright (C) 2007 Oracle Corp.
+#
+# Get the status of reading/writing disk every 5 seconds, output top ten entries
+#
+# This is free software,GNU General Public License (GPL); either version 2, or (at your option) any
+# later version.
+#
+# Usage:
+# ./disktop.stp
+#
+
+global io_stat,device
+global read_bytes,write_bytes
+
+probe kernel.function("vfs_read").return {
+ if ($return>0) {
+ dev = __file_dev($file)
+ devname = __find_bdevname(dev,__file_bdev($file))
+
+ if (devname!="N/A") {/*skip read from cache*/
+ io_stat[pid(),execname(),uid(),ppid(),"R"] += $return
+ device[pid(),execname(),uid(),ppid(),"R"] = devname
+ read_bytes += $return
+ }
+ }
+}
+
+probe kernel.function("vfs_write").return {
+ if ($return>0) {
+ dev = __file_dev($file)
+ devname = __find_bdevname(dev,__file_bdev($file))
+
+ if (devname!="N/A") { /*skip update cache*/
+ io_stat[pid(),execname(),uid(),ppid(),"W"] += $return
+ device[pid(),execname(),uid(),ppid(),"W"] = devname
+ write_bytes += $return
+ }
+ }
+}
+
+probe timer.ms(5000) {
+ /* skip non-read/write disk */
+ if (read_bytes+write_bytes) {
+
+ printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",ctime(gettimeofday_s()),"Average:",
+ ((read_bytes+write_bytes)/1024)/5,"Read:",read_bytes/1024,"Write:",write_bytes/1024)
+
+ /* print header */
+ printf("%8s %8s %8s %25s %8s %4s %12s\n","UID","PID","PPID","CMD","DEVICE","T","BYTES")
+ }
+ /* print top ten I/O */
+ foreach ([process,cmd,userid,parent,action] in io_stat- limit 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])
+
+ /* clear data */
+ delete io_stat
+ delete device
+ read_bytes = 0
+ write_bytes = 0
+}
+
+probe end{
+ delete io_stat
+ delete device
+ delete read_bytes
+ delete write_bytes
+}