summaryrefslogtreecommitdiffstats
path: root/SystemTap_Beginners_Guide/associativearrays.html
diff options
Diffstat (limited to 'SystemTap_Beginners_Guide/associativearrays.html')
-rw-r--r--SystemTap_Beginners_Guide/associativearrays.html14
1 files changed, 8 insertions, 6 deletions
diff --git a/SystemTap_Beginners_Guide/associativearrays.html b/SystemTap_Beginners_Guide/associativearrays.html
index 6e959de3..ef47630e 100644
--- a/SystemTap_Beginners_Guide/associativearrays.html
+++ b/SystemTap_Beginners_Guide/associativearrays.html
@@ -1,13 +1,15 @@
1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!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.4. Associative 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="publican v4.0.0" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="SystemTap-SystemTap_Beginners_Guide-2.6-en-US-2.0-1" /><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="commandlineargssect.html" title="3.3.4. Command-Line Arguments" /><link rel="next" href="arrayoperators.html" title="3.5. Array Operations in SystemTap" /></head><body><p id="title"><a class="left" href="https://fedorahosted.org/publican"><img alt="Product Site" src="Common_Content/images//image_left.png" /></a><a class="right" href="https://fedorahosted.org/publican"><img alt="Documentation Site" src="Common_Content/images//image_right.png" /></a></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="commandlineargssect.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="arrayoperators.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" lang="en-US"><div class="titlepage"><div><div><h2 class="title"><a id="associativearrays"></a>3.4. Associative Arrays</h2></div></div></div><a id="idm47951420873600" class="indexterm"></a><a id="idm47951429350848" class="indexterm"></a><div class="para"> 2<!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.4. Associative 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="publican v4.1.3" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="SystemTap-SystemTap_Beginners_Guide-2.6-en-US-2.0-1" /><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="commandlineargssect.html" title="3.3.4. Command-Line Arguments" /><link rel="next" href="arrayoperators.html" title="3.5. Array Operations in SystemTap" /></head><body><p id="title"><a class="left" href="https://fedorahosted.org/publican"><img alt="Product Site" src="Common_Content/images//image_left.png" /></a><a class="right" href="https://fedorahosted.org/publican"><img alt="Documentation Site" src="Common_Content/images//image_right.png" /></a></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="commandlineargssect.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="arrayoperators.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" lang="en-US"><div class="titlepage"><div><div><h2 class="title"><a id="associativearrays">
3 ⁠</a>3.4. Associative Arrays</h2></div></div></div><a id="idm214007233712" class="indexterm"></a><a id="idm214018905072" class="indexterm"></a><div class="para">
3 SystemTap also supports the use of associative arrays. While an ordinary variable represents a single value, associative arrays can represent a collection of values. Simply put, an associative array is a collection of unique keys; each key in the array has a value associated with it. 4 SystemTap also supports the use of associative arrays. While an ordinary variable represents a single value, associative arrays can represent a collection of values. Simply put, an associative array is a collection of unique keys; each key in the array has a value associated with it.
4 </div><a id="idm47951468330144" class="indexterm"></a><a id="idm47951456713952" class="indexterm"></a><a id="idm47951475551232" class="indexterm"></a><a id="idm47951457841888" class="indexterm"></a><a id="idm47951457839264" class="indexterm"></a><a id="idm47951427780864" class="indexterm"></a><a id="idm47951456296992" class="indexterm"></a><a id="idm47951429346912" class="indexterm"></a><div class="para"> 5 </div><a id="idm214018799152" class="indexterm"></a><a id="idm213979340784" class="indexterm"></a><a id="idm214007089824" class="indexterm"></a><a id="idm214017493712" class="indexterm"></a><a id="idm213969444112" class="indexterm"></a><a id="idm214016959840" class="indexterm"></a><a id="idm214026583152" class="indexterm"></a><a id="idm214009641888" class="indexterm"></a><div class="para">
5 Since associative arrays are normally processed in multiple probes (as we will demonstrate later), they should be declared as <code class="command">global</code> variables in the SystemTap script. The syntax for accessing an element in an associative array is similar to that of <code class="command">awk</code>, and is as follows: 6 Since associative arrays are normally processed in multiple probes (as we will demonstrate later), they should be declared as <code class="command">global</code> variables in the SystemTap script. The syntax for accessing an element in an associative array is similar to that of <code class="command">awk</code>, and is as follows:
6 </div><a id="idm47951468162656" class="indexterm"></a><a id="idm47951463622608" class="indexterm"></a><a id="idm47951463771856" class="indexterm"></a><pre class="screen"><em class="replaceable"><code>array_name</code></em>[<em class="replaceable"><code>index_expression</code></em>]</pre><div class="para"> 7 </div><a id="idm213975388304" class="indexterm"></a><a id="idm214021154928" class="indexterm"></a><a id="idm214026344944" class="indexterm"></a><pre class="screen"><em class="replaceable">array_name</em>[<em class="replaceable">index_expression</em>]</pre><div class="para">
7 Here, the <code class="command"><em class="replaceable"><code>array_name</code></em></code> is any arbitrary name the array uses. The <code class="command"><em class="replaceable"><code>index_expression</code></em></code> is used to refer to a specific unique key in the array. To illustrate, let us try to build an array named <code class="command">foo</code> that specifies the ages of three people <code class="command">tom</code>, <code class="command">dick</code>, and <code class="command">harry</code> (which are unique keys). To assign them the ages (associated values) of 23, 24, and 25 respectively, we'd use the following array statements: 8 Here, the <code class="command"><em class="replaceable">array_name</em></code> is any arbitrary name the array uses. The <code class="command"><em class="replaceable">index_expression</em></code> is used to refer to a specific unique key in the array. To illustrate, let us try to build an array named <code class="command">foo</code> that specifies the ages of three people <code class="command">tom</code>, <code class="command">dick</code>, and <code class="command">harry</code> (which are unique keys). To assign them the ages (associated values) of 23, 24, and 25 respectively, we'd use the following array statements:
8 </div><a id="idm47951457443712" class="indexterm"></a><a id="idm47951456157664" class="indexterm"></a><div class="example"><a id="arraysimplestexample"></a><p class="title"><strong>Example 3.13. Basic Array Statements</strong></p><div class="example-contents"><pre class="screen">foo["tom"] = 23 9 </div><a id="idm214012568416" class="indexterm"></a><a id="idm214010602368" class="indexterm"></a><div class="example"><a id="arraysimplestexample">
10 ⁠</a><p class="title"><strong>Example 3.13. Basic Array Statements</strong></p><div class="example-contents"><pre class="screen">foo["tom"] = 23
9foo["dick"] = 24 11foo["dick"] = 24
10foo["harry"] = 25</pre></div></div><br class="example-break" /><div class="para"> 12foo["harry"] = 25</pre></div></div><div class="para">
11 You can specify up to nine index expressions in an array statement, each one delimited by a comma (<code class="command">,</code>). This is useful if you wish to have a key that contains multiple pieces of information. The following line from <a class="xref" href="mainsect-disk.html#scriptdisktop">disktop.stp</a> uses 5 elements for the key: process ID, executable name, user ID, parent process ID, and string "W". It associates the value of <code class="command">devname</code> with that key. 13 You can specify up to nine index expressions in an array statement, each one delimited by a comma (<code class="command">,</code>). This is useful if you wish to have a key that contains multiple pieces of information. The following line from <a class="xref" href="mainsect-disk.html#scriptdisktop">disktop.stp</a> uses 5 elements for the key: process ID, executable name, user ID, parent process ID, and string "W". It associates the value of <code class="command">devname</code> with that key.
12 </div><pre class="screen">device[pid(),execname(),uid(),ppid(),"W"] = devname</pre><div xmlns:d="http://docbook.org/ns/docbook" class="important"><div class="admonition_header"><p><strong>Important</strong></p></div><div class="admonition"><div class="para"> 14 </div><pre class="screen">device[pid(),execname(),uid(),ppid(),"W"] = devname</pre><div xmlns:d="http://docbook.org/ns/docbook" class="important"><div class="admonition_header"><p><strong>Important</strong></p></div><div class="admonition"><div class="para">
13 All associate arrays must be declared as <code class="command">global</code>, regardless of whether the associate array is used in one or multiple probes. 15 All associate arrays must be declared as <code class="command">global</code>, regardless of whether the associate array is used in one or multiple probes.