profile-bpfcc: Profile CPU stack traces at a timed interval
profile-bpfcc [-h] [-p PID | -L TID] [-U | -K] [-F FREQUENCY | -c COUNT] [-d] [-a] [-I] [-f] [--hash-storage-size HASH_STORAGE_SIZE] [--stack-storage-size STACK_STORAGE_SIZE] [-C CPU] [--cgroupmap CGROUPMAP] [--mntnsmap MNTNSMAP] [-A] [duration]
What it does
Profile CPU stack traces at a timed interval. Part of the bcc tools (bpfcc-tools 0.35.0 on Ubuntu, installed as /usr/sbin/profile-bpfcc; upstream and other distributions call it profile). It loads an eBPF program, so it needs root.
Options you will use
duration- duration of trace, in seconds
-p, --pid PID- profile processes with one or more comma-separated PIDs only
-L, --tid TID- profile threads with one or more comma-separated TIDs only
-U, --user-stacks-only- show stacks from user space only (no kernel space stacks)
-K, --kernel-stacks-only- show stacks from kernel space only (no user space stacks)
-F, --frequency FREQUENCY- sample frequency, Hertz
-c, --count COUNT- sample period, number of events
-d, --delimited- insert delimiter between kernel/user stacks
-a, --annotations- add _[k] annotations to kernel frames
-I, --include-idle- include CPU idle stacks
-f, --folded- output folded format, one line per stack (for flame graphs)
--hash-storage-size HASH_STORAGE_SIZE- the number of hash keys that can be stored and (default 40960)
--stack-storage-size STACK_STORAGE_SIZE- the number of unique stack traces that can be stored and displayed (default 16384)
-C, --cpu CPU- cpu number to run profile on
--cgroupmap CGROUPMAP- trace cgroups in this BPF map only
--mntnsmap MNTNSMAP- trace mount namespaces in this BPF map only
-A, --address- show raw addresses
Examples
$ sudo profile-bpfccprofile stack traces at 49 Hertz until Ctrl-C
$ sudo profile-bpfcc -F 99profile stack traces at 99 Hertz
$ sudo profile-bpfcc -c 1000000profile stack traces every 1 in a million events
$ sudo profile-bpfcc 5profile at 49 Hertz for 5 seconds only
$ sudo profile-bpfcc -f 5output in folded format for flame graphs
$ sudo profile-bpfcc -p 185only profile process with PID 185
$ sudo profile-bpfcc -L 185only profile thread with TID 185
$ sudo profile-bpfcc -Uonly show user space stacks (no kernel)
Gotchas
- Samples stacks at 49 Hz by default (-F to change); -f folded output for flame graphs.
- As a normal user it fails with "could not open bpf map: ..., error: Operation not permitted" (unprivileged BPF is off on Ubuntu).
Try profile-bpfcc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.