Commit 7f0a6f80 authored by Andrew Birchall's avatar Andrew Birchall

Update documentation and man page for offcputime

parent 1f202e7b
...@@ -4,17 +4,17 @@ offcputime \- Summarize off-CPU time by kernel stack trace. Uses Linux eBPF/bcc. ...@@ -4,17 +4,17 @@ offcputime \- Summarize off-CPU time by kernel stack trace. Uses Linux eBPF/bcc.
.SH SYNOPSIS .SH SYNOPSIS
.B offcputime [\-h] [\-u] [\-p PID] [\-v] [\-f] [duration] .B offcputime [\-h] [\-u] [\-p PID] [\-v] [\-f] [duration]
.SH DESCRIPTION .SH DESCRIPTION
This program shows kernel stack traces and task names that were blocked and This program shows stack traces and task names that were blocked and "off-CPU",
"off-CPU", and the total duration they were not running: their "off-CPU time". and the total duration they were not running: their "off-CPU time".
It works by tracing when threads block and when they return to CPU, measuring It works by tracing when threads block and when they return to CPU, measuring
both the time they were off-CPU and the blocked kernel stack trace and the both the time they were off-CPU and the blocked stack trace and the task name.
task name. This data is summarized in the kernel using an eBPF map, and by This data is summarized in the kernel using an eBPF map, and by summing the
summing the off-CPU time by unique stack trace and task name. off-CPU time by unique stack trace and task name.
The output summary will help you identify reasons why threads The output summary will help you identify reasons why threads were blocking,
were blocking, and quantify the time they were off-CPU. This spans all types and quantify the time they were off-CPU. This spans all types of blocking
of blocking activity: disk I/O, network I/O, locks, page faults, involuntary activity: disk I/O, network I/O, locks, page faults, involuntary context
context switches, etc. switches, etc.
This is complementary to CPU profiling (e.g., CPU flame graphs) which shows This is complementary to CPU profiling (e.g., CPU flame graphs) which shows
the time spent on-CPU. This shows the time spent off-CPU, and the output, the time spent on-CPU. This shows the time spent off-CPU, and the output,
...@@ -34,14 +34,20 @@ Print usage message. ...@@ -34,14 +34,20 @@ Print usage message.
\-f \-f
Print output in folded stack format. Print output in folded stack format.
.TP .TP
\-p PID
Trace this process ID only (filtered in-kernel).
.TP
\-u \-u
Only trace user threads (not kernel threads). Only trace user threads (no kernel threads).
.TP .TP
\-v \-k
Show raw addresses (for non-folded output). Only trace kernel threads (no user threads).
.TP .TP
\-p PID \-U
Trace this process ID only (filtered in-kernel). Show stacks from user space only (no kernel space stacks).
.TP
\-K
Show stacks from kernel space only (no user space stacks).
.TP .TP
duration duration
Duration to trace, in seconds. Duration to trace, in seconds.
......
...@@ -42,23 +42,25 @@ examples = """examples: ...@@ -42,23 +42,25 @@ examples = """examples:
./offcputime -p 185 # only trace threads for PID 185 ./offcputime -p 185 # only trace threads for PID 185
./offcputime -u # only trace user threads (no kernel) ./offcputime -u # only trace user threads (no kernel)
./offcputime -k # only trace kernel threads (no user) ./offcputime -k # only trace kernel threads (no user)
./offcputime -U # only show user space stacks (no kernel)
./offcputime -K # only show kernel space stacks (no user)
""" """
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Summarize off-CPU time by kernel stack trace", description="Summarize off-CPU time by stack trace",
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=examples) epilog=examples)
thread_group = parser.add_mutually_exclusive_group() thread_group = parser.add_mutually_exclusive_group()
thread_group.add_argument("-p", "--pid", type=positive_int, thread_group.add_argument("-p", "--pid", type=positive_int,
help="trace this PID only") help="trace this PID only")
thread_group.add_argument("-k", "--kernel-threads-only", action="store_true",
help="kernel threads only (no user threads)")
thread_group.add_argument("-u", "--user-threads-only", action="store_true", thread_group.add_argument("-u", "--user-threads-only", action="store_true",
help="user threads only (no kernel threads)") help="user threads only (no kernel threads)")
thread_group.add_argument("-k", "--kernel-threads-only", action="store_true",
help="kernel threads only (no user threads)")
stack_group = parser.add_mutually_exclusive_group() stack_group = parser.add_mutually_exclusive_group()
stack_group.add_argument("-U", "--user-stacks-only", action="store_true", stack_group.add_argument("-U", "--user-stacks-only", action="store_true",
help="show stack from user space only (no kernel space stacks)") help="show stacks from user space only (no kernel space stacks)")
stack_group.add_argument("-K", "--kernel-stacks-only", action="store_true", stack_group.add_argument("-K", "--kernel-stacks-only", action="store_true",
help="show stack from kernel space only (no user space stacks)") help="show stacks from kernel space only (no user space stacks)")
parser.add_argument("-f", "--folded", action="store_true", parser.add_argument("-f", "--folded", action="store_true",
help="output folded format") help="output folded format")
parser.add_argument("--stack-storage-size", default=1024, parser.add_argument("--stack-storage-size", default=1024,
......
...@@ -4,15 +4,16 @@ Demonstrations of offcputime, the Linux eBPF/bcc version. ...@@ -4,15 +4,16 @@ Demonstrations of offcputime, the Linux eBPF/bcc version.
This program shows stack traces that were blocked, and the total duration they This program shows stack traces that were blocked, and the total duration they
were blocked. It works by tracing when threads block and when they return to were blocked. It works by tracing when threads block and when they return to
CPU, measuring both the time they were blocked (aka the "off-CPU time") and the CPU, measuring both the time they were blocked (aka the "off-CPU time") and the
blocked kernel stack trace and the task name. This data is summarized in kernel blocked stack trace and the task name. This data is summarized in kernel by
by summing the blocked time by unique stack trace and task name. summing the blocked time by unique stack trace and task name.
Here is some example output. To explain what we are seeing: the very first Here is some example output. The -K option was used to only match kernel stacks.
stack trace looks like a page fault (do_page_fault() etc) from the "chmod" To explain what we are seeing: the very first stack trace looks like a page
command, and in total was off-CPU for 13 microseconds. fault (do_page_fault() etc) from the "chmod" command, and in total was off-CPU
for 13 microseconds.
# ./offcputime -K # ./offcputime -K
Tracing off-CPU time (us) by kernel stack... Hit Ctrl-C to end. Tracing off-CPU time (us) of all threads by kernel stack... Hit Ctrl-C to end.
^C ^C
schedule schedule
schedule_timeout schedule_timeout
...@@ -587,7 +588,7 @@ Tracing off-CPU time (us) by kernel stack... Hit Ctrl-C to end. ...@@ -587,7 +588,7 @@ Tracing off-CPU time (us) by kernel stack... Hit Ctrl-C to end.
81670888 81670888
The last few stack traces aren't very interesting, since they are threads that The last few stack traces aren't very interesting, since they are threads that
are ofter blocked off-CPU waiting for work. are often blocked off-CPU waiting for work.
Do be somewhat careful with overhead: this is tracing scheduler functions, which Do be somewhat careful with overhead: this is tracing scheduler functions, which
can be called very frequently. While this uses in-kernel summaries for can be called very frequently. While this uses in-kernel summaries for
...@@ -600,7 +601,7 @@ A -p option can be used to filter (in-kernel) on a single process ID. For ...@@ -600,7 +601,7 @@ A -p option can be used to filter (in-kernel) on a single process ID. For
example, only matching PID 26651, which is a running "dd" command: example, only matching PID 26651, which is a running "dd" command:
# ./offcputime -K -p 26651 # ./offcputime -K -p 26651
Tracing off-CPU time (us) by kernel stack... Hit Ctrl-C to end. Tracing off-CPU time (us) of all threads by kernel stack... Hit Ctrl-C to end.
^C ^C
schedule schedule
schedule_timeout schedule_timeout
...@@ -624,7 +625,7 @@ total of 2.4 seconds during tracing. ...@@ -624,7 +625,7 @@ total of 2.4 seconds during tracing.
A duration can be added, for example, tracing for 5 seconds only: A duration can be added, for example, tracing for 5 seconds only:
# ./offcputime -K -p 26651 5 # ./offcputime -K -p 26651 5
Tracing off-CPU time (us) by kernel stack for 5 secs. Tracing off-CPU time (us) of all threads by kernel stack for 5 secs.
schedule schedule
schedule_timeout schedule_timeout
...@@ -718,11 +719,11 @@ creating your "off-CPU time flame graphs". ...@@ -718,11 +719,11 @@ creating your "off-CPU time flame graphs".
USAGE message: USAGE message:
# ./offcputime -h # ./offcputime -h
usage: offcputime.py [-h] [-p PID | -k | -u] [-U | -K] [-f] usage: offcputime.py [-h] [-p PID | -k | -u] [-K | -U] [-f]
[--stack-storage-size STACK_STORAGE_SIZE] [--stack-storage-size STACK_STORAGE_SIZE]
[duration] [duration]
Summarize off-CPU time by kernel stack trace Summarize off-CPU time by stack trace
positional arguments: positional arguments:
duration duration of trace, in seconds duration duration of trace, in seconds
...@@ -730,15 +731,15 @@ positional arguments: ...@@ -730,15 +731,15 @@ positional arguments:
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-p PID, --pid PID trace this PID only -p PID, --pid PID trace this PID only
-k, --kernel-threads-only
kernel threads only (no user threads)
-u, --user-threads-only -u, --user-threads-only
user threads only (no kernel threads) user threads only (no kernel threads)
-k, --kernel-threads-only
kernel threads only (no user threads)
-U, --user-stacks-only -U, --user-stacks-only
show stack from user space only (no kernel space show stacks from user space only (no kernel space
stacks) stacks)
-K, --kernel-stacks-only -K, --kernel-stacks-only
show stack from kernel space only (no user space show stacks from kernel space only (no user space
stacks) stacks)
-f, --folded output folded format -f, --folded output folded format
--stack-storage-size STACK_STORAGE_SIZE --stack-storage-size STACK_STORAGE_SIZE
...@@ -752,3 +753,5 @@ examples: ...@@ -752,3 +753,5 @@ examples:
./offcputime -p 185 # only trace threads for PID 185 ./offcputime -p 185 # only trace threads for PID 185
./offcputime -u # only trace user threads (no kernel) ./offcputime -u # only trace user threads (no kernel)
./offcputime -k # only trace kernel threads (no user) ./offcputime -k # only trace kernel threads (no user)
./offcputime -U # only show user space stacks (no kernel)
./offcputime -K # only show kernel space stacks (no user)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment