This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs. This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference. 1. Change order of arguments (Quentin), as: bpftool prog profile PROG [duration DURATION] METRICs 2. Add bash-completion for bpftool prog profile (Quentin); 3. Fix build of selftests (Yonghong); 4. Better handling of bpf_map_lookup_elem() returns (Yonghong); 5. Improve clean up logic of do_profile() (Yonghong); 6. Other smaller fixes/cleanups. Changes RFC => v2: 1. Use new bpf_program__set_attach_target() API; 2. Update output format to be perf-stat like (Alexei); 3. Incorporate skeleton generation into Makefile; 4. Make DURATION optional and Allow Ctrl-C (Alexei); 5. Add calcated values "insn per cycle" and "LLC misses per million isns". Song Liu (3): bpftool: introduce "prog profile" command bpftool: Documentation for bpftool prog profile bpftool: bash completion for "bpftool prog profile" .../bpftool/Documentation/bpftool-prog.rst | 19 + tools/bpf/bpftool/Makefile | 18 + tools/bpf/bpftool/bash-completion/bpftool | 45 +- tools/bpf/bpftool/prog.c | 432 +++++++++++++++++- tools/bpf/bpftool/skeleton/profiler.bpf.c | 171 +++++++ tools/bpf/bpftool/skeleton/profiler.h | 47 ++ tools/scripts/Makefile.include | 1 + 7 files changed, 731 insertions(+), 2 deletions(-) create mode 100644 tools/bpf/bpftool/skeleton/profiler.bpf.c create mode 100644 tools/bpf/bpftool/skeleton/profiler.h -- 2.17.1