Debian Codegraph @

doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-inodewatch.xml

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
3 ]>
4
5
6 <section id="inodewatchsect">
7 <title>Monitoring Reads and Writes to a File</title>
8
9 <indexterm>
10 <primary>script examples</primary>
11 <secondary>monitoring reads and writes to a file</secondary>
12 </indexterm>
13
14 <indexterm>
15 <primary>examples of SystemTap scripts</primary>
16 <secondary>monitoring reads and writes to a file</secondary>
17 </indexterm>
18
19 <indexterm>
20 <primary>monitoring reads and writes to a file</primary>
21 <secondary>examples of SystemTap scripts</secondary>
22 </indexterm>
23
24 <indexterm>
25 <primary>file reads/writes, monitoring</primary>
26 <secondary>examples of SystemTap scripts</secondary>
27 </indexterm>
28
29 <indexterm>
30 <primary>reads/writes to a file, monitoring</primary>
31 <secondary>examples of SystemTap scripts</secondary>
32 </indexterm>
33
34 <indexterm>
35 <primary>writes/reads to a file, monitoring</primary>
36 <secondary>examples of SystemTap scripts</secondary>
37 </indexterm>
38
39 <remark>
40 WAR STORY: monitoring inode activity http://sourceware.org/systemtap/wiki/WSFileMonitor?highlight=((WarStories))
41 </remark>
42
43 <remark>
44 no script in examples
45 </remark>
46
47
48 <para>This section describes how to monitor reads from and writes to a file in real time. </para>
49
50 <formalpara id="inodewatch">
51 <title>inodewatch.stp</title>
52 <para>
53 <programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/io/inodewatch.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
54 </para>
55 </formalpara>
56
57 <remark>need to add references to sources/man pages that explain how "dev_nr = $file->f_dentry->d_inode->i_sb->s_dev" and "($1 &lt;&lt; 20 | $2)".</remark>
58
59
60 <para><xref linkend="inodewatch"/> takes the following information about the
61 file as arguments on the command line:</para>
62 <indexterm>
63 <primary>script examples</primary>
64 <secondary>file device number (integer format)</secondary>
65 </indexterm>
66
67 <indexterm>
68 <primary>examples of SystemTap scripts</primary>
69 <secondary>file device number (integer format)</secondary>
70 </indexterm>
71
72 <indexterm>
73 <primary>file device number (integer format)</primary>
74 <secondary>examples of SystemTap scripts</secondary>
75 </indexterm>
76
77 <indexterm>
78 <primary>device number of a file (integer format)</primary>
79 <secondary>examples of SystemTap scripts</secondary>
80 </indexterm>
81
82 <itemizedlist>
83 <listitem><para>The file's major device number.</para></listitem>
84
85 <listitem><para>The file's minor device number.</para></listitem>
86
87 <listitem><para>The file's <command>inode</command> number.</para></listitem>
88 </itemizedlist>
89 <indexterm>
90 <primary>script examples</primary>
91 <secondary>stat -c, determining file device number (integer format)</secondary>
92 </indexterm>
93
94 <indexterm>
95 <primary>examples of SystemTap scripts</primary>
96 <secondary>stat -c, determining file device number (integer format)</secondary>
97 </indexterm>
98
99 <indexterm>
100 <primary>stat -c, determining file device number (integer format)</primary>
101 <secondary>examples of SystemTap scripts</secondary>
102 </indexterm>
103 <para>To get this information, use <command>stat -c '%D %i' <replaceable>filename</replaceable></command>, where <command><replaceable>filename</replaceable></command> is an absolute path.</para>
104
105 <para>For instance: to monitor <filename>/etc/crontab</filename>, run <command>stat -c '%D %i' /etc/crontab</command> first. This gives the following output:</para>
106
107 <screen>805 1078319</screen>
108 <indexterm>
109 <primary>script examples</primary>
110 <secondary>inode number</secondary>
111 </indexterm>
112
113 <indexterm>
114 <primary>examples of SystemTap scripts</primary>
115 <secondary>inode number</secondary>
116 </indexterm>
117
118 <indexterm>
119 <primary>inode number</primary>
120 <secondary>examples of SystemTap scripts</secondary>
121 </indexterm>
122
123 <para><computeroutput>805</computeroutput> is the base-16 (hexadecimal) device number. The lower two digits are the minor device number and the upper digits are the major number. <computeroutput>1078319</computeroutput> is the <command>inode</command> number. To start monitoring <filename>/etc/crontab</filename>, run <command>stap inodewatch.stp 0x8 0x05 1078319</command> (The <command>0x</command> prefixes indicate base-16 values.</para>
124
125 <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, <command>vfs_read</command> or <command>vfs_write</command>), the device number (in hex format), and the <command>inode</command> number. <xref linkend="inodewatchoutput"/> contains the output of <command>stap inodewatch.stp 0x8 0x05 1078319</command> (when <command>cat /etc/crontab</command> is executed while the script is running) :</para>
126
127
128 <example id="inodewatchoutput">
129 <title><xref linkend="inodewatch"/> Sample Output</title>
130 <screen>cat(16437) vfs_read 0x800005/1078319
131 cat(16437) vfs_read 0x800005/1078319</screen>
132 </example>
133
134 <!--
135 probe kernel.function ("vfs_write"),
136 kernel.function ("vfs_read")
137 {
138 dev_nr = $file->f_dentry->d_inode->i_sb->s_dev
139 inode_nr = $file->f_dentry->d_inode->i_ino
140
141 if (dev_nr == ($1 &lt;&lt; 20 | $2) # major/minor device
142 &amp;&amp; inode_nr == $3)
143 printf ("%s(%d) %s 0x%x/%u\n",
144 execname(), pid(), probefunc(), dev_nr, inode_nr)
145 }
146
147 -->
148
149 </section>
150