Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 95299258dbdf9a86cefd89b97c0d81e5 > files > 95

systemtap-1.2-1.fc13.i686.rpm

<?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.2. Reading Values From Arrays</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="arrayoperators.html" title="3.5. Array Operations in SystemTap" /><link rel="next" href="arrayops-increment.html" title="3.5.3. Incrementing Associated Values" /></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="arrayoperators.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="arrayops-increment.html"><strong>Next</strong></a></li></ul><div class="section" title="3.5.2. Reading Values From Arrays"><div class="titlepage"><div><div><h3 class="title" id="arrayops-readvalues">3.5.2. Reading Values From Arrays</h3></div></div></div><a id="id2771450" class="indexterm"></a><a id="id3065002" class="indexterm"></a><a id="id2895747" class="indexterm"></a><div class="para">
			You can also read values from an array the same way you would read the value of a variable. To do so, include the <code class="command"><em class="replaceable"><code>array_name</code></em>[<em class="replaceable"><code>index_expression</code></em>]</code> statement as an element in a mathematical expression. For example:
		</div><a id="id2854861" class="indexterm"></a><a id="id3034422" class="indexterm"></a><a id="id3007289" class="indexterm"></a><a id="id3099416" class="indexterm"></a><a id="id4361491" class="indexterm"></a><a id="id2909464" class="indexterm"></a><a id="id2746370" class="indexterm"></a><a id="id2960407" class="indexterm"></a><a id="id2847923" class="indexterm"></a><a id="id3105795" class="indexterm"></a><div class="example" id="arrayreadingvaluesfrom"><div class="example-contents"><pre class="screen">
delta = gettimeofday_s() - foo[tid()]
</pre></div><h6>Example 3.13. Using Array Values in Simple Computations</h6></div><br class="example-break" /><div class="para">
			This example assumes that the array <code class="command">foo</code> was built using the construct in <a class="xref" href="arrayoperators.html#arrays-timestampprocessname" title="Example 3.12. Associating Timestamps to Process Names">Example 3.12, “Associating Timestamps to Process Names”</a> (from <a class="xref" href="arrayoperators.html#arrayops-assignvalue" title="3.5.1. Assigning an Associated Value">Section 3.5.1, “Assigning an Associated Value”</a>). This sets a timestamp that will serve as a <span class="emphasis"><em>reference point</em></span>, to be used in computing for <code class="literal">delta</code>.
		</div><div class="para">
			The construct in <a class="xref" href="arrayops-readvalues.html#arrayreadingvaluesfrom" title="Example 3.13. Using Array Values in Simple Computations">Example 3.13, “Using Array Values in Simple Computations”</a> computes a value for the variable <code class="literal">delta</code> by subtracting the associated value of the key <code class="literal">tid()</code> from the current <code class="command">gettimeofday_s()</code>. The construct does this by <span class="emphasis"><em>reading</em></span> the value of <code class="literal">tid()</code> from the array. This particular construct is useful for determining the time between two events, such as the start and completion of a read operation.
		</div><a id="id2770475" class="indexterm"></a><a id="id3081311" class="indexterm"></a><a id="id2728072" class="indexterm"></a><a id="id4353336" class="indexterm"></a><div class="note"><h2>Note</h2><div class="para">
				If the <code class="command"><em class="replaceable"><code>index_expression</code></em></code> cannot find the unique key, it returns a value of 0 (for numerical operations, such as <a class="xref" href="arrayops-readvalues.html#arrayreadingvaluesfrom" title="Example 3.13. Using Array Values in Simple Computations">Example 3.13, “Using Array Values in Simple Computations”</a>) or a null/empty string value (for string operations) by default.
			</div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="arrayoperators.html"><strong>Prev</strong>3.5. Array Operations in SystemTap</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-increment.html"><strong>Next</strong>3.5.3. Incrementing Associated Values</a></li></ul></body></html>