<?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>3.5.5. Clearing/Deleting Arrays and Array Elements</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="arrayoperators.html" title="3.5. Array Operations in SystemTap" /><link rel="prev" href="arrayops-foreach.html" title="3.5.4. Processing Multiple Elements in an Array" /><link rel="next" href="arrayops-conditionals.html" title="3.5.6. Using Arrays in Conditional Statements" /></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="arrayops-foreach.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="arrayops-conditionals.html"><strong>Next</strong></a></li></ul><div class="section" title="3.5.5. Clearing/Deleting Arrays and Array Elements"><div class="titlepage"><div><div><h3 class="title" id="arrayops-deleting">3.5.5. Clearing/Deleting Arrays and Array Elements</h3></div></div></div><a id="id3083660" class="indexterm"></a><a id="id2776770" class="indexterm"></a><a id="id2966520" class="indexterm"></a><a id="id3035118" class="indexterm"></a><a id="id2944134" class="indexterm"></a><div class="para"> Sometimes, you may need to clear the associated values in array elements, or reset an entire array for re-use in another probe. <a class="xref" href="arrayops-foreach.html#simplevfsreadprint" title="Example 3.15. cumulative-vfsreads.stp">Example 3.15, “cumulative-vfsreads.stp”</a> in <a class="xref" href="arrayops-foreach.html" title="3.5.4. Processing Multiple Elements in an Array">Section 3.5.4, “Processing Multiple Elements in an Array”</a> allows you to track how the number of VFS reads per process grows over time, but it does not show you the number of VFS reads each process makes per 3-second period. </div><a id="id3058448" class="indexterm"></a><a id="id3424575" class="indexterm"></a><a id="id4361502" class="indexterm"></a><a id="id2756438" class="indexterm"></a><div class="para"> To do that, you will need to clear the values accumulated by the array. You can accomplish this using the <code class="command">delete</code> operator to delete elements in an array, or an entire array. Consider the following example: </div><a id="id3099380" class="indexterm"></a><a id="id3084590" class="indexterm"></a><a id="id2731067" class="indexterm"></a><a id="id3092532" class="indexterm"></a><div class="example" id="simplevfsreadprintnotcumulative"><div class="example-contents"><pre class="programlisting"> global reads probe vfs.read { reads[execname()] ++ } probe timer.s(3) { foreach (count in reads) printf("%s : %d \n", count, reads[count]) delete reads } </pre></div><h6>Example 3.16. noncumulative-vfsreads.stp</h6></div><br class="example-break" /><div class="para"> In <a class="xref" href="arrayops-deleting.html#simplevfsreadprintnotcumulative" title="Example 3.16. noncumulative-vfsreads.stp">Example 3.16, “noncumulative-vfsreads.stp”</a>, the second probe prints the number of VFS reads each process made <span class="emphasis"><em>within the probed 3-second period only</em></span>. The <code class="command">delete reads</code> statement clears the <code class="command">reads</code> array within the probe. </div><div class="note"><h2>Note</h2><a id="id2901231" class="indexterm"></a><a id="id2757190" class="indexterm"></a><a id="id2875678" class="indexterm"></a><a id="id2914028" class="indexterm"></a><div class="para"> You can have multiple array operations within the same probe. Using the examples from <a class="xref" href="arrayops-foreach.html" title="3.5.4. Processing Multiple Elements in an Array">Section 3.5.4, “Processing Multiple Elements in an Array”</a> and <a class="xref" href="arrayops-deleting.html" title="3.5.5. Clearing/Deleting Arrays and Array Elements">Section 3.5.5, “Clearing/Deleting Arrays and Array Elements”</a> , you can track the number of VFS reads each process makes per 3-second period <span class="emphasis"><em>and</em></span> tally the cumulative VFS reads of those same processes. Consider the following example: </div><pre class="screen"> global reads, totalreads probe vfs.read { reads[execname()] ++ totalreads[execname()] ++ } probe timer.s(3) { printf("=======\n") foreach (count in reads-) printf("%s : %d \n", count, reads[count]) delete reads } probe end { printf("TOTALS\n") foreach (total in totalreads-) printf("%s : %d \n", total, totalreads[total]) } </pre><div class="para"> In this example, the arrays <code class="command">reads</code> and <code class="command">totalreads</code> track the same information, and are printed out in a similar fashion. The only difference here is that <code class="command">reads</code> is cleared every 3-second period, whereas <code class="command">totalreads</code> keeps growing. </div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="arrayops-foreach.html"><strong>Prev</strong>3.5.4. Processing Multiple Elements in an Array</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="arrayops-conditionals.html"><strong>Next</strong>3.5.6. Using Arrays in Conditional Statements</a></li></ul></body></html>