From 218a165500487ccdba0d654221909f362efb09b9 Mon Sep 17 00:00:00 2001 From: ddomingo Date: Thu, 27 Nov 2008 11:33:06 +1000 Subject: added more index entries --- doc/SystemTap_Beginners_Guide/en-US/Arrays.xml | 152 ++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) (limited to 'doc/SystemTap_Beginners_Guide/en-US/Arrays.xml') diff --git a/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml b/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml index c487503b..fa81d7fc 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml @@ -4,10 +4,123 @@
Associative Arrays - + +arrays +introduction + + + +associative arrays +introduction + SystemTap also supports the use of associative arrays. While an ordinary variable represents a single value, associative arrays can represent a list of values. Simply put, an associative array is a collection of unique keys; each key in the array has a value associated with it. Illustrating this visually would be similar to creating a two-column table: the first column would have the unique key, while the second column would have each key's associated value. Each unique key and its associated value is referred to as a key pair. + + + +arrays +introduction +key pairs + + + +associative arrays +introduction +key pairs + + + +key pairs +introduction +arrays + + + + + +arrays +introduction +unique keys + + + +associative arrays +introduction +unique keys + + + +unique keys +introduction +arrays + + + + + +arrays +introduction +associated values + + + +associative arrays +introduction +associated values + + + +associated values +introduction +arrays + + + + + +arrays +introduction +index expression + + + +associative arrays +introduction +index expression + + + +index expression +introduction +arrays + + Since associative arrays are normally processed in multiple probes (as we will demonstrate later), they are declared as global variables in the SystemTap script. The syntax for manipulating arrays (i.e. accessing elements in an associative array) is similar to that of awk, and is as follows: + + +arrays +introduction +syntax + + + +associative arrays +introduction +syntax + + + +syntax +introduction +arrays + + + +format +introduction +arrays + + array_name[index_expression] operation @@ -15,7 +128,25 @@ Here, the array_name is any arbitrary name the array uses. The index_expression is used to refer to a specific unique key (or set of unique keys) in the array, and the operation defines what to do with the index_expression. To illustrate, let us try to build an array named foo that specifies the ages of three people (i.e. the unique keys): tom, dick, and harry. To assign them the ages (i.e. associated values) of 23, 24, and 25 respectively, we'd use the following array statements: + + + +arrays +introduction +example + + + +associative arrays +introduction +example + + +example +introduction +arrays + Basic Array Statements @@ -33,6 +164,25 @@ foo["harry"] = 25
Array Slots + + + +arrays +introduction +slots + + + +associative arrays +introduction +slots + + + +slots +introduction +arrays + Another important point to remember in arrays is that each element therein (i.e. the indexed expression) exists in a slot. A key pair's slot is defined by the order in which each pair's unique key is defined. In our sample array foo in , the key pair that uses the unique key tom is in the first slot, since tom was the first unique key to be defined. dick is in the second slot, and so on.