summaryrefslogtreecommitdiffstats
path: root/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml
blob: 781ea949ba37306e85fc8f25d60bb0584b49706f (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?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="disktop">
		<title>Summarizing Disk Read/Write Traffic</title>
<indexterm>
<primary>script examples</primary>
<secondary>summarizing disk I/O traffic</secondary>
</indexterm>

<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>summarizing disk I/O traffic</secondary>
</indexterm>

<indexterm>
<primary>summarizing disk I/O traffic</primary>
<secondary>script examples</secondary>
</indexterm>		
		
		<remark>
			NO ENTRY IN WAR STORIES: Summarize Disk Read/Write Traffic
			http://sourceware.org/systemtap/examples/io/disktop.stp
		</remark>

<indexterm>
<primary>disk I/O traffic, summarizing</primary>
<secondary>script examples</secondary>
</indexterm>
<!-- next 2 indexterms for I/O traffic, summarizing -->

<indexterm>
<primary>I/O traffic, summarizing</primary>
<secondary>script examples</secondary>
</indexterm>

<!-- next 2 indexterms for heaviest disk reads/writes, identifying -->

<indexterm>
<primary>heaviest disk reads/writes, identifying</primary>
<secondary>script examples</secondary>
</indexterm>


<!-- next 2 indexterms for summarizing disk I/O traffic -->

<indexterm>
<primary>summarizing disk I/O traffic</primary>
<secondary>script examples</secondary>
</indexterm>


<!-- next 2 indexterms for identifying heaviest disk reads/writes -->

<indexterm>
<primary>identifying heaviest disk reads/writes</primary>
<secondary>script examples</secondary>
</indexterm>
	
	<para>This section describes how to identify which processes are performing the heaviest disk reads/writes to the system.</para>
	
<formalpara id="scriptdisktop">
	<title>disktop.stp</title>
<para>
<programlisting>
<xi:include parse="text" href="../testsuite/systemtap.examples/io/disktop.stp" xmlns:xi="http://www.w3.org/2001/XInclude" />
</programlisting>
</para>
</formalpara>		

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

<itemizedlist>
	<listitem><para><computeroutput>UID</computeroutput> &mdash; user ID. A user ID of <computeroutput>0</computeroutput> refers to the root user.</para></listitem>
	
	<listitem><para><computeroutput>PID</computeroutput> &mdash; the ID of the listed process.</para></listitem>
	
	<listitem><para><computeroutput>PPID</computeroutput> &mdash; the process ID of the listed process's <emphasis>parent process</emphasis>.</para></listitem>
	
	<listitem><para><computeroutput>CMD</computeroutput> &mdash; the name of the listed process.</para></listitem>
	
	<listitem><para><computeroutput>DEVICE</computeroutput> &mdash; which storage device the listed process is reading from or writing to.</para></listitem>
	
	<listitem><para><computeroutput>T</computeroutput> &mdash; the type of action performed by the listed process; <computeroutput>W</computeroutput> refers to write, while <computeroutput>R</computeroutput> refers to read.</para></listitem>
	
	<listitem><para><computeroutput>BYTES</computeroutput> &mdash; the amount of data read to or written from disk.</para></listitem>
</itemizedlist>	
<!-- next 2 indexterms for ctime(), example of usage -->

<indexterm>
<primary>script examples</primary>
<secondary>ctime(), example of usage</secondary>
</indexterm>

<indexterm>
<primary>examples of SystemTap scripts</primary>
<secondary>ctime(), example of usage</secondary>
</indexterm>

<indexterm>
<primary>ctime(), example of usage</primary>
<secondary>script examples</secondary>
</indexterm>


	
<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>
<!-- 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>
	In this script, the <command>$return</command> is a local variable that stores the
	actual number of bytes each process reads or writes from the virtual file system. 
	<command>$return</command> can only be used in return probes (e.g. 
	<command>vfs.read.return</command> and <command>vfs.read.return</command>).
</para>
	
<!--<remark>needinfo: what does $return do?</remark> 	-->
<example id="disktopoutput">
	<title><xref linkend="scriptdisktop"/> Sample Output</title>
<screen>
[...]
Mon Sep 29 03:38:28 2008 , Average:  19Kb/sec, Read: 7Kb, Write: 89Kb

UID      PID     PPID                       CMD   DEVICE    T    BYTES
0    26319    26294                   firefox     sda5    W        90229
0     2758     2757           pam_timestamp_c     sda5    R         8064
0     2885        1                     cupsd     sda5    W         1678

Mon Sep 29 03:38:38 2008 , Average:   1Kb/sec, Read: 7Kb, Write: 1Kb

UID      PID     PPID                       CMD   DEVICE    T    BYTES
0     2758     2757           pam_timestamp_c     sda5    R         8064
0     2885        1                     cupsd     sda5    W         1678
</screen>
</example>

<!--
<programlisting>
global io_stat,device
global read_bytes,write_bytes

probe kernel.function("vfs_read").return {
	if ($return>0) {
		dev = __file_dev($file)
		devname = __find_bdevname(dev,__file_bdev($file))

		if (devname!="N/A") {/*skip read from cache*/
			io_stat[pid(),execname(),uid(),ppid(),"R"] += $return
			device[pid(),execname(),uid(),ppid(),"R"] = devname
			read_bytes += $return
		}
	}
}

probe kernel.function("vfs_write").return {
	if ($return>0) {
		dev = __file_dev($file)
		devname = __find_bdevname(dev,__file_bdev($file))

		if (devname!="N/A") { /*skip update cache*/
			io_stat[pid(),execname(),uid(),ppid(),"W"] += $return
			device[pid(),execname(),uid(),ppid(),"W"] = devname
			write_bytes += $return
		}
	}
}

probe timer.ms(5000) {
	/* skip non-read/write disk */
	if (read_bytes+write_bytes) {

		printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",ctime(gettimeofday_s()),"Average:",
      		((read_bytes+write_bytes)/1024)/5,"Read:",read_bytes/1024,"Write:",write_bytes/1024)

		/* print header */
		printf("%8s %8s %8s %25s %8s %4s %12s\n","UID","PID","PPID","CMD","DEVICE","T","BYTES")
	}
	/* print top ten I/O */
	foreach ([process,cmd,userid,parent,action] in io_stat- limit 10)
	  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])

	/* clear data */
	delete io_stat
	delete device
	read_bytes = 0
	write_bytes = 0	
}

probe end{
	delete io_stat
	delete device
	delete read_bytes
	delete write_bytes	
}
</programlisting>
-->

	</section>