linux/tools/bpf/bpftool
Song Liu 47c09d6a9f bpftool: Introduce "prog profile" command
With fentry/fexit programs, it is possible to profile BPF program with
hardware counters. Introduce bpftool "prog profile", which measures key
metrics of a BPF program.

bpftool prog profile command creates per-cpu perf events. Then it attaches
fentry/fexit programs to the target BPF program. The fentry program saves
perf event value to a map. The fexit program reads the perf event again,
and calculates the difference, which is the instructions/cycles used by
the target program.

Example input and output:

  ./bpftool prog profile id 337 duration 3 cycles instructions llc_misses

        4228 run_cnt
     3403698 cycles                                              (84.08%)
     3525294 instructions   #  1.04 insn per cycle               (84.05%)
          13 llc_misses     #  3.69 LLC misses per million isns  (83.50%)

This command measures cycles and instructions for BPF program with id
337 for 3 seconds. The program has triggered 4228 times. The rest of the
output is similar to perf-stat. In this example, the counters were only
counting ~84% of the time because of time multiplexing of perf counters.

Note that, this approach measures cycles and instructions in very small
increments. So the fentry/fexit programs introduce noticeable errors to
the measurement results.

The fentry/fexit programs are generated with BPF skeletons. Therefore, we
build bpftool twice. The first time _bpftool is built without skeletons.
Then, _bpftool is used to generate the skeletons. The second time, bpftool
is built with skeletons.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200309173218.2739965-2-songliubraving@fb.com
2020-03-10 00:04:07 +01:00
..
bash-completion bpftool: Update bash completion for "bpftool feature" command 2020-02-26 18:34:34 +01:00
Documentation bpftool: Update documentation of "bpftool feature" command 2020-02-26 18:34:34 +01:00
skeleton bpftool: Introduce "prog profile" command 2020-03-10 00:04:07 +01:00
.gitignore tools: bpf: account for generated feature/ and libbpf/ directories 2019-08-31 00:38:16 +02:00
btf_dumper.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2020-01-23 08:10:16 +01:00
btf.c bpftool: Add header guards to generated vmlinux.h 2020-03-02 16:25:14 -08:00
cfg.c tools: bpftool: teach cfg code about JMP32 2019-01-26 13:33:01 -08:00
cfg.h tools: bpftool: replace Netronome boilerplate with SPDX license headers 2018-12-13 12:08:44 +01:00
cgroup.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
common.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
feature.c bpftool: Make probes which emit dmesg warnings optional 2020-02-26 18:34:34 +01:00
gen.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
jit_disasm.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
json_writer.c tools: bpftool: move "__printf()" attributes to header file 2019-08-15 22:06:46 -07:00
json_writer.h tools: bpftool: move "__printf()" attributes to header file 2019-08-15 22:06:46 -07:00
main.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
main.h bpftool: Support struct_ops, tracing, ext prog types 2020-02-26 16:40:53 +01:00
Makefile bpftool: Introduce "prog profile" command 2020-03-10 00:04:07 +01:00
map_perf_ring.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
map.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
net.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
netlink_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
netlink_dumper.h tools: bpftool: dual license all files 2018-12-13 12:08:44 +01:00
perf.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
prog.c bpftool: Introduce "prog profile" command 2020-03-10 00:04:07 +01:00
tracelog.c tools: bpftool: add an option to prevent auto-mount of bpffs, tracefs 2018-12-18 14:47:17 +01:00
xlated_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
xlated_dumper.h tools: bpftool: replace Netronome boilerplate with SPDX license headers 2018-12-13 12:08:44 +01:00