stap
. stap
can run SystemTap scripts from standard input or from file.
stap
and staprun
requires elevated privileges to the system. However, not all users can be granted root access just to run SystemTap. In some cases, for instance, you may want to allow a non-privileged user to run SystemTap instrumentation on his machine.
stap
to run SystemTap scripts, or staprun
to run SystemTap instrumentation modules.
stap
involves compiling SystemTap scripts into kernel modules and loading them into the kernel. This requires elevated privileges to the system, which are granted to stapdev
members. Unfortunately, such privileges also grant effective root access to stapdev
members. As such, you should only grant stapdev
group membership to users whom you can trust root access.
staprun
to run SystemTap instrumentation modules. In addition, they can only run those modules from /lib/modules/kernel_version
/systemtap/
. Note that this directory must be owned only by the root user, and must only be writable by the root user.
stap
options:
stap -vvv script.stp
) to provide more details on the script's execution. This option is particularly useful if you encounter any errors in running the script.
filename
filename
).
size
,count
size
megabytes and limit the number of files kept around to count
. The file names will have a sequence number suffix. This option implements logrotate operations for SystemTap.
process ID
target()
to the specified process ID. For more information about target()
, refer to SystemTap Functions.
command
'target()
to the specified command and runs the SystemTap instrumentation for the duration of the specified command. For more information about target()
, refer to SystemTap Functions.
script
'script
string rather than a file as input for systemtap translator.
stap
to run scripts from standard input using the switch -
. To illustrate:
stap
to run the script passed by echo
to standard input. Any stap
options you wish to use should be inserted before the -
switch; for instance, to make the example in Example 2.1, “Running Scripts From Standard Input” more verbose, the command would be:
echo "probe timer.s(1) {exit()}" | stap -v -
stap
, refer to man stap
.
staprun
instead. For more information about staprun
and cross-instrumentation, refer to Section 2.2, “Generating Instrumentation for Other Computers”.
Note
stap
options -v
and -o
also work for staprun
. For more information about staprun
, refer to man staprun
.
-F
option) limits the amount of output generated. There are two variations of the flight recorder mode: in-memory and file mode. In both cases the SystemTap script runs as a background process.
-F
option) is used without a file name SystemTap uses a buffer in kernel memory to store the output of the script. The SystemTap instrumentation module will load and the probes start running, the instrumentation will then detach and be put in the background. When the interesting event occurs, you can reattach to the instrumentation and see the recent output in the memory buffer and any continuing output. The following command starts a script using the flight recorder in-memory mode:
stap -F iotime.stp
Disconnecting from systemtap module. To reconnect, type "staprun -A stap_5dd0073edcb1f13f7565d8c343063e68_19556"
staprun -A stap_5dd0073edcb1f13f7565d8c343063e68_19556
-s
option specifying the size in megabytes (rounded up to the next power over 2) for the buffer. For example -s2
on the SystemTap command line would specify 2MB for the buffer.
-S
option followed by two numerical arguments separated by a comma. The first argument is the maximum size in megabytes for the each output file. The second argument is the number of recent files to keep. The file name is specified by the -o
option followed by the name. SystemTap will add a number suffix to the file name to indicate the order of the files. The following will start SystemTap in file flight recorder mode with the output going to files named /tmp/iotime.log.
[0-9]+
and each file 1MB or smaller and keeping latest two files:
stap -F -o /tmp/pfaults.log -S 1,2 pfaults.stp
kill -s SIGTERM 7590
ls -sh /tmp/pfaults.log.*
shows the only two files:
1020K /tmp/pfaults.log.5 44K /tmp/pfaults.log.6