summaryrefslogtreecommitdiffstats
path: root/SystemTap_Beginners_Guide/inodewatchsect.html
blob: ff0dd0b86d8268555d0e8eab49d4790a9b93bfb2 (plain) (blame)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 
<?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 xmlns:d="http://docbook.org/ns/docbook">5.2.5. Monitoring Reads and Writes to a File</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta xmlns:d="http://docbook.org/ns/docbook" name="generator" content="not publican" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="mainsect-disk.html" title="5.2. Disk" /><link rel="prev" href="traceio2sect.html" title="5.2.4. I/O Monitoring (By Device)" /><link rel="next" href="inodewatch2sect.html" title="5.2.6. Monitoring Changes to File Attributes" /></head><body><p id="title"></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="traceio2sect.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="inodewatch2sect.html"><strong>Next</strong></a></li></ul><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="inodewatchsect"></a>5.2.5. Monitoring Reads and Writes to a File</h3></div></div></div><a id="idm140174736433200" class="indexterm"></a><a id="idm140174734267088" class="indexterm"></a><a id="idm140174730540736" class="indexterm"></a><a id="idm140174736455216" class="indexterm"></a><a id="idm140174743333408" class="indexterm"></a><a id="idm140174733987456" 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="para"><div xmlns:d="http://docbook.org/ns/docbook" class="title">inodewatch.stp</div> <pre class="programlisting">#! /usr/bin/env stap probe vfs.write, vfs.read { # dev and ino are defined by vfs.write and vfs.read if (dev == MKDEV($1,$2) # major/minor device &amp;&amp; ino == $3) printf ("%s(%d) %s 0x%x/%u\n", execname(), pid(), ppfunc(), dev, ino) } </pre> </div><div class="para"><a class="xref" href="inodewatchsect.html#inodewatch">inodewatch.stp</a> takes the following information about the file as arguments on the command line:</div><a id="idm140174733947984" class="indexterm"></a><a id="idm140174738986352" class="indexterm"></a><a id="idm140174742063584" class="indexterm"></a><a id="idm140174730967552" class="indexterm"></a><div xmlns:d="http://docbook.org/ns/docbook" 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="idm140174740788704" class="indexterm"></a><a id="idm140174731496896" class="indexterm"></a><a id="idm140174731378880" class="indexterm"></a><div class="para">To get this information, use <code class="command">stat -c '%D %i' <em class="replaceable">filename</em></code>, where <code class="command"><em class="replaceable">filename</em></code> is an absolute path.</div><div class="para">For instance: 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="idm140174738380352" class="indexterm"></a><a id="idm140174733120368" class="indexterm"></a><a id="idm140174737442336" 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 (that is, <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">Example 5.10, “inodewatch.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"><a id="inodewatchoutput"></a><p class="title"><strong>Example 5.10<a class="xref" href="inodewatchsect.html#inodewatch">inodewatch.stp</a> Sample Output</strong></p><div class="example-contents"><pre class="screen">cat(16437) vfs_read 0x800005/1078319 cat(16437) vfs_read 0x800005/1078319</pre></div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="traceio2sect.html"><strong>Prev</strong>5.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>5.2.6. Monitoring Changes to File Attributes</a></li></ul></body></html>