| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 3 |
]> |
| 4 |
|
| 5 |
|
| 6 |
<section id="disktop"> |
| 7 |
<title>Summarizing Disk Read/Write Traffic</title> |
| 8 |
<indexterm> |
| 9 |
<primary>script examples</primary> |
| 10 |
<secondary>summarizing disk I/O traffic</secondary> |
| 11 |
</indexterm> |
| 12 |
|
| 13 |
<indexterm> |
| 14 |
<primary>examples of SystemTap scripts</primary> |
| 15 |
<secondary>summarizing disk I/O traffic</secondary> |
| 16 |
</indexterm> |
| 17 |
|
| 18 |
<indexterm> |
| 19 |
<primary>summarizing disk I/O traffic</primary> |
| 20 |
<secondary>script examples</secondary> |
| 21 |
</indexterm> |
| 22 |
|
| 23 |
<remark> |
| 24 |
NO ENTRY IN WAR STORIES: Summarize Disk Read/Write Traffic |
| 25 |
http://sourceware.org/systemtap/examples/io/disktop.stp |
| 26 |
</remark> |
| 27 |
|
| 28 |
<indexterm> |
| 29 |
<primary>disk I/O traffic, summarizing</primary> |
| 30 |
<secondary>script examples</secondary> |
| 31 |
</indexterm> |
| 32 |
<!-- next 2 indexterms for I/O traffic, summarizing --> |
| 33 |
|
| 34 |
<indexterm> |
| 35 |
<primary>I/O traffic, summarizing</primary> |
| 36 |
<secondary>script examples</secondary> |
| 37 |
</indexterm> |
| 38 |
|
| 39 |
<!-- next 2 indexterms for heaviest disk reads/writes, identifying --> |
| 40 |
|
| 41 |
<indexterm> |
| 42 |
<primary>heaviest disk reads/writes, identifying</primary> |
| 43 |
<secondary>script examples</secondary> |
| 44 |
</indexterm> |
| 45 |
|
| 46 |
|
| 47 |
<!-- next 2 indexterms for summarizing disk I/O traffic --> |
| 48 |
|
| 49 |
<indexterm> |
| 50 |
<primary>summarizing disk I/O traffic</primary> |
| 51 |
<secondary>script examples</secondary> |
| 52 |
</indexterm> |
| 53 |
|
| 54 |
|
| 55 |
<!-- next 2 indexterms for identifying heaviest disk reads/writes --> |
| 56 |
|
| 57 |
<indexterm> |
| 58 |
<primary>identifying heaviest disk reads/writes</primary> |
| 59 |
<secondary>script examples</secondary> |
| 60 |
</indexterm> |
| 61 |
|
| 62 |
<para>This section describes how to identify which processes are performing the heaviest disk reads/writes to the system.</para> |
| 63 |
|
| 64 |
<formalpara id="scriptdisktop"> |
| 65 |
<title>disktop.stp</title> |
| 66 |
<para> |
| 67 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/io/disktop.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 68 |
</para> |
| 69 |
</formalpara> |
| 70 |
|
| 71 |
<para><xref linkend="scriptdisktop"/> outputs the top ten processes responsible for the heaviest reads/writes to disk. <xref linkend="disktopoutput"/> displays a sample output for this script, and includes the following data per listed process:</para> |
| 72 |
|
| 73 |
<itemizedlist> |
| 74 |
<listitem><para><computeroutput>UID</computeroutput> — user ID. A user ID of <computeroutput>0</computeroutput> refers to the root user.</para></listitem> |
| 75 |
|
| 76 |
<listitem><para><computeroutput>PID</computeroutput> — the ID of the listed process.</para></listitem> |
| 77 |
|
| 78 |
<listitem><para><computeroutput>PPID</computeroutput> — the process ID of the listed process's <emphasis>parent process</emphasis>.</para></listitem> |
| 79 |
|
| 80 |
<listitem><para><computeroutput>CMD</computeroutput> — the name of the listed process.</para></listitem> |
| 81 |
|
| 82 |
<listitem><para><computeroutput>DEVICE</computeroutput> — which storage device the listed process is reading from or writing to.</para></listitem> |
| 83 |
|
| 84 |
<listitem><para><computeroutput>T</computeroutput> — the type of action performed by the listed process; <computeroutput>W</computeroutput> refers to write, while <computeroutput>R</computeroutput> refers to read.</para></listitem> |
| 85 |
|
| 86 |
<listitem><para><computeroutput>BYTES</computeroutput> — the amount of data read to or written from disk.</para></listitem> |
| 87 |
</itemizedlist> |
| 88 |
<!-- next 2 indexterms for ctime(), example of usage --> |
| 89 |
|
| 90 |
<indexterm> |
| 91 |
<primary>script examples</primary> |
| 92 |
<secondary>ctime(), example of usage</secondary> |
| 93 |
</indexterm> |
| 94 |
|
| 95 |
<indexterm> |
| 96 |
<primary>examples of SystemTap scripts</primary> |
| 97 |
<secondary>ctime(), example of usage</secondary> |
| 98 |
</indexterm> |
| 99 |
|
| 100 |
<indexterm> |
| 101 |
<primary>ctime(), example of usage</primary> |
| 102 |
<secondary>script examples</secondary> |
| 103 |
</indexterm> |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
<para>The time and date in the output of <xref linkend="scriptdisktop"/> is returned by the functions <command>ctime()</command> and <command>gettimeofday_s()</command>. <command>ctime()</command> derives calendar time in terms of seconds passed since the Unix epoch (January 1, 1970). <command>gettimeofday_s()</command> counts the <emphasis>actual</emphasis> number of seconds since Unix epoch, which gives a fairly accurate human-readable timestamp for the output.</para> |
| 108 |
<!-- next 3 indexterms for $return --> |
| 109 |
<indexterm> |
| 110 |
<primary>local variables</primary> |
| 111 |
<secondary>sample usage</secondary> |
| 112 |
<tertiary>$return</tertiary> |
| 113 |
</indexterm> |
| 114 |
|
| 115 |
<indexterm> |
| 116 |
<primary>variables (local)</primary> |
| 117 |
<secondary>sample usage</secondary> |
| 118 |
<tertiary>$return</tertiary> |
| 119 |
</indexterm> |
| 120 |
|
| 121 |
<indexterm> |
| 122 |
<primary>$return</primary> |
| 123 |
<secondary>sample usage</secondary> |
| 124 |
<tertiary>local variables</tertiary> |
| 125 |
</indexterm> |
| 126 |
<para> |
| 127 |
In this script, the <command>$return</command> is a local variable that stores the |
| 128 |
actual number of bytes each process reads or writes from the virtual file system. |
| 129 |
<command>$return</command> can only be used in return probes (for example, |
| 130 |
<command>vfs.read.return</command> and <command>vfs.read.return</command>). |
| 131 |
</para> |
| 132 |
|
| 133 |
<!--<remark>needinfo: what does $return do?</remark> --> |
| 134 |
<example id="disktopoutput"> |
| 135 |
<title><xref linkend="scriptdisktop"/> Sample Output</title> |
| 136 |
<screen>[...] |
| 137 |
Mon Sep 29 03:38:28 2008 , Average: 19Kb/sec, Read: 7Kb, Write: 89Kb |
| 138 |
|
| 139 |
UID PID PPID CMD DEVICE T BYTES |
| 140 |
0 26319 26294 firefox sda5 W 90229 |
| 141 |
0 2758 2757 pam_timestamp_c sda5 R 8064 |
| 142 |
0 2885 1 cupsd sda5 W 1678 |
| 143 |
|
| 144 |
Mon Sep 29 03:38:38 2008 , Average: 1Kb/sec, Read: 7Kb, Write: 1Kb |
| 145 |
|
| 146 |
UID PID PPID CMD DEVICE T BYTES |
| 147 |
0 2758 2757 pam_timestamp_c sda5 R 8064 |
| 148 |
0 2885 1 cupsd sda5 W 1678</screen> |
| 149 |
</example> |
| 150 |
|
| 151 |
<!-- |
| 152 |
<programlisting>global io_stat,device |
| 153 |
global read_bytes,write_bytes |
| 154 |
|
| 155 |
probe kernel.function("vfs_read").return { |
| 156 |
if ($return>0) { |
| 157 |
dev = __file_dev($file) |
| 158 |
devname = __find_bdevname(dev,__file_bdev($file)) |
| 159 |
|
| 160 |
if (devname!="N/A") {/*skip read from cache*/ |
| 161 |
io_stat[pid(),execname(),uid(),ppid(),"R"] += $return |
| 162 |
device[pid(),execname(),uid(),ppid(),"R"] = devname |
| 163 |
read_bytes += $return |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
probe kernel.function("vfs_write").return { |
| 169 |
if ($return>0) { |
| 170 |
dev = __file_dev($file) |
| 171 |
devname = __find_bdevname(dev,__file_bdev($file)) |
| 172 |
|
| 173 |
if (devname!="N/A") { /*skip update cache*/ |
| 174 |
io_stat[pid(),execname(),uid(),ppid(),"W"] += $return |
| 175 |
device[pid(),execname(),uid(),ppid(),"W"] = devname |
| 176 |
write_bytes += $return |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
probe timer.ms(5000) { |
| 182 |
/* skip non-read/write disk */ |
| 183 |
if (read_bytes+write_bytes) { |
| 184 |
|
| 185 |
printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",ctime(gettimeofday_s()),"Average:", |
| 186 |
((read_bytes+write_bytes)/1024)/5,"Read:",read_bytes/1024,"Write:",write_bytes/1024) |
| 187 |
|
| 188 |
/* print header */ |
| 189 |
printf("%8s %8s %8s %25s %8s %4s %12s\n","UID","PID","PPID","CMD","DEVICE","T","BYTES") |
| 190 |
} |
| 191 |
/* print top ten I/O */ |
| 192 |
foreach ([process,cmd,userid,parent,action] in io_stat- limit 10) |
| 193 |
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]) |
| 194 |
|
| 195 |
/* clear data */ |
| 196 |
delete io_stat |
| 197 |
delete device |
| 198 |
read_bytes = 0 |
| 199 |
write_bytes = 0 |
| 200 |
} |
| 201 |
|
| 202 |
probe end{ |
| 203 |
delete io_stat |
| 204 |
delete device |
| 205 |
delete read_bytes |
| 206 |
delete write_bytes |
| 207 |
}</programlisting> |
| 208 |
--> |
| 209 |
|
| 210 |
</section> |
| 211 |
|