begin
(that is, the start of the session) triggers the handler enclosed in
{ }
, which simply prints hello
world
followed by a new-line, then exits.
Note
printf ()
statement is one of the simplest
functions for printing data. printf ()
can also be
used to display data using a wide variety of SystemTap functions in the
following format:
printf ("format string\n", arguments)
hello world
, and contains no format specifiers.
%s
(for strings)
and %d
(for numbers) in format strings, depending on
your list of arguments. Format strings can have multiple format
specifiers, each matching a corresponding argument; multiple arguments
are delimited by a comma (,
).
Note
Example 3.5. variables-in-printf-statements.stp
probe syscall.open { printf ("%s(%d) open\n", execname(), pid()) }
open
; for each event, it prints the
current execname()
(a string with the executable name) and
pid()
(the current process ID number), followed by the word
open
. A snippet of this probe's output would look like:
vmware-guestd(2206) open hald(2360) open hald(2360) open hald(2360) open df(3433) open df(3433) open df(3433) open hald(2360) open
printf ()
arguments. Example 3.5, “variables-in-printf-statements.stp”
uses the SystemTap functions execname()
(name of the
process that called a kernel function/performed a system call) and
pid()
(current process ID).
thread_indent()
by the thread),
a process name, and the thread ID. This allows you to
identify what functions were called, who called them, and the
duration of each function call.
thread_indent()
:
Example 3.6. thread_indent.stp
probe kernel.function("*@net/socket.c").call { printf ("%s -> %s\n", thread_indent(1), probefunc()) } probe kernel.function("*@net/socket.c").return { printf ("%s <- %s\n", thread_indent(-1), probefunc()) }
thread_indent()
and probe functions at each event
in the following format:0 ftp(7223): -> sys_socketcall 1159 ftp(7223): -> sys_socket 2173 ftp(7223): -> __sock_create 2286 ftp(7223): -> sock_alloc_inode 2737 ftp(7223): <- sock_alloc_inode 3349 ftp(7223): -> sock_alloc 3389 ftp(7223): <- sock_alloc 3417 ftp(7223): <- __sock_create 4117 ftp(7223): -> sock_create 4160 ftp(7223): <- sock_create 4301 ftp(7223): -> sock_map_fd 4644 ftp(7223): -> sock_map_file 4699 ftp(7223): <- sock_map_file 4715 ftp(7223): <- sock_map_fd 4732 ftp(7223): <- sys_socket 4775 ftp(7223): <- sys_socketcall
thread_indent()
call for the thread (included in the string from thread_indent()
).thread_indent()
).<-
) or an exit (->
); the indentations help you match specific function call entries with their corresponding exits.syscall.system_call
.
stap
script -x process
ID
or stap
script -c
command
. If you want to specify
a script to take an argument of a process ID or command, use
target()
as the variable in the script to refer
to it. For example:
-x process ID
, it
watches all system calls (as specified by the event
syscall.*
) and prints out the name of all system
calls made by the specified process.
if (pid() ==
process ID)
each time you wish
to target a specific process. However, using
target()
makes it easier for you to re-use the
script, giving you the ability to pass a process ID as an
argument each time you wish to run the script (that is, stap
targetexample.stp -x process ID
).
man stapfuncs
.