• Song Liu's avatar
    perf bpf: Save BTF information as headers to perf.data · a70a1123
    Song Liu authored
    This patch enables 'perf record' to save BTF information as headers to
    perf.data.
    
    A new header type HEADER_BPF_BTF is introduced for this data.
    
    Committer testing:
    
    As root, being on the kernel sources top level directory, run:
    
        # perf trace -e tools/perf/examples/bpf/augmented_raw_syscalls.c -e *msg
    
    Just to compile and load a BPF program that attaches to the
    raw_syscalls:sys_{enter,exit} tracepoints to trace the syscalls ending
    in "msg" (recvmsg, sendmsg, recvmmsg, sendmmsg, etc).
    
    Make sure you have a recent enough clang, say version 9, to get the
    BTF ELF sections needed for this testing:
    
      # clang --version | head -1
      clang version 9.0.0 (https://git.llvm.org/git/clang.git/ 7906282d3afec5dfdc2b27943fd6c0309086c507) (https://git.llvm.org/git/llvm.git/ a1b5de1ff8ae8bc79dc8e86e1f82565229bd0500)
      # readelf -SW tools/perf/examples/bpf/augmented_raw_syscalls.o | grep BTF
        [22] .BTF              PROGBITS        0000000000000000 000ede 000b0e 00      0   0  1
        [23] .BTF.ext          PROGBITS        0000000000000000 0019ec 0002a0 00      0   0  1
        [24] .rel.BTF.ext      REL             0000000000000000 002fa8 000270 10     30  23  8
    
    Then do a systemwide perf record session for a few seconds:
    
      # perf record -a sleep 2s
    
    Then look at:
    
      # perf report --header-only | grep b[pt]f
      # event : name = cycles:ppp, , id = { 1116204, 1116205, 1116206, 1116207, 1116208, 1116209, 1116210, 1116211 }, size = 112, { sample_period, sample_freq } = 4000, sample_type = IP|TID|TIME|PERIOD, read_format = ID, disabled = 1, inherit = 1, mmap = 1, comm = 1, freq = 1, enable_on_exec = 1, task = 1, precise_ip = 3, sample_id_all = 1, exclude_guest = 1, mmap2 = 1, comm_exec = 1, ksymbol = 1, bpf_event = 1
      # bpf_prog_info of id 13
      # bpf_prog_info of id 14
      # bpf_prog_info of id 15
      # bpf_prog_info of id 16
      # bpf_prog_info of id 17
      # bpf_prog_info of id 18
      # bpf_prog_info of id 21
      # bpf_prog_info of id 22
      # bpf_prog_info of id 51
      # bpf_prog_info of id 52
      # btf info of id 8
      #
    
    We need to show more info about these BPF and BTF entries , but that can
    be done later.
    Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
    Reviewed-by: default avatarJiri Olsa <jolsa@kernel.org>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stanislav Fomichev <sdf@google.com>
    Cc: kernel-team@fb.com
    Link: http://lkml.kernel.org/r/20190312053051.2690567-10-songliubraving@fb.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    a70a1123
header.c 87.4 KB