System information

SystemTap—Filtering and Analyzing System Data 79
by a name. They take any number of string or numeric arguments (by value) and may
return a single string or number.
function function_name(arguments) {statements}
probe event {function_name(arguments)}
The statements in function_name are executed when the probe for event exe-
cutes. The arguments are optional values passed into the function.
Functions can be defined anywhere in the script. They may take any
One of the functions needed very often was already introduced in Example5.1, “Sim-
ple SystemTap Script” (page76): the printf function for printing data in a
formatted way. When using the printf function, you can specify how arguments
should be printed by using a format string. The format string is included in quotation
marks and can contain further format specifiers, introduced by a % character.
Which format strings to use depends on your list of arguments. Format strings can
have multiple format specifiers—each matching a corresponding argument. Multiple
arguments can be separated by a comma.
Example5.3: printf Function with Format Specifiers
printf (" %s (%d ) open\n ", execname(), pid())
Start of the format string, indicated by ".
String format specifier.
Integer format specifier.
End of the format string, indicated by ".
The example above would print the current executable name (execname()) as
string and the process ID (pid()) as integer in brackets, followed by a space, then
the word open and a line break:
[...]
vmware-guestd(2206) open
hald(2360) open
[...]
Apart from the two functions execname()and pid()) used in Example5.3,
printf Function with Format Specifiers” (page79), a variety of other func-
tions can be used as printf arguments.
Among the most commonly used SystemTap functions are the following: