offcputime(8)
β¨ offcputime(8) β¨
π NAME π
okay so the manual name is offcputime(8) π and it does this: summarize off-CPU time by kernel stack trace. It uses Linux eBPF/bcc π₯
π§ SYNOPSIS π§
offcputime [-h] [-p PID | -t TID | -u | -k] [-U | -K] [-d] [-f]
[--stack-storage-size STACK_STORAGE_SIZE] [-m MIN_BLOCK_TIME] [-M
MAX_BLOCK_TIME] [--state STATE] [duration]
πΈ DESCRIPTION πΈ
bestie, this program shows you the stack traces and task names of things that were blocked and "off-CPU" π, plus the total duration they were not running. That's their off-CPU time β¨. It works by tracing when threads block and when they get back on CPU, measuring how long they were off-CPU, along with the blocked stack trace and the task name. All of this gets summarized in the kernel using an eBPF map, by adding up the off-CPU time for each unique stack trace and task name π
The output summary helps you figure out why threads were blocking and how much time they lost being off-CPU π It covers every kind of blocking activity: disk I/O, network I/O, locks, page faults, involuntary context switches, etc. The whole vibe is giving "everything that made my thread wait" π«Ά
This is complementary to CPU profiling (e.g., CPU flame graphs), which shows time spent on-CPU π₯. This one shows time spent off-CPU instead. The output, especially the -f format, can be used to generate an "off-CPU time flame graph" π¦
See http://www.brendangregg.com/FlameGraphs/offcpuflamegraphs.html π
β οΈ This tool only works on Linux 4.6+. It uses the newerBPF_STACK_TRACEtable APIs to generate the in-kernel stack traces. For kernels older than 4.6, see the version undertools/old.
Also, lowkey important: this tool only traces off-CPU times that both began and ended while tracing π
π REQUIREMENTS π
You'll need CONFIG_BPF and bcc π
π OPTIONS π
-hβ Prints the usage message π-p PIDβ Traces only this process ID (filtered in-kernel) π-t TIDβ Traces only this thread ID (filtered in-kernel) π-uβ Only traces user threads, no kernel threads π§-kβ Only traces kernel threads, no user threads π§-Uβ Shows stacks from user space only, no kernel space stacks β¨-Kβ Shows stacks from kernel space only, no user space stacks β¨-dβ Inserts a delimiter between kernel and user stacks π¦-fβ Prints output in folded stack format π₯--stack-storage-size STACK_STORAGE_SIZEβ Changes how many unique stack traces can be stored and displayed π-m MIN_BLOCK_TIMEβ The minimum time in microseconds over which traces get stored (default1) π«Ά-M MAX_BLOCK_TIMEβ The maximum time in microseconds under which traces get stored (defaultU64_MAX) π«Ά--stateβ Filters on this thread state bitmask (eg,2==TASK_UNINTERRUPTIBLE). Checkinclude/linux/sched.hfor the states πdurationβ How long to trace, in seconds β
π§ EXAMPLES π§
okay here are the vibes, bestie π
Trace all thread blocking events, and summarize (in-kernel) by kernel stack trace and total off-CPU time:
# offcputime
Trace for 5 seconds only:
# offcputime 5
Trace for 5 seconds, and emit output in folded stack format (suitable for flame graphs):
# offcputime -f 5
Trace PID 185 only:
# offcputime -p 185
π OVERHEAD π
This one summarizes unique stack traces in-kernel for efficiency π§ , which means it can trace a higher rate of events than methods that post-process in user space. The stack trace and time data only gets copied to user space once, when the output is printed. Even so, scheduler events are still a high frequency event, since they can exceed 1 million events per second, so be careful π
β οΈ Caution: test before production use, bestie. Seriously π
If overhead is still a problem, take a look at the MINBLOCK_US tunable in the code π§. If you're chasing down longer blocking events, you can increase it to filter out the shorter blocking events, which lowers overhead even more π«Ά
π¦ SOURCE π¦
This is from bcc π
https://github.com/iovisor/bcc
Also look in the bcc distribution for a companion _examples.txt file containing example usage, output, and commentary for this tool πΈ
π OS π
Linux π§
π STABILITY π
Unstable, still in development π§
π AUTHOR π
Brendan Gregg π
π SEE ALSO π
stackcount(8) β¨
Bye bestie, this was the USER COMMANDS manual page for offcputime(8), dated 2016-01-14 ππ«Άπ
π¦ where this page comes from
- centos-stream 10: bcc-tools 0.36.1-1.el10 Β· Apache-2.0
- centos-stream 9: bcc-tools 0.36.1-1.el9 Β· ASL 2.0
- fedora 43: bcc-tools 0.35.0-2.fc43 Β· Apache-2.0
- fedora 44: bcc-tools 0.35.0-5.fc44 Β· Apache-2.0
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms