summaryrefslogtreecommitdiffstats
path: root/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-traceio.xml
blob: d3e04eff705828595a74f98912d39ddd633d801a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version='1.0'?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
]>

	<section id="traceiosect">
		<title>Track Cumulative IO</title>
<indexterm>
<primary>script examples</primary>
<secondary>tracking cumulative I/O</secondary>
</indexterm>

<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>tracking cumulative I/O</secondary>
</indexterm>

<indexterm>
<primary>tracking cumulative I/O</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>		
		
<indexterm>
<primary>cumulative I/O, tracking</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>
		
<indexterm>
<primary>monitoring cumulative I/O</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>

<indexterm>
<primary>printing I/O activity (cumulative)</primary>
<secondary>examples of SystemTap scripts</secondary>
</indexterm>

		<para>
			This section describes how to track the cumulative amount of I/O to the system.
		</para>
		
<formalpara id="traceio">
	<title>traceio.stp</title>
<para>
<programlisting>
<xi:include parse="text" href="../testsuite/systemtap.examples/io/traceio.stp" xmlns:xi="http://www.w3.org/2001/XInclude" />
</programlisting>
</para>
</formalpara>
<!--
<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>-->

<para>
	<xref linkend="traceio"/> prints the top ten executables generating I/O traffic over time. In
	addition, it also tracks the cumulative amount of I/O reads and writes done by those ten 
	executables. This information is tracked and printed out in 1-second intervals, and in 
	descending order.
</para>
<!-- next 3 indexterms for $return -->
<indexterm>
	<primary>local variables</primary>
	<secondary>sample usage</secondary>
	<tertiary>$return</tertiary>
</indexterm>

<indexterm>
	<primary>variables (local)</primary>
	<secondary>sample usage</secondary>
	<tertiary>$return</tertiary>
</indexterm>

<indexterm>
	<primary>$return</primary>
	<secondary>sample usage</secondary>
	<tertiary>local variables</tertiary>
</indexterm>
<para>
	Note that <xref linkend="traceio"/> also uses the local variable <command>$return</command>,
	which is also used by <xref linkend="scriptdisktop"/> from <xref linkend="disktop"/>.
</para>

<!--<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>-->

<example id="traceiooutput">
	<title><xref linkend="traceio"/> Sample Output</title>
<screen>
[...]
           Xorg r:   583401 KiB w:        0 KiB
       floaters r:       96 KiB w:     7130 KiB
multiload-apple r:      538 KiB w:      537 KiB
           sshd r:       71 KiB w:       72 KiB
pam_timestamp_c r:      138 KiB w:        0 KiB
        staprun r:       51 KiB w:       51 KiB
          snmpd r:       46 KiB w:        0 KiB
          pcscd r:       28 KiB w:        0 KiB
     irqbalance r:       27 KiB w:        4 KiB
          cupsd r:        4 KiB w:       18 KiB

           Xorg r:   588140 KiB w:        0 KiB
       floaters r:       97 KiB w:     7143 KiB
multiload-apple r:      543 KiB w:      542 KiB
           sshd r:       72 KiB w:       72 KiB
pam_timestamp_c r:      138 KiB w:        0 KiB
        staprun r:       51 KiB w:       51 KiB
          snmpd r:       46 KiB w:        0 KiB
          pcscd r:       28 KiB w:        0 KiB
     irqbalance r:       27 KiB w:        4 KiB
          cupsd r:        4 KiB w:       18 KiB
</screen>
</example>		
<!--	
global reads, writes, total_io

probe kernel.function("vfs_read").return {
reads[execname()] += $return
}

probe kernel.function("vfs_write").return {
writes[execname()] += $return
}

probe timer.s(1) {
foreach (p in reads)
total_io[p] += reads[p]
foreach (p in writes)
total_io[p] += writes[p]
foreach(p in total_io- limit 10)
printf("%15s r: %8d KiB w: %8d KiB\n",
p, reads[p]/1024,
writes[p]/1024)
printf("\n")
# Note we don't zero out reads, writes and total_io,
# so the values are cumulative since the script started.
}-->

</section>