Este contenido no está disponible en el idioma seleccionado.
3.2. SystemTap Scripts
Note
SystemTap scripts use the file extension .stp
, and contains probes written in the following format:
probe event {statements}
,
). If multiple events are specified in a single probe, SystemTap will execute the handler when any of the specified events occur.
{ }
) and contains the statements to be executed per event. SystemTap executes these statements in sequence; special separators or terminators are generally not necessary between multiple statements.
Note
function function_name(arguments) {statements} probe event {function_name(arguments)}
statements
in function_name are executed when the probe for event executes. The arguments are optional values passed into the function.
Important
3.2.1. Event
A synchronous event occurs when any process executes an instruction at a particular location in kernel code. This gives other events a reference point from which more contextual data may be available.
- syscall.system_call
- The entry to the system call system_call. If the exit from a syscall is desired, appending a
.return
to the event monitor the exit of the system call instead. For example, to specify the entry and exit of the system callclose
, usesyscall.close
andsyscall.close.return
respectively. - vfs.file_operation
- The entry to the file_operation event for Virtual File System (VFS). Similar to
syscall
event, appending a.return
to the event monitors the exit of the file_operation operation. - kernel.function("function")
- The entry to the kernel function function. For example,
kernel.function("sys_open")
refers to the "event" that occurs when the kernel functionsys_open
is called by any thread in the system. To specify the return of the kernel functionsys_open
, append thereturn
string to the event statement; that iskernel.function("sys_open").return
.When defining probe events, you can use asterisk (*
) for wildcards. You can also trace the entry or exit of a function in a kernel source file. Consider the following example:Example 3.1. wildcards.stp
probe kernel.function("*@net/socket.c") { } probe kernel.function("*@net/socket.c").return { }
In the previous example, the first probe's event specifies the entry of ALL functions in the kernel source filenet/socket.c
. The second probe specifies the exit of all those functions. Note that in this example, there are no statements in the handler; as such, no information will be collected or displayed. - kernel.trace("tracepoint")
- The static probe for tracepoint. Recent kernels (2.6.30 and newer) include instrumentation for specific events in the kernel. These events are statically marked with tracepoints. One example of a tracepoint available in systemtap is
kernel.trace("kfree_skb")
which indicates each time a network buffer is freed in the kernel. - module("module").function("function")
- Allows you to probe functions within modules. For example:
Example 3.2. moduleprobe.stp
probe module("ext3").function("*") { } probe module("ext3").function("*").return { }
The first probe in Example 3.2, “moduleprobe.stp” points to the entry of all functions for theext3
module. The second probe points to the exits of all functions for that same module; the use of the.return
suffix is similar tokernel.function()
. Note that the probes in Example 3.2, “moduleprobe.stp” do not contain statements in the probe handlers, and as such will not print any useful data (as in Example 3.1, “wildcards.stp”).A system's kernel modules are typically located in/lib/modules/kernel_version
, where kernel_version refers to the currently loaded kernel version. Modules use the file name extension.ko
.
Asynchronous events are not tied to a particular instruction or location in code. This family of probe points consists mainly of counters, timers, and similar constructs.
- begin
- The startup of a SystemTap session; that is as soon as the SystemTap script is run.
- end
- The end of a SystemTap session.
- timer events
- An event that specifies a handler to be executed periodically. For example:
Example 3.3. timer-s.stp
probe timer.s(4) { printf("hello world\n") }
Example 3.3, “timer-s.stp” is an example of a probe that printshello world
every 4 seconds. Note that you can also use the following timer events:timer.ms(milliseconds)
timer.us(microseconds)
timer.ns(nanoseconds)
timer.hz(hertz)
timer.jiffies(jiffies)
When used in conjunction with other probes that collect information, timer events allows you to print out get periodic updates and see how that information changes over time.
Important
man stapprobes
. The SEE ALSO section of man stapprobes
also contains links to other man
pages that discuss supported events for specific subsystems and components.