Sophie

Sophie

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

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.5. Monitoring Reads and Writes to a File</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="mainsect-disk.html" title="4.2. Disk" /><link rel="prev" href="traceio2sect.html" title="4.2.4. I/O Monitoring (By Device)" /><link rel="next" href="inodewatch2sect.html" title="4.2.6. Monitoring Changes to File Attributes" /></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="traceio2sect.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="inodewatch2sect.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" title="4.2.5. Monitoring Reads and Writes to a File" lang="en-US"><div class="titlepage"><div><div><h3 class="title" id="inodewatchsect">4.2.5. Monitoring Reads and Writes to a File</h3></div></div></div><a id="id2794501" class="indexterm"></a><a id="id3033111" class="indexterm"></a><a id="id3084087" class="indexterm"></a><a id="id3052193" class="indexterm"></a><a id="id3090845" class="indexterm"></a><a id="id3091445" class="indexterm"></a><div class="para">
		This section describes how to monitor reads from and writes to a file in real time.
	</div><div class="formalpara"><h5 class="formalpara" id="inodewatch">inodewatch-simple.stp</h5>
			
<pre class="programlisting">
probe vfs.write, vfs.read&#13;
{&#13;
  dev_nr = $file-&gt;f_dentry-&gt;d_inode-&gt;i_sb-&gt;s_dev&#13;
  inode_nr = $file-&gt;f_dentry-&gt;d_inode-&gt;i_ino&#13;
  if (dev_nr == ($1 &lt;&lt; 20 | $2) # major/minor device&#13;
      &amp;&amp; inode_nr == $3)&#13;
    printf ("%s(%d) %s 0x%x/%u\n",&#13;
      execname(), pid(), probefunc(), dev_nr, inode_nr)&#13;
}&#13;

</pre>
		</div><div class="para">
		<a class="xref" href="inodewatchsect.html#inodewatch" title="inodewatch-simple.stp">inodewatch-simple.stp</a> takes the following information about the file as arguments on the command line:
	</div><a id="id2948788" class="indexterm"></a><a id="id2999003" class="indexterm"></a><a id="id2720696" class="indexterm"></a><a id="id3031022" class="indexterm"></a><div class="itemizedlist"><ul><li class="listitem"><div class="para">
				The file's major device number.
			</div></li><li class="listitem"><div class="para">
				The file's minor device number.
			</div></li><li class="listitem"><div class="para">
				The file's <code class="command">inode</code> number.
			</div></li></ul></div><a id="id3090402" class="indexterm"></a><a id="id2843748" class="indexterm"></a><a id="id2892866" class="indexterm"></a><div class="para">
		To get this information, use <code class="command">stat -c '%D %i' <em class="replaceable"><code>filename</code></em></code>, where <code class="command"><em class="replaceable"><code>filename</code></em></code> is an absolute path.
	</div><div class="para">
		For instance: if you wish to monitor <code class="filename">/etc/crontab</code>, run <code class="command">stat -c '%D %i' /etc/crontab</code> first. This gives the following output:
	</div><pre class="screen">
805 1078319
</pre><a id="id2736778" class="indexterm"></a><a id="id2751633" class="indexterm"></a><a id="id4363701" class="indexterm"></a><div class="para">
		<code class="computeroutput">805</code> is the base-16 (hexadecimal) device number. The lower two digits are the minor device number and the upper digits are the major number. <code class="computeroutput">1078319</code> is the <code class="command">inode</code> number. To start monitoring <code class="filename">/etc/crontab</code>, run <code class="command">stap inodewatch.stp 0x8 0x05 1078319</code> (The <code class="command">0x</code> prefixes indicate base-16 values.
	</div><div class="para">
		The output of this command contains the name and ID of any process performing a read/write, the function it is performing (i.e. <code class="command">vfs_read</code> or <code class="command">vfs_write</code>), the device number (in hex format), and the <code class="command">inode</code> number. <a class="xref" href="inodewatchsect.html#inodewatchoutput" title="Example 4.10. inodewatch-simple.stp Sample Output">Example 4.10, “inodewatch-simple.stp Sample Output”</a> contains the output of <code class="command">stap inodewatch.stp 0x8 0x05 1078319</code> (when <code class="command">cat /etc/crontab</code> is executed while the script is running) :
	</div><div class="example" id="inodewatchoutput"><div class="example-contents"><pre class="screen">
cat(16437) vfs_read 0x800005/1078319
cat(16437) vfs_read 0x800005/1078319
</pre></div><h6>Example 4.10. <a class="xref" href="inodewatchsect.html#inodewatch" title="inodewatch-simple.stp">inodewatch-simple.stp</a> Sample Output</h6></div><br class="example-break" /></div><ul class="docnav"><li class="previous"><a accesskey="p" href="traceio2sect.html"><strong>Prev</strong>4.2.4. I/O Monitoring (By Device)</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="inodewatch2sect.html"><strong>Next</strong>4.2.6. Monitoring Changes to File Attributes</a></li></ul></body></html>