On Wed, Mar 04, 2020 at 10:07:07AM -0800, Song Liu wrote: > 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%) FYI I'm in the middle of moving perf's 'events parsing' interface to libperf, which takes event name/s on input and returns list of perf_event_attr objects parse_events("cycles") -> ready to use 'struct perf_event_attr' You can use any event that's listed in 'perf list' command, which includes also all vendor (Intel/Arm/ppc..) events. It might be useful extension for this command. jirka