From e557e9564abe26495b516332fec90016bc4760ac Mon Sep 17 00:00:00 2001 From: William Cohen Date: Wed, 10 Dec 2008 10:38:53 -0500 Subject: Edit text sections on associative arrays. Also tweak example two space indent. --- doc/SystemTap_Beginners_Guide/en-US/Arrays.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (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 04e34de3..63c3df04 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml @@ -14,7 +14,7 @@ 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. +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. @@ -98,7 +98,7 @@ 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: +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 accessing an element in an associative array is similar to that of awk, and is as follows: arrays @@ -126,10 +126,10 @@ -array_name[index_expression] operation +array_name[index_expression] -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: +Here, the array_name is any arbitrary name the array uses. The index_expression is used to refer to a specific unique key in the array. 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: @@ -158,13 +158,13 @@ foo["dick"] = 24 foo["harry"] = 25 - + Important All associate arrays must be declared as global, regardless of whether the associate array is used in one or multiple probes. @@ -220,13 +220,13 @@ probe begin { foo[4,"hello"] ++ } You can also use a handler function in as the unique_key. Doing so creates an associate array that uses the values returned by the handler function as the unique keys. The first time that a probe using this array returns a string value, that value is set as a unique key with an initial value of 0. The next time that the probe returns the same string value, it increments the associated value of the unique key by 1. -For example, let's say you need to tally how many times each process performs a read to the virtual file system (VFS). To do this, probe the kernel function vfs_read, use the handler execname() to identify which processes performed the VFS read, and tally the reads of each process using the associative array named reads, as in +For example, let's say you need to tally how many times each process performs a read to the virtual file system (VFS). To do this, probe the VFS read opeartion, use the handler execname() to identify which processes performed the VFS read, and tally the reads of each process using the associative array named reads, as in tallying-in-arrays.stp -probe kernel.function("vfs_read") +probe vfs.read { reads[execname()] += $count } @@ -234,4 +234,4 @@ probe kernel.function("vfs_read") In , the first time that the probe returns the process name gnome-terminal (i.e. the first time gnome-terminal performs a VFS read), that process name is set as a unique key. The next time that the probe returns the process name gnome-terminal, SystemTap increments the associated value of gnome-terminal by 1. SystemTap performs this operation for all process names as the probe returns them. --> - \ No newline at end of file + -- cgit