summaryrefslogtreecommitdiffstats
path: root/SystemTap_Beginners_Guide/arrayops-readvalues.html
blob: 007e61ccba57ce7f16d0b31f6c503e72293cdee9 (plain) (blame)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
<?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 xmlns:d="http://docbook.org/ns/docbook">3.5.2. Reading Values From Arrays</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta xmlns:d="http://docbook.org/ns/docbook" name="generator" content="not publican" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="" /><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><p id="title"></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="arrayoperators.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="arrayops-increment.html"><strong>Next</strong></a></li></ul><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="arrayops-readvalues"></a>3.5.2. Reading Values From Arrays</h3></div></div></div><a id="idp71890961379296" class="indexterm"></a><a id="idp71890964935344" class="indexterm"></a><a id="idp71890964936928" 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">array_name</em>[<em class="replaceable">index_expression</em>]</code>	statement as an element in a mathematical expression. For example:</div><a id="idp71890967953120" class="indexterm"></a><a id="idp71890960001248" class="indexterm"></a><a id="idp71890960003248" class="indexterm"></a><a id="idp71890967556528" class="indexterm"></a><a id="idp71890960139504" class="indexterm"></a><a id="idp71890968139312" class="indexterm"></a><a id="idp71890971744736" class="indexterm"></a><a id="idp71890966293616" class="indexterm"></a><a id="idp71890966295664" class="indexterm"></a><a id="idp71890971559104" class="indexterm"></a><div class="example"><a id="arrayreadingvaluesfrom"></a><p class="title"><strong>Example 3.15. Using Array Values in Simple Computations</strong></p><div class="example-contents"><pre class="screen">delta = gettimeofday_s() - foo[tid()]</pre></div></div><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">Example 3.14, “Associating Timestamps to Process Names”</a> (from <a class="xref" href="arrayoperators.html#arrayops-assignvalue">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">Example 3.15, “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="idp71890971336608" class="indexterm"></a><a id="idp71890967553424" class="indexterm"></a><a id="idp71890966283440" class="indexterm"></a><a id="idp71890964951424" class="indexterm"></a><div xmlns:d="http://docbook.org/ns/docbook" class="note"><div class="admonition_header"><p><strong>Note</strong></p></div><div class="admonition"><div class="para">	If the <code class="command"><em class="replaceable">index_expression</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">Example 3.15, “Using Array Values in Simple Computations”</a>) or a null/empty string value (for string operations) by	default. </div></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>