Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 95299258dbdf9a86cefd89b97c0d81e5 > files > 113

systemtap-1.2-1.fc13.i686.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>4.2. Disk</title><link rel="stylesheet" href="./Common_Content/css/default.css" type="text/css" /><meta name="generator" content="publican 1.6" /><meta name="package" content="Systemtap-SystemTap_Beginners_Guide-1.0-en-US-2.0-2" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="useful-systemtap-scripts.html" title="Chapter 4. Useful SystemTap Scripts" /><link rel="prev" href="useful-systemtap-scripts.html" title="Chapter 4. Useful SystemTap Scripts" /><link rel="next" href="iotimesect.html" title="4.2.2. Tracking I/O Time For Each File Read or Write" /></head><body class=""><p id="title"><a class="left" href="http://www.fedoraproject.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://docs.fedoraproject.org"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="useful-systemtap-scripts.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="iotimesect.html"><strong>Next</strong></a></li></ul><div class="section" title="4.2. Disk"><div class="titlepage"><div><div><h2 class="title" id="mainsect-disk">4.2. Disk</h2></div></div></div><div class="para">
			The following sections showcase scripts that monitor disk and I/O activity.
		</div><div xml:lang="en-US" class="section" title="4.2.1. Summarizing Disk Read/Write Traffic" lang="en-US"><div class="titlepage"><div><div><h3 class="title" id="disktop">4.2.1. Summarizing Disk Read/Write Traffic</h3></div></div></div><a id="id2940183" class="indexterm"></a><a id="id4365517" class="indexterm"></a><a id="id3035781" class="indexterm"></a><a id="id3056420" class="indexterm"></a><a id="id2987712" class="indexterm"></a><a id="id2989707" class="indexterm"></a><a id="id2815294" class="indexterm"></a><a id="id2953140" class="indexterm"></a><div class="para">
		This section describes how to identify which processes are performing the heaviest disk reads/writes to the system.
	</div><div class="formalpara"><h5 class="formalpara" id="scriptdisktop">disktop.stp</h5>
			
<pre class="programlisting">
#!/usr/bin/env stap 
#
# Copyright (C) 2007 Oracle Corp.
#
# Get the status of reading/writing disk every 5 seconds,
# output top ten entries 
#
# This is free software,GNU General Public License (GPL);
# either version 2, or (at your option) any later version.
#
# Usage:
#  ./disktop.stp
#

global io_stat,device
global read_bytes,write_bytes

probe vfs.read.return {
  if ($return&gt;0) {
    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 vfs.write.return {
  if ($return&gt;0) {
    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
}

</pre>
		</div><div class="para">
		<a class="xref" href="mainsect-disk.html#scriptdisktop" title="disktop.stp">disktop.stp</a> outputs the top ten processes responsible for the heaviest reads/writes to disk. <a class="xref" href="mainsect-disk.html#disktopoutput" title="Example 4.6. disktop.stp Sample Output">Example 4.6, “disktop.stp Sample Output”</a> displays a sample output for this script, and includes the following data per listed process:
	</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
				<code class="computeroutput">UID</code> — user ID. A user ID of <code class="computeroutput">0</code> refers to the root user.
			</div></li><li class="listitem"><div class="para">
				<code class="computeroutput">PID</code> — the ID of the listed process.
			</div></li><li class="listitem"><div class="para">
				<code class="computeroutput">PPID</code> — the process ID of the listed process's <span class="emphasis"><em>parent process</em></span>.
			</div></li><li class="listitem"><div class="para">
				<code class="computeroutput">CMD</code> — the name of the listed process.
			</div></li><li class="listitem"><div class="para">
				<code class="computeroutput">DEVICE</code> — which storage device the listed process is reading from or writing to.
			</div></li><li class="listitem"><div class="para">
				<code class="computeroutput">T</code> — the type of action performed by the listed process; <code class="computeroutput">W</code> refers to write, while <code class="computeroutput">R</code> refers to read.
			</div></li><li class="listitem"><div class="para">
				<code class="computeroutput">BYTES</code> — the amount of data read to or written from disk.
			</div></li></ul></div><a id="id2843666" class="indexterm"></a><a id="id2714391" class="indexterm"></a><a id="id2739308" class="indexterm"></a><div class="para">
		The time and date in the output of <a class="xref" href="mainsect-disk.html#scriptdisktop" title="disktop.stp">disktop.stp</a> is returned by the functions <code class="command">ctime()</code> and <code class="command">gettimeofday_s()</code>. <code class="command">ctime()</code> derives calendar time in terms of seconds passed since the Unix epoch (January 1, 1970). <code class="command">gettimeofday_s()</code> counts the <span class="emphasis"><em>actual</em></span> number of seconds since Unix epoch, which gives a fairly accurate human-readable timestamp for the output.
	</div><a id="id3093843" class="indexterm"></a><a id="id2753001" class="indexterm"></a><a id="id3424631" class="indexterm"></a><div class="para">
		In this script, the <code class="command">$return</code> is a local variable that stores the actual number of bytes each process reads or writes from the virtual file system. <code class="command">$return</code> can only be used in return probes (e.g. <code class="command">vfs.read.return</code> and <code class="command">vfs.read.return</code>).
	</div><div class="example" id="disktopoutput"><div class="example-contents"><pre class="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
</pre></div><h6>Example 4.6. <a class="xref" href="mainsect-disk.html#scriptdisktop" title="disktop.stp">disktop.stp</a> Sample Output</h6></div><br class="example-break" /></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="useful-systemtap-scripts.html"><strong>Prev</strong>Chapter 4. Useful SystemTap Scripts</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="iotimesect.html"><strong>Next</strong>4.2.2. Tracking I/O Time For Each File Read or Wr...</a></li></ul></body></html>