Debian Codegraph @

doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-iotime.xml

raw
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 <section id="iotimesect">
6 <title>Tracking I/O Time For Each File Read or Write</title>
7 <indexterm>
8 <primary>script examples</primary>
9 <secondary>monitoring I/O time</secondary>
10 </indexterm>
11
12 <indexterm>
13 <primary>examples of SystemTap scripts</primary>
14 <secondary>monitoring I/O time</secondary>
15 </indexterm>
16
17 <indexterm>
18 <primary>monitoring I/O time</primary>
19 <secondary>examples of SystemTap scripts</secondary>
20 </indexterm>
21
22 <indexterm>
23 <primary>I/O time, monitoring</primary>
24 <secondary>examples of SystemTap scripts</secondary>
25 </indexterm>
26
27 <indexterm>
28 <primary>time of I/O </primary>
29 <secondary>examples of SystemTap scripts</secondary>
30 </indexterm>
31
32 <!-- <para>This section describes how to monitor I/O time on the system.</para> -->
33
34 <para>
35 This section describes how to monitor the amount of time it takes for each process to read
36 from or write to any file. This is useful to determine what files are slow to
37 load on a given system.
38 </para>
39
40 <formalpara id="iotime">
41 <title>iotime.stp</title>
42 <para>
43 <programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/io/iotime.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
44 </para>
45 </formalpara>
46
47 <para>
48 <xref linkend="iotime"/> tracks each time a system call opens, closes, reads from, and writes
49 to a file. For each file any system call accesses, <xref linkend="iotime"/> counts the number
50 of microseconds it takes for any reads or writes to finish and tracks the amount of data (in
51 bytes) read from or written to the file.
52 </para>
53 <!-- next 2 indexterms for $count -->
54
55 <indexterm>
56 <primary>local variables</primary>
57 <secondary>sample usage</secondary>
58 <tertiary>$count</tertiary>
59 </indexterm>
60
61 <indexterm>
62 <primary>variables (local)</primary>
63 <secondary>sample usage</secondary>
64 <tertiary>$count</tertiary>
65 </indexterm>
66
67 <indexterm>
68 <primary>$count</primary>
69 <secondary>sample usage</secondary>
70 <tertiary>local variables</tertiary>
71 </indexterm>
72
73
74 <para>
75 <xref linkend="iotime"/> also uses the local variable <command>$count</command> to track the
76 amount of data (in bytes) that any system call <emphasis>attempts</emphasis> to read or
77 write. Note that <command>$return</command> (as used in <xref linkend="scriptdisktop"/> from
78 <xref linkend= "disktop"/>) stores the <emphasis>actual</emphasis> amount of data
79 read/written. <command>$count</command> can only be used on probes that track data reads or
80 writes (that is, <command>syscall.read</command> and <command>syscall.write</command>).
81 </para>
82
83 <!--<remark>what does $count do, specifically?</remark>-->
84
85 <example id="iotimeoutput">
86 <title><xref linkend="iotime"/> Sample Output</title>
87 <screen>[...]
88 825946 3364 (NetworkManager) access /sys/class/net/eth0/carrier read: 8190 write: 0
89 825955 3364 (NetworkManager) iotime /sys/class/net/eth0/carrier time: 9
90 [...]
91 117061 2460 (pcscd) access /dev/bus/usb/003/001 read: 43 write: 0
92 117065 2460 (pcscd) iotime /dev/bus/usb/003/001 time: 7
93 [...]
94 3973737 2886 (sendmail) access /proc/loadavg read: 4096 write: 0
95 3973744 2886 (sendmail) iotime /proc/loadavg time: 11
96 [...]</screen>
97 </example>
98
99 <para>
100 <xref linkend="iotimeoutput"/> prints out the following data:
101 </para>
102
103 <itemizedlist>
104 <listitem><para>A timestamp, in microseconds.</para></listitem>
105 <listitem><para>Process ID and process name.</para></listitem>
106 <listitem><para>An <computeroutput>access</computeroutput> or
107 <computeroutput>iotime</computeroutput> flag.</para></listitem>
108 <listitem><para>The file accessed.</para></listitem>
109 </itemizedlist>
110
111 <para>
112 If a process was able to read or write any data, a pair of
113 <computeroutput>access</computeroutput> and <computeroutput>iotime</computeroutput> lines
114 should appear together. The <computeroutput>access</computeroutput> line's timestamp refers to
115 the time that a given process started accessing a file; at the end of the line, it will show
116 the amount of data read/written (in bytes). The <computeroutput>iotime</computeroutput> line
117 will show the amount of time (in microseconds) that the process took in order to perform the
118 read or write.
119 </para>
120
121 <para>
122 If an <computeroutput>access</computeroutput> line is not followed by an
123 <computeroutput>iotime</computeroutput> line, it means that the process did not read
124 or write any data.
125 </para>
126
127 <!--
128 <para><xref linkend="iotopoutput"/> displays top I/O writes and reads within a random 10-second interval. Note that <xref linkend="iotop"/> also detects I/O resulting from SystemTap activity &mdash; <xref linkend="iotopoutput"/> displays reads done by <command>staprun</command>.</para>-->
129 <!--
130 global reads, writes, total_io
131
132 probe kernel.function("vfs_read") {
133 reads[execname()] += $count
134 }
135
136 probe kernel.function("vfs_write") {
137 writes[execname()] += $count
138 }
139
140 # print top 10 IO processes every 5 seconds
141 probe timer.s(5) {
142 foreach (name in writes)
143 total_io[name] += writes[name]
144 foreach (name in reads)
145 total_io[name] += reads[name]
146 printf ("%16s\t%10s\t%10s\n", "Process", "KB Read", "KB Written")
147 foreach (name in total_io- limit 10)
148 printf("%16s\t%10d\t%10d\n", name,
149 reads[name]/1024, writes[name]/1024)
150 delete reads
151 delete writes
152 delete total_io
153 print("\n")
154 }
155 -->
156
157 </section>