Chapter 40. Profiling kernel activity with SystemTap
You can profile the kernel activity by monitoring function calls with the following scripts.
40.1. Counting function calls with SystemTap Copy linkLink copied to clipboard!
You can use the functioncallcount.stp SystemTap script to count specific kernel function calls. You can also use this script to target multiple kernel functions.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the functioncallcount.stp script:
stap --example functioncallcount.stp 'argument'
# stap --example functioncallcount.stp 'argument'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This script takes the targeted kernel function as an argument. You can use the argument wildcards to target multiple kernel functions up to a certain extent.
The output of the script, in alphabetical order, contains the names of the functions called and how many times it was called during the sample time.
Consider the following example:
stap -w -v --example functioncallcount.stp "*@mm*.c" -c /bin/true
# stap -w -v --example functioncallcount.stp "*@mm*.c" -c /bin/true
Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
- -w : Suppresses warnings.
- -v : Makes the output of starting kernel visible.
-c command : Tells SystemTap to count function calls during the execution of a command, in this example being
/bin/true
.The output should look similar to the following:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
40.2. Tracing function calls with SystemTap Copy linkLink copied to clipboard!
You can use the para-callgraph.stp SystemTap script to trace function calls and function returns.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
- Run the para-callgraph.stp script.
stap --example para-callgraph.stp 'argument1' 'argument2'
# stap --example para-callgraph.stp 'argument1' 'argument2'
The script para-callgraph.stp takes two command-line arguments:
- The name of the function(s) whose entry/exit you’d like to trace.
- An optional trigger function, which enables or disables tracing on a per-thread basis. Tracing in each thread will continue as long as the trigger function has not exited yet.
Consider the following example:
stap -wv --example para-callgraph.stp 'kernel.function("*@fs/proc.c*")' 'kernel.function("vfs_read")' -c "cat /proc/sys/vm/* || true"
# stap -wv --example para-callgraph.stp 'kernel.function("*@fs/proc.c*")' 'kernel.function("vfs_read")' -c "cat /proc/sys/vm/* || true"
where:
- -w : Suppresses warnings.
- -v : Makes the output of starting kernel visible.
-
-c command : Tells SystemTap to count function calls during the execution of a command, in this example being
/bin/true
.
The output should look similar to the following:
40.3. Determining time spent in kernel and user space with SystemTap Copy linkLink copied to clipboard!
You can use the thread-times.stp SystemTap script to determine the amount of time any given thread is spending in either the kernel or user-space.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the thread-times.stp script:
stap --example thread-times.stp
# stap --example thread-times.stp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This script will display the top 20 processes taking up CPU time during a 5-second period, along with the total number of CPU ticks made during the sample. The output of this script also notes the percentage of CPU time each process used, as well as whether that time was spent in kernel space or user space.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
40.4. Monitoring polling applications with SystemTap Copy linkLink copied to clipboard!
You can use timeout.stp SystemTap script to identify and monitor which applications are polling. Doing so allows you to track unnecessary or excessive polling, which helps you pinpoint areas for improvement in terms of CPU usage and power savings.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the timeout.stp script:
stap --example timeout.stp
# stap --example timeout.stp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This script will track how many times each application uses the following system calls over time:
-
poll
-
select
-
epoll
-
itimer
-
futex
-
nanosleep
-
signal
In this example output you can see which process used which system call and how many times.
40.5. Tracking most frequently used system calls with SystemTap Copy linkLink copied to clipboard!
You can use the topsys.stp SystemTap script to list the top 20 system calls used by the system per 5-second interval. It also lists how many times each system call was used during that period.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the topsys.stp script:
stap --example topsys.stp
# stap --example topsys.stp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Consider the following example:
stap -v --example topsys.stp
# stap -v --example topsys.stp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow where -v makes the output of starting kernel visible.
The output should look similar to the following:
40.6. Tracking system call volume per process with SystemTap Copy linkLink copied to clipboard!
You can use the syscalls_by_proc.stp SystemTap script to see which processes are performing the highest volume of system calls. It displays 20 processes performing the most of system calls.
Prerequisites
- You have installed SystemTap as described in Installing Systemtap.
Procedure
Run the syscalls_by_proc.stp script:
stap --example syscalls_by_proc.stp
# stap --example syscalls_by_proc.stp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Output of the syscalls_by_proc.stp script looks similar to the following:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow