Sample SystemTap scripts
You can find sample scripts that are distributed with the installation of SystemTap in the /usr/share/systemtap/examples directory.
Use the stap command to run different SystemTap scripts:
- Tracing function calls
-
You can use the
para-callgraph.stpSystemTap script to trace function calls and function returns.# stap para-callgraph.stp <argument1 argument2>The script takes two command-line arguments:
- The name of the function(s) whose entry/exit you are tracing.
- An optional trigger function, which enables or disables tracing on a per-thread basis.
Tracing in each thread continues as long as the trigger function has not exited.
- Monitoring polling applications
-
You can use the
timeout.stpSystemTap script to identify and monitor which applications are polling. Knowing this, you can track unnecessary or excessive polling. It can help you to pinpoint areas for improvement in terms of CPU usage and power savings.# stap timeout.stpThis script tracks how many times each application uses
poll,select,epoll,itimer,futex,nanosleep, andSignalsystem calls over time. - Tracking system call volume per process
-
You can use the
syscalls_by_proc.stpSystemTap script to see what processes are performing the highest volume of system calls. It displays the top 20 processes by default.# stap syscalls_by_proc.stp - Tracing functions called in network socket code
-
You can use the
socket-trace.stpSystemTap script to trace functions called from the kernel’snet/socket.cfile. This helps you to identify how each process interacts with the network at the kernel level in fine detail.# stap socket-trace.stp - Tracking I/O time for each file read or write
-
Use the
iotime.stpSystemTap script to monitor time taken for each process to read from or write to any file. This helps you to determine what files are slow to load on a system.# stap iotime.stp - Tracking IRQ’s and other processes stealing cycles from a task
-
Use the
cycle_thief.stpSystemTap script to track the time a task is running and the amount of time it is not running. This helps you to identify which processes are stealing cycles from a task.# stap cycle_thief.stp -x pidFor more information, see the
/usr/share/systemtap/examplesdirectory.Note You can find more examples and information about SystemTap scripts in the
/usr/share/systemtap/examples/index.htmlfile. Open it in a web browser to see a list of all the available scripts and their descriptions.