Associative Arrays; Examples; Types Of Values; Array Capacity - Red Hat ENTERPRISE LINUX 5.4 - SYSTEMTAP LANGUAGE Reference Manual

Systemtap language reference
Hide thumbs Also See for ENTERPRISE LINUX 5.4 - SYSTEMTAP LANGUAGE:
Table of Contents

Advertisement

Chapter 7.

Associative arrays

Associative arrays are implemented as hash tables with a maximum size set at startup. Associative
arrays are too large to be created dynamically for individual probe handler runs, so they must be
declared as global. The basic operations for arrays are setting and looking up elements. These
operations are expressed in awk syntax: the array name followed by an opening bracket ([), a comma-
separated list of up to five index index expressions, and a closing bracket (]). Each index expression
may be a string or a number, as long as it is consistently typed throughout the script.

7.1. Examples

# Increment the named array slot:
foo [4,"hello"] ++
# Update a statistic:
processusage [uid(),execname()] ++
# Set a timestamp reference point:
times [tid()] = get_cycles()
# Compute a timestamp delta:
delta = get_cycles() - times [tid()]

7.2. Types of values

Array elements may be set to a number or a string. The type must be consistent throughout the use
of the array. The first assignment to the array defines the type of the elements. Unset array elements
may be fetched and return a null value (zero or empty string) as appropriate, but they are not seen by
a membership test.

7.3. Array capacity

Array sizes can be specified explicitly or allowed to default to the maximum size as defined
Section 1.6, "Safety and security"
by MAXMAPENTRIES. See Section
for details on changing
MAXMAPENTRIES.
You can explicitly specify the size of an array as follows:
global ARRAY[<size>]
If you do not specify the size parameter, then the array is created to hold MAXMAPENTRIES number
of elements
33

Advertisement

Table of Contents
loading

Table of Contents