| 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 |
<section id="traceio2sect"> |
| 6 |
<title>I/O Monitoring (By Device)</title> |
| 7 |
<indexterm> |
| 8 |
<primary>script examples</primary> |
| 9 |
<secondary>monitoring device I/O</secondary> |
| 10 |
</indexterm> |
| 11 |
|
| 12 |
<indexterm> |
| 13 |
<primary>examples of SystemTap scripts</primary> |
| 14 |
<secondary>monitoring device I/O</secondary> |
| 15 |
</indexterm> |
| 16 |
|
| 17 |
<indexterm> |
| 18 |
<primary>monitoring device I/O</primary> |
| 19 |
<secondary>examples of SystemTap scripts</secondary> |
| 20 |
</indexterm> |
| 21 |
|
| 22 |
<indexterm> |
| 23 |
<primary>I/O monitoring (by device)</primary> |
| 24 |
<secondary>examples of SystemTap scripts</secondary> |
| 25 |
</indexterm> |
| 26 |
|
| 27 |
<indexterm> |
| 28 |
<primary>device I/O, monitoring</primary> |
| 29 |
<secondary>examples of SystemTap scripts</secondary> |
| 30 |
</indexterm> |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
<remark> |
| 37 |
example from http://sourceware.org/systemtap/examples/io/traceio2.stp, but error |
| 38 |
</remark> |
| 39 |
|
| 40 |
<remark> |
| 41 |
WAR STORY: http://sourceware.org/systemtap/wiki/WSDeviceMonitor?highlight=((WarStories)), but script errored |
| 42 |
</remark> |
| 43 |
|
| 44 |
<remark> |
| 45 |
was able to correct script through http://sourceware.org/systemtap/wiki/WSFileMonitor?highlight=((WarStories)) |
| 46 |
</remark> |
| 47 |
|
| 48 |
<para> |
| 49 |
This section describes how to monitor I/O activity on a specific device. |
| 50 |
</para> |
| 51 |
|
| 52 |
<formalpara id="traceio2"> |
| 53 |
<title>traceio2.stp</title> |
| 54 |
<para> |
| 55 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/io/traceio2.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 56 |
</para> |
| 57 |
</formalpara> |
| 58 |
|
| 59 |
<!-- <remark>in new SystemTap, returned a warning, but ran ok.</remark> |
| 60 |
|
| 61 |
<para condition="fedora">For some kernel versions (for example, <filename>2.6.21-1.3194.fc7</filename>), you may need to revise <xref linkend="traceio2"/> accordingly. SystemTap will output the following error if you need to do so:</para> |
| 62 |
|
| 63 |
<screen condition="fedora"> |
| 64 |
semantic error: field 'f_dentry' not found</screen> |
| 65 |
|
| 66 |
<para condition="fedora">If this is the case, revise <xref linkend="traceio2"/> by deleting the following lines in the script:</para> |
| 67 |
|
| 68 |
<programlisting condition="fedora"> |
| 69 |
dev_nr = $file->f_dentry->d_inode->i_sb->s_dev |
| 70 |
inode_nr = $file->f_dentry->d_inode->i_ino</programlisting> |
| 71 |
|
| 72 |
<para condition="fedora">Replace those lines with:</para> |
| 73 |
|
| 74 |
<programlisting condition="fedora"> |
| 75 |
dev_nr = $file->f_path->dentry->d_inode->i_sb->s_dev |
| 76 |
inode_nr = $file->f_path->dentry->d_inode->i_ino |
| 77 |
</programlisting>--> |
| 78 |
<indexterm> |
| 79 |
<primary>script examples</primary> |
| 80 |
<secondary>stat -c, determining whole device number</secondary> |
| 81 |
</indexterm> |
| 82 |
|
| 83 |
<indexterm> |
| 84 |
<primary>examples of SystemTap scripts</primary> |
| 85 |
<secondary>stat -c, determining whole device number</secondary> |
| 86 |
</indexterm> |
| 87 |
|
| 88 |
<indexterm> |
| 89 |
<primary>stat -c, determining whole device number</primary> |
| 90 |
<secondary>examples of SystemTap scripts</secondary> |
| 91 |
</indexterm> |
| 92 |
|
| 93 |
<indexterm> |
| 94 |
<primary>script examples</primary> |
| 95 |
<secondary>whole device number (usage as a command-line argument)</secondary> |
| 96 |
</indexterm> |
| 97 |
|
| 98 |
<indexterm> |
| 99 |
<primary>examples of SystemTap scripts</primary> |
| 100 |
<secondary>whole device number (usage as a command-line argument)</secondary> |
| 101 |
</indexterm> |
| 102 |
|
| 103 |
<indexterm> |
| 104 |
<primary>whole device number (usage as a command-line argument)</primary> |
| 105 |
<secondary>examples of SystemTap scripts</secondary> |
| 106 |
</indexterm> |
| 107 |
<para><xref linkend="traceio2"/> takes 1 argument: the whole device number. To get this number, use <command>stat -c "0x%D" <replaceable>directory</replaceable></command>, where <command><replaceable>directory</replaceable></command> is located in the device to be monitored.</para> |
| 108 |
<indexterm> |
| 109 |
<primary>script examples</primary> |
| 110 |
<secondary>usrdev2kerndev()</secondary> |
| 111 |
</indexterm> |
| 112 |
|
| 113 |
<indexterm> |
| 114 |
<primary>examples of SystemTap scripts</primary> |
| 115 |
<secondary>usrdev2kerndev()</secondary> |
| 116 |
</indexterm> |
| 117 |
|
| 118 |
<indexterm> |
| 119 |
<primary>usrdev2kerndev()</primary> |
| 120 |
<secondary>examples of SystemTap scripts</secondary> |
| 121 |
</indexterm> |
| 122 |
<para>The <command>usrdev2kerndev()</command> function converts the whole device number into the format understood by the kernel. The output produced by <command>usrdev2kerndev()</command> is used in conjunction with the <command>MKDEV()</command>, <command>MINOR()</command>, and <command>MAJOR()</command> functions to determine the major and minor numbers of a specific device.</para> |
| 123 |
|
| 124 |
<para>The output of <xref linkend="traceio2"/> includes 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>), and the kernel device number.</para> |
| 125 |
<!-- |
| 126 |
<remark>please verify if "0x800005" is "device number (in hex format)", and why it needs to be stated buy </remark>--> |
| 127 |
|
| 128 |
<para>The following example is an excerpt from the full output of <command>stap traceio2.stp 0x805</command>, where <literal>0x805</literal> is the whole device number of <filename>/home</filename>. <filename>/home</filename> resides in <filename>/dev/sda5</filename>, which is the device we wish to monitor.</para> |
| 129 |
|
| 130 |
<example id="traceio2output"> |
| 131 |
<title><xref linkend="traceio2"/> Sample Output</title> |
| 132 |
<screen>[...] |
| 133 |
synergyc(3722) vfs_read 0x800005 |
| 134 |
synergyc(3722) vfs_read 0x800005 |
| 135 |
cupsd(2889) vfs_write 0x800005 |
| 136 |
cupsd(2889) vfs_write 0x800005 |
| 137 |
cupsd(2889) vfs_write 0x800005 |
| 138 |
[...]</screen> |
| 139 |
</example> |
| 140 |
<!-- |
| 141 |
probe kernel.function ("vfs_write"), |
| 142 |
kernel.function ("vfs_read") |
| 143 |
{ |
| 144 |
dev_nr = $file->f_dentry->d_inode->i_sb->s_dev |
| 145 |
inode_nr = $file->f_dentry->d_inode->i_ino |
| 146 |
if (dev_nr == ($1 << 20 | $2)) |
| 147 |
printf ("%s(%d) %s 0x%x\n", execname(), pid(), probefunc(), dev_nr) |
| 148 |
}--> |
| 149 |
|
| 150 |
|
| 151 |
</section> |
| 152 |
|
| 153 |
|