• Arnaldo Carvalho de Melo's avatar
    perf trace: Use a common encoding for augmented arguments, with size + error + payload · c90a88d3
    Arnaldo Carvalho de Melo authored
    We were using a more compact format, without explicitely encoding the
    size and possible error in the payload for an argument.
    
    To do it generically, at least as Howard Chu did in his GSoC activities,
    it is more convenient to use the same model that was being used for
    string arguments, passing { size, error, payload }.
    
    So use that for the non string syscall args we have so far:
    
      struct timespec
      struct perf_event_attr
      struct sockaddr (this one has even a variable size)
    
    With this in place we have the userspace pretty printers:
    
      perf_event_attr___scnprintf()
      syscall_arg__scnprintf_augmented_sockaddr()
      syscall_arg__scnprintf_augmented_timespec()
    
    Ready to have the generic BPF collector in tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
    sending its generic payload and thus we'll use them instead of a generic
    libbpf btf_dump interface that doesn't know about about the sockaddr
    mux, perf_event_attr non-trivial fields (sample_type, etc), leaving it
    as a (useful) fallback that prints just basic types until we put in
    place a more sophisticated pretty printer infrastructure that associates
    synthesized enums to struct fields using the header scrapers we have in
    tools/perf/trace/beauty/, some of them in this list:
    
      $ ls tools/perf/trace/beauty/*.sh
      tools/perf/trace/beauty/arch_errno_names.sh
      tools/perf/trace/beauty/kcmp_type.sh
      tools/perf/trace/beauty/perf_ioctl.sh
      tools/perf/trace/beauty/statx_mask.sh
      tools/perf/trace/beauty/clone.sh
      tools/perf/trace/beauty/kvm_ioctl.sh
      tools/perf/trace/beauty/pkey_alloc_access_rights.sh
      tools/perf/trace/beauty/sync_file_range.sh
      tools/perf/trace/beauty/drm_ioctl.sh
      tools/perf/trace/beauty/madvise_behavior.sh
      tools/perf/trace/beauty/prctl_option.sh
      tools/perf/trace/beauty/usbdevfs_ioctl.sh
      tools/perf/trace/beauty/fadvise.sh
      tools/perf/trace/beauty/mmap_flags.sh
      tools/perf/trace/beauty/rename_flags.sh
      tools/perf/trace/beauty/vhost_virtio_ioctl.sh
      tools/perf/trace/beauty/fs_at_flags.sh
      tools/perf/trace/beauty/mmap_prot.sh
      tools/perf/trace/beauty/sndrv_ctl_ioctl.sh
      tools/perf/trace/beauty/x86_arch_prctl.sh
      tools/perf/trace/beauty/fsconfig.sh
      tools/perf/trace/beauty/mount_flags.sh
      tools/perf/trace/beauty/sndrv_pcm_ioctl.sh
      tools/perf/trace/beauty/fsmount.sh
      tools/perf/trace/beauty/move_mount_flags.sh
      tools/perf/trace/beauty/sockaddr.sh
      tools/perf/trace/beauty/fspick.sh
      tools/perf/trace/beauty/mremap_flags.sh
      tools/perf/trace/beauty/socket.sh
      $
    
    Testing it:
    
      root@number:~# rm -f 987654 ; touch 123456 ; perf trace -e rename* mv 123456 987654
         0.000 ( 0.031 ms): mv/1193096 renameat2(olddfd: CWD, oldname: "123456", newdfd: CWD, newname: "987654", flags: NOREPLACE) = 0
      root@number:~# perf trace -e *nanosleep sleep 1.2345678901
           0.000 (1234.654 ms): sleep/1192697 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 234567891 }, rmtp: 0x7ffe1ea80460) = 0
      root@number:~# perf trace -e perf_event_open* perf stat -e cpu-clock sleep 1
           0.000 ( 0.011 ms): perf/1192701 perf_event_open(attr_uptr: { type: 1 (software), size: 136, config: 0 (PERF_COUNT_SW_CPU_CLOCK), sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 1192702 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
    
       Performance counter stats for 'sleep 1':
    
                    0.51 msec cpu-clock                        #    0.001 CPUs utilized
    
             1.001242090 seconds time elapsed
    
             0.000000000 seconds user
             0.001010000 seconds sys
    
      root@number:~# perf trace -e connect* ping -c 1 bsky.app
           0.000 ( 0.130 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: LOCAL, path: /run/systemd/resolve/io.systemd.Resolve }, addrlen: 42) = 0
          23.907 ( 0.006 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 3.20.108.158 }, addrlen: 16) = 0
          23.915 PING bsky.app (3.20.108.158) 56(84) bytes of data.
      ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.917 ( 0.002 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 3.12.170.30 }, addrlen: 16) = 0
          23.921 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.923 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 18.217.70.179 }, addrlen: 16) = 0
          23.925 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.927 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 3.132.20.46 }, addrlen: 16) = 0
          23.930 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.931 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 3.142.89.165 }, addrlen: 16) = 0
          23.934 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.935 ( 0.002 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 18.119.147.159 }, addrlen: 16) = 0
          23.938 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.940 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 3.22.38.164 }, addrlen: 16) = 0
          23.942 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: UNSPEC }, addrlen: 16)           = 0
          23.944 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 0, addr: 3.13.14.133 }, addrlen: 16) = 0
          23.956 ( 0.001 ms): ping/1192740 connect(fd: 5, uservaddr: { .family: INET, port: 1025, addr: 3.20.108.158 }, addrlen: 16) = 0
      ^C
      --- bsky.app ping statistics ---
      1 packets transmitted, 0 received, 100% packet loss, time 0ms
    
      root@number:~#
    Reviewed-by: default avatarIan Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Howard Chu <howardchu95@gmail.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/lkml/CAP-5=fW4=2GoP6foAN6qbrCiUzy0a_TzHbd8rvDsakTPfdzvfg@mail.gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    c90a88d3
timespec.c 708 Bytes