Debian Codegraph @

doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-traceio.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="traceiosect">
6 <title>Track Cumulative IO</title>
7 <indexterm>
8 <primary>script examples</primary>
9 <secondary>tracking cumulative I/O</secondary>
10 </indexterm>
11
12 <indexterm>
13 <primary>examples of SystemTap scripts</primary>
14 <secondary>tracking cumulative I/O</secondary>
15 </indexterm>
16
17 <indexterm>
18 <primary>tracking cumulative I/O</primary>
19 <secondary>examples of SystemTap scripts</secondary>
20 </indexterm>
21
22 <indexterm>
23 <primary>cumulative I/O, tracking</primary>
24 <secondary>examples of SystemTap scripts</secondary>
25 </indexterm>
26
27 <indexterm>
28 <primary>monitoring cumulative I/O</primary>
29 <secondary>examples of SystemTap scripts</secondary>
30 </indexterm>
31
32 <indexterm>
33 <primary>printing I/O activity (cumulative)</primary>
34 <secondary>examples of SystemTap scripts</secondary>
35 </indexterm>
36
37 <para>
38 This section describes how to track the cumulative amount of I/O to the system.
39 </para>
40
41 <formalpara id="traceio">
42 <title>traceio.stp</title>
43 <para>
44 <programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/io/traceio.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
45 </para>
46 </formalpara>
47 <!--
48 <remark>what do $return, $length, and $count return, specifically? when i substituted $return for $length here, script still ran but gave me bigger numbers. errored out with $length. where documented?</remark>-->
49
50 <para>
51 <xref linkend="traceio"/> prints the top ten executables generating I/O traffic over time. In
52 addition, it also tracks the cumulative amount of I/O reads and writes done by those ten
53 executables. This information is tracked and printed out in 1-second intervals, and in
54 descending order.
55 </para>
56 <!-- next 3 indexterms for $return -->
57 <indexterm>
58 <primary>local variables</primary>
59 <secondary>sample usage</secondary>
60 <tertiary>$return</tertiary>
61 </indexterm>
62
63 <indexterm>
64 <primary>variables (local)</primary>
65 <secondary>sample usage</secondary>
66 <tertiary>$return</tertiary>
67 </indexterm>
68
69 <indexterm>
70 <primary>$return</primary>
71 <secondary>sample usage</secondary>
72 <tertiary>local variables</tertiary>
73 </indexterm>
74 <para>
75 Note that <xref linkend="traceio"/> also uses the local variable <command>$return</command>,
76 which is also used by <xref linkend="scriptdisktop"/> from <xref linkend="disktop"/>.
77 </para>
78
79 <!--<para><xref linkend="traceio"/> is similar to <xref linkend="iotop"/> (from <xref linkend="iotopsect"/>); both SystemTap scripts print out the top ten executables generating I/O traffic over time. However, <xref linkend="traceio"/> tracks the <emphasis>cumulative</emphasis> amount of I/O reads and writes done by the system's top ten executables. This information is tracked and printed out in 1-second intervals and in descending order.</para>-->
80
81 <example id="traceiooutput">
82 <title><xref linkend="traceio"/> Sample Output</title>
83 <screen>[...]
84 Xorg r: 583401 KiB w: 0 KiB
85 floaters r: 96 KiB w: 7130 KiB
86 multiload-apple r: 538 KiB w: 537 KiB
87 sshd r: 71 KiB w: 72 KiB
88 pam_timestamp_c r: 138 KiB w: 0 KiB
89 staprun r: 51 KiB w: 51 KiB
90 snmpd r: 46 KiB w: 0 KiB
91 pcscd r: 28 KiB w: 0 KiB
92 irqbalance r: 27 KiB w: 4 KiB
93 cupsd r: 4 KiB w: 18 KiB
94
95 Xorg r: 588140 KiB w: 0 KiB
96 floaters r: 97 KiB w: 7143 KiB
97 multiload-apple r: 543 KiB w: 542 KiB
98 sshd r: 72 KiB w: 72 KiB
99 pam_timestamp_c r: 138 KiB w: 0 KiB
100 staprun r: 51 KiB w: 51 KiB
101 snmpd r: 46 KiB w: 0 KiB
102 pcscd r: 28 KiB w: 0 KiB
103 irqbalance r: 27 KiB w: 4 KiB
104 cupsd r: 4 KiB w: 18 KiB</screen>
105 </example>
106 <!--
107 global reads, writes, total_io
108
109 probe vfs.read.return {
110 if ($return > 0) {
111 reads[pid(),execname()] += $return
112 total_io[pid(),execname()] += $return
113 }
114 }
115
116 probe vfs.write.return {
117 if ($return > 0) {
118 writes[pid(),execname()] += $return
119 total_io[pid(),execname()] += $return
120 }
121 }
122
123 function humanreadable(bytes) {
124 if (bytes > 1024*1024*1024) {
125 return sprintf("%d GiB", bytes/1024/1024/1024)
126 } else if (bytes > 1024*1024) {
127 return sprintf("%d MiB", bytes/1024/1024)
128 } else if (bytes > 1024) {
129 return sprintf("%d KiB", bytes/1024)
130 } else {
131 return sprintf("%d B", bytes)
132 }
133 }
134
135 probe timer.s(1) {
136 foreach([p,e] in total_io- limit 10)
137 printf("%8d %15s r: %12s w: %12s\n",
138 p, e, humanreadable(reads[p,e]),
139 humanreadable(writes[p,e]))
140 printf("\n")
141 # Note we don't zero out reads, writes and total_io,
142 # so the values are cumulative since the script started.
143 }
144 -->
145
146 </section>
147
148