此内容没有您所选择的语言版本。
3.5. Array Operations in SystemTap
This section enumerates some of the most commonly used array operations in SystemTap.
3.5.1. Assigning an Associated Value
Use
=
to set an associated value to indexed unique pairs, as in:
array_name[index_expression] = value
Example 3.11, “Basic Array Statements” 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
index_expression
and value
. 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:
Example 3.12. Associating Timestamps to Process Names
foo[tid()] = gettimeofday_s()
Whenever an event invokes the statement in Example 3.12, “Associating Timestamps to Process Names”, SystemTap returns the appropriate
tid()
value (that is the ID of a thread, which is then used as the unique key). At the same time, SystemTap also uses the function gettimeofday_s()
to set the corresponding timestamp as the associated value to the unique key defined by the function tid()
. This creates an array composed of key pairs containing thread IDs and timestamps.
In this same example, if
tid()
returns a value that is already defined in the array foo
, the operator will discard the original associated value to it, and replace it with the current timestamp from gettimeofday_s()
.