Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 95299258dbdf9a86cefd89b97c0d81e5 > files > 89

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. Array Operations in SystemTap</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="understanding-how-systemtap-works.html" title="Chapter 3. Understanding How SystemTap Works" /><link rel="prev" href="associativearrays.html" title="3.4. Associative Arrays" /><link rel="next" href="arrayops-readvalues.html" title="3.5.2. Reading Values From Arrays" /></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="associativearrays.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="arrayops-readvalues.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" title="3.5. Array Operations in SystemTap" lang="en-US"><div class="titlepage"><div><div><h2 class="title" id="arrayoperators">3.5. Array Operations in SystemTap</h2></div></div></div><a id="id4341470" class="indexterm"></a><a id="id2881260" class="indexterm"></a><div class="para">
		This section enumerates some of the most commonly used array operations in SystemTap.
	</div><div class="section" title="3.5.1. Assigning an Associated Value"><div class="titlepage"><div><div><h3 class="title" id="arrayops-assignvalue">3.5.1. Assigning an Associated Value</h3></div></div></div><a id="id2866835" class="indexterm"></a><a id="id3033506" class="indexterm"></a><a id="id3010808" class="indexterm"></a><div class="para">
			Use <code class="command">=</code> to set an associated value to indexed unique pairs, as in:
		</div><pre class="screen">
<em class="replaceable"><code>array_name</code></em>[<em class="replaceable"><code>index_expression</code></em>] = <em class="replaceable"><code>value</code></em>
</pre><div class="para">
			<a class="xref" href="associativearrays.html#arraysimplestexample" title="Example 3.11. Basic Array Statements">Example 3.11, “Basic Array Statements”</a> shows a very basic example of how to set an explicit associated value to a unique key. You can also use a handler function as both your <code class="command"><em class="replaceable"><code>index_expression</code></em></code> and <code class="command"><em class="replaceable"><code>value</code></em></code>. For example, you can use arrays to set a timestamp as the associated value to a process name (which you wish to use as your unique key), as in:
		</div><a id="id2829783" class="indexterm"></a><a id="id2983521" class="indexterm"></a><a id="id2980603" class="indexterm"></a><a id="id2742951" class="indexterm"></a><a id="id2980634" class="indexterm"></a><a id="id2807278" class="indexterm"></a><div class="example" id="arrays-timestampprocessname"><div class="example-contents"><pre class="programlisting">
foo[tid()] = gettimeofday_s()
</pre></div><h6>Example 3.12. Associating Timestamps to Process Names</h6></div><br class="example-break" /><div class="para">
			Whenever an event invokes the statement 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>, SystemTap returns the appropriate <code class="command">tid()</code> value (i.e. the ID of a thread, which is then used as the unique key). At the same time, SystemTap also uses the function <code class="command">gettimeofday_s()</code> to set the corresponding timestamp as the associated value to the unique key defined by the function <code class="command">tid()</code>. This creates an array composed of key pairs containing thread IDs and timestamps.
		</div><div class="para">
			In this same example, if <code class="command">tid()</code> returns a value that is already defined in the array <code class="command">foo</code>, the operator will discard the original associated value to it, and replace it with the current timestamp from <code class="command">gettimeofday_s()</code>.
		</div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="associativearrays.html"><strong>Prev</strong>3.4. Associative Arrays</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-readvalues.html"><strong>Next</strong>3.5.2. Reading Values From Arrays</a></li></ul></body></html>