System information

72 System Analysis and Tuning Guide
5.1.1 SystemTap Scripts
SystemTap usage is based on SystemTap scripts (*.stp). They tell SystemTap which
type of information to collect, and what to do once that information is collected.
The scripts are written in the SystemTap scripting language that is similar to AWK
and C. For the language definition, see http://sourceware.org/system
tap/langref/.
The essential idea behind a SystemTap script is to name events, and to give them
handlers. When SystemTap runs the script, it monitors for certain events. When an
event occurs, the Linux kernel runs the handler as a sub-routine, then resumes. Thus,
events serve as the triggers for handlers to run. Handlers can record specified data and
print it in a certain manner.
The SystemTap language only uses a few data types (integers, strings, and associative
arrays of these), and full control structures (blocks, conditionals, loops, functions). It
has a lightweight punctuation (semicolons are optional) and does not need detailed de-
clarations (types are inferred and checked automatically).
For more information about SystemTap scripts and their syntax, refer to Section5.3,
“Script Syntax” (page76) and to the stapprobes and stapfuncs man pages,
that are available with the systemtap-docs package.
5.1.2 Tapsets
Tapsets are a library of pre-written probes and functions that can be used in System-
Tap scripts. When a user runs a SystemTap script, SystemTap checks the script's
probe events and handlers against the tapset library. SystemTap then loads the cor-
responding probes and functions before translating the script to C. Like SystemTap
scripts themselves, tapsets use the filename extension *.stp.
However, unlike SystemTap scripts, tapsets are not meant for direct execution—they
constitute the library from which other scripts can pull definitions. Thus, the tapset li-
brary is an abstraction layer designed to make it easier for users to define events and
functions. Tapsets provide useful aliases for functions that users may want to specify
as an event (knowing the proper alias is mostly easier than remembering specific ker-
nel functions that might vary between kernel versions).