<?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.3. Track Cumulative IO</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="iotimesect.html" title="4.2.2. Tracking I/O Time For Each File Read or Write" /><link rel="next" href="traceio2sect.html" title="4.2.4. I/O Monitoring (By Device)" /></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="iotimesect.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="traceio2sect.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" title="4.2.3. Track Cumulative IO" lang="en-US"><div class="titlepage"><div><div><h3 class="title" id="traceiosect">4.2.3. Track Cumulative IO</h3></div></div></div><a id="id2746317" class="indexterm"></a><a id="id2750819" class="indexterm"></a><a id="id3008975" class="indexterm"></a><a id="id2848628" class="indexterm"></a><a id="id2773546" class="indexterm"></a><a id="id2838194" class="indexterm"></a><div class="para"> This section describes how to track the cumulative amount of I/O to the system. </div><div class="formalpara"><h5 class="formalpara" id="traceio">traceio.stp</h5> <pre class="programlisting"> #! /usr/bin/env stap # traceio.stp # Copyright (C) 2007 Red Hat, Inc., Eugene Teo <eteo@redhat.com> # Copyright (C) 2009 Kai Meyer <kai@unixlords.com> # Fixed a bug that allows this to run longer # And added the humanreadable function # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # global reads, writes, total_io probe vfs.read.return { reads[pid(),execname()] += $return total_io[pid(),execname()] += $return } probe vfs.write.return { writes[pid(),execname()] += $return total_io[pid(),execname()] += $return } function humanreadable(bytes) { if (bytes > 1024*1024*1024) { return sprintf("%d GiB", bytes/1024/1024/1024) } else if (bytes > 1024*1024) { return sprintf("%d MiB", bytes/1024/1024) } else if (bytes > 1024) { return sprintf("%d KiB", bytes/1024) } else { return sprintf("%d B", bytes) } } probe timer.s(1) { foreach([p,e] in total_io- limit 10) printf("%8d %15s r: %12s w: %12s\n", p, e, humanreadable(reads[p,e]), humanreadable(writes[p,e])) printf("\n") # Note we don't zero out reads, writes and total_io, # so the values are cumulative since the script started. } </pre> </div><div class="para"> <a class="xref" href="traceiosect.html#traceio" title="traceio.stp">traceio.stp</a> prints the top ten executables generating I/O traffic over time. In addition, it also tracks the cumulative amount of I/O reads and writes done by those ten executables. This information is tracked and printed out in 1-second intervals, and in descending order. </div><a id="id2816943" class="indexterm"></a><a id="id3033599" class="indexterm"></a><a id="id3070962" class="indexterm"></a><div class="para"> Note that <a class="xref" href="traceiosect.html#traceio" title="traceio.stp">traceio.stp</a> also uses the local variable <code class="command">$return</code>, which is also used by <a class="xref" href="mainsect-disk.html#scriptdisktop" title="disktop.stp">disktop.stp</a> from <a class="xref" href="mainsect-disk.html#disktop" title="4.2.1. Summarizing Disk Read/Write Traffic">Section 4.2.1, “Summarizing Disk Read/Write Traffic”</a>. </div><div class="example" id="traceiooutput"><div class="example-contents"><pre class="screen"> [...] Xorg r: 583401 KiB w: 0 KiB floaters r: 96 KiB w: 7130 KiB multiload-apple r: 538 KiB w: 537 KiB sshd r: 71 KiB w: 72 KiB pam_timestamp_c r: 138 KiB w: 0 KiB staprun r: 51 KiB w: 51 KiB snmpd r: 46 KiB w: 0 KiB pcscd r: 28 KiB w: 0 KiB irqbalance r: 27 KiB w: 4 KiB cupsd r: 4 KiB w: 18 KiB Xorg r: 588140 KiB w: 0 KiB floaters r: 97 KiB w: 7143 KiB multiload-apple r: 543 KiB w: 542 KiB sshd r: 72 KiB w: 72 KiB pam_timestamp_c r: 138 KiB w: 0 KiB staprun r: 51 KiB w: 51 KiB snmpd r: 46 KiB w: 0 KiB pcscd r: 28 KiB w: 0 KiB irqbalance r: 27 KiB w: 4 KiB cupsd r: 4 KiB w: 18 KiB </pre></div><h6>Example 4.8. <a class="xref" href="traceiosect.html#traceio" title="traceio.stp">traceio.stp</a> Sample Output</h6></div><br class="example-break" /></div><ul class="docnav"><li class="previous"><a accesskey="p" href="iotimesect.html"><strong>Prev</strong>4.2.2. Tracking I/O Time For Each File Read or Wr...</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="traceio2sect.html"><strong>Next</strong>4.2.4. I/O Monitoring (By Device)</a></li></ul></body></html>