Debian Codegraph @

testsuite/systemtap.examples/io/disktop.stp

raw
1 #!/usr/bin/env stap
2 #
3 # Copyright (C) 2007 Oracle Corp.
4 #
5 # Get the status of reading/writing disk every 5 seconds,
6 # output top ten entries
7 #
8 # This is free software,GNU General Public License (GPL);
9 # either version 2, or (at your option) any later version.
10 #
11 # Usage:
12 # ./disktop.stp
13 #
14
15 global io_stat,device
16 global read_bytes,write_bytes
17
18 probe vfs.read.return {
19 if (returnval()>0) {
20 if (devname!="N/A") {/*skip read from cache*/
21 io_stat[pid(),execname(),uid(),ppid(),"R"] += returnval()
22 device[pid(),execname(),uid(),ppid(),"R"] = devname
23 read_bytes += returnval()
24 }
25 }
26 }
27
28 probe vfs.write.return {
29 if (returnval()>0) {
30 if (devname!="N/A") { /*skip update cache*/
31 io_stat[pid(),execname(),uid(),ppid(),"W"] += returnval()
32 device[pid(),execname(),uid(),ppid(),"W"] = devname
33 write_bytes += returnval()
34 }
35 }
36 }
37
38 probe timer.ms(5000) {
39 /* skip non-read/write disk */
40 if (read_bytes+write_bytes) {
41
42 printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",
43 ctime(gettimeofday_s()),
44 "Average:", ((read_bytes+write_bytes)/1024)/5,
45 "Read:",read_bytes/1024,
46 "Write:",write_bytes/1024)
47
48 /* print header */
49 printf("%8s %8s %8s %25s %8s %4s %12s\n",
50 "UID","PID","PPID","CMD","DEVICE","T","BYTES")
51 }
52 /* print top ten I/O */
53 foreach ([process,cmd,userid,parent,action] in io_stat- limit 10)
54 printf("%8d %8d %8d %25s %8s %4s %12d\n",
55 userid,process,parent,cmd,
56 device[process,cmd,userid,parent,action],
57 action,io_stat[process,cmd,userid,parent,action])
58
59 /* clear data */
60 delete io_stat
61 delete device
62 read_bytes = 0
63 write_bytes = 0
64 }
65
66 probe end{
67 delete io_stat
68 delete device
69 delete read_bytes
70 delete write_bytes
71 }