1. 30 7月, 2019 14 次提交
    • A
      perf trace beauty: Beautify bind's sockaddr arg · 247dd65b
      Arnaldo Carvalho de Melo 提交于
      By reusing the "connect" BPF collector.
      
      Testing it system wide and stopping/starting sshd:
      
        # perf trace -e bind
        LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        DNS Res~er #18/15132 bind(243, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #19/4833 bind(247, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #19/4833 bind(238, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/15132 bind(243, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/10327 bind(258, { .family: PF_NETLINK }, 12)  = 0
        :6507/6507 bind(24, { .family: PF_NETLINK }, 12)   = 0
        DNS Res~er #19/4833 bind(238, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/15132 bind(242, { .family: PF_NETLINK }, 12)  = 0
        sshd/6514 bind(3, { .family: PF_NETLINK }, 12)    = 0
        sshd/6514 bind(5, { .family: PF_INET, port: 22, addr: 0.0.0.0 }, 16) = 0
        sshd/6514 bind(7, { .family: PF_INET6, port: 22, addr: :: }, 28) = 0
        DNS Res~er #18/10327 bind(229, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/15132 bind(231, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #19/4833 bind(229, { .family: PF_NETLINK }, 12)  = 0
        ^C#
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-m2hmxqrckxxw2ciki0tu889u@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      247dd65b
    • A
      perf trace beauty: Do not try to use the fd->pathname beautifier for bind/connect fd arg · ef969ca6
      Arnaldo Carvalho de Melo 提交于
      Doesn't make sense and also we now beautify the sockaddr, which provides
      enough info:
      
        # trace -e close,socket,connec* ssh www.bla.com
        <SNIP>
        close(5)                                = 0
        socket(PF_INET, SOCK_DGRAM|CLOEXEC|NONBLOCK, IPPROTO_IP) = 5
        connect(5, { .family: PF_INET, port: 53, addr: 192.168.44.1 }, 16) = 0
        close(5)                                = 0
        socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 5
        ^C#
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-h9drpb7ail808d2mh4n7tla4@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ef969ca6
    • A
      perf trace beauty: Disable fd->pathname when close() not enabled · 79d725cd
      Arnaldo Carvalho de Melo 提交于
      As we invalidate the fd->pathname table in the SCA_CLOSE_FD beautifier,
      if we don't have it we may end up keeping an fd->pathname association
      that then gets misprinted.
      
      The previous behaviour continues when the close() syscall is enabled,
      which may still be a a problem if we lose records (i.e. we may lose a
      'close' record and then get that fd reused by socket()) but then the
      tool will notify that records are being lost and the user will be warned
      that some of the heuristics will fall apart.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-b7t6h8sq9lebemvfy2zh3qq1@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      79d725cd
    • A
      perf trace beauty: Make connect's addrlen be printed as an int, not hex · 1d862752
      Arnaldo Carvalho de Melo 提交于
        # perf trace -e connec* ssh www.bla.com
        connect(3</var/lib/sss/mc/passwd>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(3</var/lib/sss/mc/passwd>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(4<socket:[16610959]>, { .family: PF_LOCAL, path: /var/lib/sss/pipes/nss }, 110) = 0
        connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(5, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET, port: 53, addr: 192.168.44.1 }, 16) = 0
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET, port: 22, addr: 146.112.61.108 }, 16) = 0
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET6, port: 22, addr: ::ffff:146.112.61.108 }, 28) = 0
        ^Cconnect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET, port: 22, addr: 146.112.61.108 }, 16) = -1 (unknown) (INTERNAL ERROR: strerror_r(512, [buf], 128)=22)
        #
      
      Argh, the SCA_FD needs to invalidate its cache when close is done...
      
      It works if the 'close' syscall is not filtered out ;-\
      
        # perf trace -e close,connec* ssh www.bla.com
        close(3)                                = 0
        close(3</usr/lib64/libpcre2-8.so.0.8.0>) = 0
        close(3)                                = 0
        close(3</usr/lib64/libkrb5.so.3.3>)     = 0
        close(3</usr/lib64/libkrb5.so.3.3>)     = 0
        close(3)                                = 0
        close(3</usr/lib64/libk5crypto.so.3.1>) = 0
        close(3</usr/lib64/libk5crypto.so.3.1>) = 0
        close(3</usr/lib64/libcom_err.so.2.1>)  = 0
        close(3</usr/lib64/libcom_err.so.2.1>)  = 0
        close(3)                                = 0
        close(3</usr/lib64/libkrb5support.so.0.1>) = 0
        close(3</usr/lib64/libkrb5support.so.0.1>) = 0
        close(3</usr/lib64/libkeyutils.so.1.8>) = 0
        close(3</usr/lib64/libkeyutils.so.1.8>) = 0
        close(3)                                = 0
        close(3)                                = 0
        close(3)                                = 0
        close(3)                                = 0
        close(4)                                = 0
        close(3)                                = 0
        close(3)                                = 0
        connect(3</etc/nsswitch.conf>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        close(3</etc/nsswitch.conf>)            = 0
        connect(3</usr/lib64/libnss_sss.so.2>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        close(3</usr/lib64/libnss_sss.so.2>)    = 0
        close(3</usr/lib64/libnss_sss.so.2>)    = 0
        close(3)                                = 0
        close(3)                                = 0
        connect(4<socket:[16616519]>, { .family: PF_LOCAL, path: /var/lib/sss/pipes/nss }, 110) = 0
        ^C
        #
      
      Will disable this beautifier when 'close' is filtered out...
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-ekuiciyx4znchvy95c8p1yyi@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1d862752
    • A
      perf trace: Look for default name for entries in the syscalls prog array · 8b8044e5
      Arnaldo Carvalho de Melo 提交于
      I.e. just look for "!syscalls:sys_enter_" or "exit_" plus the syscall
      name, that way we need just to add entries to the
      augmented_raw_syscalls.c BPF source to add handlers.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-6xavwddruokp6ohs7tf4qilb@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8b8044e5
    • A
      perf augmented_raw_syscalls: Support copying two string syscall args · 8d5da264
      Arnaldo Carvalho de Melo 提交于
      Starting with the renameat and renameat2 syscall, that both receive as
      second and fourth parameters a pathname:
      
        # perf trace -e rename* mv one ANOTHER
        LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        mv: cannot stat 'one': No such file or directory
        renameat2(AT_FDCWD, "one", AT_FDCWD, "ANOTHER", RENAME_NOREPLACE) = -1 ENOENT (No such file or directory)
        #
      
      Since the per CPU scratch buffer map has space for two maximum sized
      pathnames, the verifier is satisfied that there will be no overrun.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-x2uboyg5kx2wqeru288209b6@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8d5da264
    • A
      perf augmented_raw_syscalls: Add handler for "openat" · 236dd583
      Arnaldo Carvalho de Melo 提交于
      I.e. for a syscall that has its second argument being a string, its
      difficult these days to find 'open' being used in the wild :-)
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-yf3kbzirqrukd3fb2sp5qx4p@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      236dd583
    • A
      perf trace: Handle raw_syscalls:sys_enter just like the BPF_OUTPUT augmented event · b119970a
      Arnaldo Carvalho de Melo 提交于
      So, we use a PERF_COUNT_SW_BPF_OUTPUT to output the augmented sys_enter
      payload, i.e. to output more than just the raw syscall args, and if
      something goes wrong when handling an unfiltered syscall, we bail out
      and just return 1 in the bpf program associated with
      raw_syscalls:sys_enter, meaning, don't filter that tracepoint, in which
      case what will appear in the perf ring buffer isn't the BPF_OUTPUT
      event, but the original raw_syscalls:sys_enter event with its normal
      payload.
      
      Now that we're switching to using a bpf_tail_call +
      BPF_MAP_TYPE_PROG_ARRAY we're going to use this in the common case, so a
      bug where raw_syscalls:sys_enter wasn't being handled by
      trace__sys_enter() surfaced and for  that case, instead of using the
      strace-like augmenter (trace__sys_enter()), we continued to use the
      normal generic tracepoint handler:
      
        (gdb) p evsel
        $2 = (struct perf_evsel *) 0xc03e40
        (gdb) p evsel->name
        $3 = 0xbc56c0 "raw_syscalls:sys_enter"
        (gdb) p ((struct perf_evsel *) 0xc03e40)->name
        $4 = 0xbc56c0 "raw_syscalls:sys_enter"
        (gdb) p ((struct perf_evsel *) 0xc03e40)->handler
        $5 = (void *) 0x495eb3 <trace__event_handler>
      
      This resulted in this:
      
           0.027 raw_syscalls:sys_enter:NR 12 (0, 7fcfcac64c9b, 4d, 7fcfcac64c9b, 7fcfcac6ce00, 19)
           ... [continued]: brk())                = 0x563b88677000
      
      I.e. only the sys_exit tracepoint was being properly handled, but since
      the sys_enter went to the generic trace__event_handler() we printed it
      using libtraceevent's formatter instead of 'perf trace's strace-like
      one.
      
      Fix it by setting trace__sys_enter() as the handler for
      raw_syscalls:sys_enter and setup the tp_field tracepoint field
      accessors.
      
      Now, to test it we just make raw_syscalls:sys_enter return 1 right after
      checking if the pid is filtered, making it not use
      bpf_perf_output_event() but rather ask for the tracepoint not to be
      filtered and the result is the expected one:
      
        brk(NULL)                               = 0x556f42d6e000
      
      I.e. raw_syscalls:sys_enter returns 1, gets handled by
      trace__sys_enter() and gets it combined with the raw_syscalls:sys_exit
      in a strace-like way.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-0mkocgk31nmy0odknegcby4z@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b119970a
    • A
      perf trace: Put the per-syscall entry/exit prog_array BPF map infrastructure in place · 3803a229
      Arnaldo Carvalho de Melo 提交于
      I.e. look for "syscalls_sys_enter" and "syscalls_sys_exit" BPF maps of
      type PROG_ARRAY and populate it with the handlers as specified per
      syscall, for now only 'open' is wiring it to something, in time all
      syscalls that need to copy arguments entering a syscall or returning
      from one will set these to the right handlers, reusing when possible
      pre-existing ones.
      
      Next step is to use bpf_tail_call() into that.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-t0p4u43i9vbpzs1xtowna3gb@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3803a229
    • A
      perf trace: Allow specifying the bpf prog to augment specific syscalls · 6ff8fff4
      Arnaldo Carvalho de Melo 提交于
      This is a step in the direction of being able to use a
      BPF_MAP_TYPE_PROG_ARRAY to handle syscalls that need to copy pointer
      payloads in addition to the raw tracepoint syscall args.
      
      There is a first example in
      tools/perf/examples/bpf/augmented_raw_syscalls.c for the 'open' syscall.
      
      Next step is to introduce the prog array map and use this 'open'
      augmenter, then use that augmenter in other syscalls that also only copy
      the first arg as a string, and then show how to use with a syscall that
      reads more than one filename, like 'rename', etc.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-pys4v57x5qqrybb4cery2mc8@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6ff8fff4
    • A
      perf trace: Add BPF handler for unaugmented syscalls · 5834da7f
      Arnaldo Carvalho de Melo 提交于
      Will be used to assign to syscalls that don't need augmentation, i.e.
      those with just integer args.
      
      All syscalls will be in a BPF_MAP_TYPE_PROG_ARRAY, and the
      bpf_tail_call() keyed by the syscall id will either find nothing in
      place, which means the syscall is being filtered, or a function that
      will either add things like filenames to the ring buffer, right after
      the raw syscall args, or be this unaugmented handler that will just
      return 1, meaning don't filter the original
      raw_syscalls:sys_{enter,exit} tracepoint.
      
      For now it is not really being used, this is just leg work to break the
      patch into smaller pieces.
      
      It introduces a trace__find_bpf_program_by_title() helper that in turn
      uses libbpf's bpf_object__find_program_by_title() on the BPF object with
      the __augmented_syscalls__ map. "title" is how libbpf calls the SEC()
      argument for functions, i.e. the ELF section that follows a convention
      to specify what BPF program (a function with this SEC() marking) should
      be connected to which tracepoint, kprobes, etc.
      
      In perf anything that is of the form SEC("sys:event_name") will be
      connected to that tracepoint by perf's BPF loader.
      
      In this case its something that will be bpf_tail_call()ed from either
      the "raw_syscalls:sys_enter" or "raw_syscall:sys_exit" tracepoints, so
      its named "!raw_syscalls:unaugmented" to convey that idea, i.e. its not
      going to be directly attached to a tracepoint, thus it starts with a
      "!".
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-meucpjx2u0slpkayx56lxqq6@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5834da7f
    • A
      perf trace: Order -e syscalls table · 83e69b92
      Arnaldo Carvalho de Melo 提交于
      The ev_qualifier is an array with the syscall ids passed via -e on the
      command line, sort it as we'll search it when setting up the
      BPF_MAP_TYPE_PROG_ARRAY.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-c8hprylp3ai6e0z9burn2r3s@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      83e69b92
    • A
      perf trace: Look up maps just on the __augmented_syscalls__ BPF object · 5ca0b7f5
      Arnaldo Carvalho de Melo 提交于
      We can conceivably have multiple BPF object files for other purposes, so
      better look just on the BPF object containing the __augmented_syscalls__
      map for all things augmented_syscalls related.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-3jt8knkuae9lt705r1lns202@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5ca0b7f5
    • A
      perf trace: Add pointer to BPF object containing __augmented_syscalls__ · c8c80570
      Arnaldo Carvalho de Melo 提交于
      So that we can use it when looking for other components of that object
      file, such as other programs to add to the BPF_MAP_TYPE_PROG_ARRAY and
      use with bpf_tail_call().
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-1ibmz7ouv6llqxajy7m8igtd@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c8c80570
  2. 10 7月, 2019 1 次提交
    • A
      perf trace: Auto bump rlimit(MEMLOCK) for eBPF maps sake · c3e78a34
      Arnaldo Carvalho de Melo 提交于
      Circa v5.2 this started to fail:
      
        # perf trace -e /wb/augmented_raw_syscalls.o
        event syntax error: '/wb/augmented_raw_syscalls.o'
                             \___ Operation not permitted
      
        (add -v to see detail)
        Run 'perf list' for a list of valid events
      
         Usage: perf trace [<options>] [<command>]
            or: perf trace [<options>] -- <command> [<options>]
            or: perf trace record [<options>] [<command>]
            or: perf trace record [<options>] -- <command> [<options>]
      
            -e, --event <event>   event/syscall selector. use 'perf list' to list available events
        #
      
      In verbose mode we some -EPERM when creating a BPF map:
      
        # perf trace -v -e /wb/augmented_raw_syscalls.o
        <SNIP>
        libbpf: failed to create map (name: '__augmented_syscalls__'): Operation not permitted
        libbpf: failed to load object '/wb/augmented_raw_syscalls.o'
        bpf: load objects failed: err=-1: (Operation not permitted)
        event syntax error: '/wb/augmented_raw_syscalls.o'
                             \___ Operation not permitted
      
        (add -v to see detail)
        Run 'perf list' for a list of valid events
      
         Usage: perf trace [<options>] [<command>]
            or: perf trace [<options>] -- <command> [<options>]
            or: perf trace record [<options>] [<command>]
            or: perf trace record [<options>] -- <command> [<options>]
      
            -e, --event <event>   event/syscall selector. use 'perf list' to list available events
        #
      
      If we bumped 'ulimit -l 128' to get it from the 64k default to double that, it
      worked, so use the recently added rlimit__bump_memlock() helper:
      
        # perf trace -e /wb/augmented_raw_syscalls.o -e open*,*sleep sleep 1
             0.000 ( 0.007 ms): sleep/28042 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3
             0.022 ( 0.004 ms): sleep/28042 openat(dfd: CWD, filename: "/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3
             0.201 ( 0.007 ms): sleep/28042 openat(dfd: CWD, filename: "", flags: RDONLY|CLOEXEC)                 = 3
             0.241 (1000.421 ms): sleep/28042 nanosleep(rqtp: 0x7ffd6c3e6ed0)                                       = 0
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-j6f2ioa6hj9dinzpjvlhcjoc@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c3e78a34
  3. 09 7月, 2019 2 次提交
    • A
      tools lib: Adopt zalloc()/zfree() from tools/perf · 7f7c536f
      Arnaldo Carvalho de Melo 提交于
      Eroding a bit more the tools/perf/util/util.h hodpodge header.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-natazosyn9rwjka25tvcnyi0@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7f7c536f
    • L
      perf trace: Fix potential NULL pointer dereference found by the smatch tool · 7a6d49dc
      Leo Yan 提交于
      Based on the following report from Smatch, fix the potential NULL
      pointer dereference check.
      
        tools/perf/builtin-trace.c:1044
        thread_trace__new() error: we previously assumed 'ttrace' could be
        null (see line 1041).
      
        tools/perf/builtin-trace.c
        1037 static struct thread_trace *thread_trace__new(void)
        1038 {
        1039         struct thread_trace *ttrace =  zalloc(sizeof(struct thread_trace));
        1040
        1041         if (ttrace)
        1042                 ttrace->files.max = -1;
        1043
        1044         ttrace->syscall_stats = intlist__new(NULL);
                     ^^^^^^^^
        1045
        1046         return ttrace;
        1047 }
      Signed-off-by: NLeo Yan <leo.yan@linaro.org>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Alexios Zavras <alexios.zavras@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Changbin Du <changbin.du@intel.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Eric Saint-Etienne <eric.saint.etienne@oracle.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Link: http://lkml.kernel.org/r/20190702103420.27540-6-leo.yan@linaro.org
      [ Just made it look like other tools/perf constructors, same end result ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7a6d49dc
  4. 26 6月, 2019 1 次提交
    • A
      tools perf: Move from sane_ctype.h obtained from git to the Linux's original · 3052ba56
      Arnaldo Carvalho de Melo 提交于
      We got the sane_ctype.h headers from git and kept using it so far, but
      since that code originally came from the kernel sources to the git
      sources, perhaps its better to just use the one in the kernel, so that
      we can leverage tools/perf/check_headers.sh to be notified when our copy
      gets out of sync, i.e. when fixes or goodies are added to the code we've
      copied.
      
      This will help with things like tools/lib/string.c where we want to have
      more things in common with the kernel, such as strim(), skip_spaces(),
      etc so as to go on removing the things that we have in tools/perf/util/
      and instead using the code in the kernel, indirectly and removing things
      like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements
      are made to the original code.
      
      Hopefully this also should help with reducing the difference of code
      hosted in tools/ to the one in the kernel proper.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxygn12@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3052ba56
  5. 18 6月, 2019 3 次提交
    • A
      perf trace: Fixup pointer arithmetic when consuming augmented syscall args · 016f327c
      Arnaldo Carvalho de Melo 提交于
      We can't just add the consumed bytes to the arg->augmented.args member,
      as it is not void *, so it will access (consumed * sizeof(struct augmented_arg))
      in the next augmented arg, totally wrong, cast the member to void pointe
      before adding the number of bytes consumed, duh.
      
      With this and hardcoding handling the 'renameat' and 'renameat2'
      syscalls in the tools/perf/examples/bpf/augmented_raw_syscalls.c eBPF
      proggie, we get:
      
      	mv/24388 renameat2(AT_FDCWD, "/tmp/build/perf/util/.bpf-event.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.bpf-event.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24394 renameat2(AT_FDCWD, "/tmp/build/perf/util/.perf-hooks.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.perf-hooks.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24398 renameat2(AT_FDCWD, "/tmp/build/perf/util/.pmu-bison.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.pmu-bison.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24401 renameat2(AT_FDCWD, "/tmp/build/perf/util/.expr-bison.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.expr-bison.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24406 renameat2(AT_FDCWD, "/tmp/build/perf/util/.pmu.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.pmu.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24407 renameat2(AT_FDCWD, "/tmp/build/perf/util/.pmu-flex.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.pmu-flex.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24416 renameat2(AT_FDCWD, "/tmp/build/perf/util/.parse-events-flex.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.parse-events-flex.o.cmd", RENAME_NOREPLACE) = 0
      
      I.e. it works with two string args in the same syscall.
      
      Now back to taming the verifier...
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Fixes: 8195168e ("perf trace: Consume the augmented_raw_syscalls payload")
      Link: https://lkml.kernel.org/n/tip-n1w59lpxks6m1le7fpo6rmyw@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      016f327c
    • A
      perf trace: Streamline validation of select syscall names list · 99f26f85
      Arnaldo Carvalho de Melo 提交于
      Rename the 'i' variable to 'nr_used' and use set 'nr_allocated' since
      the start of this function, leaving the final assignment of the longer
      named trace->ev_qualifier_ids.nr state to 'nr_used' at the end of the
      function.
      
      No change in behaviour intended.
      
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Link: https://lkml.kernel.org/n/tip-kpgyn8xjdjgt0timrrnniquv@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      99f26f85
    • A
      perf trace: Fix exclusion of not available syscall names from selector list · a4066d64
      Arnaldo Carvalho de Melo 提交于
      We were just skipping the syscalls not available in a particular
      architecture without reflecting this in the number of entries in the
      ev_qualifier_ids.nr variable, fix it.
      
      This was done with the most minimalistic way, reusing the index variable
      'i', a followup patch will further clean this by making 'i' renamed to
      'nr_used' and using 'nr_allocated' in a few more places.
      Reported-by: NLeo Yan <leo.yan@linaro.org>
      Tested-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Fixes: 04c41bcb ("perf trace: Skip unknown syscalls when expanding strace like syscall groups")
      Link: https://lkml.kernel.org/r/20190613181514.GC1402@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a4066d64
  6. 11 6月, 2019 2 次提交
    • A
      perf trace: Skip unknown syscalls when expanding strace like syscall groups · 04c41bcb
      Arnaldo Carvalho de Melo 提交于
      We have $INSTALL_DIR/share/perf-core/strace/groups/string files with
      syscalls that should be selected when 'string' is used, meaning, in this
      case, syscalls that receive as one of its arguments a string, like a
      pathname.
      
      But those were first selected and tested on x86_64, and end up failing
      in architectures where some of those syscalls are not available, like
      the 'access' syscall on arm64, which makes using 'perf trace -e string'
      in such archs to fail.
      
      Since this the routine doing the validation is used only when reading
      such files, do not fail when some syscall is not found in the
      syscalltbl, instead just use pr_debug() to register that in case people
      are suspicious of problems.
      
      Now using 'perf trace -e string' should work on arm64, selecting only
      the syscalls that have a string and are available on that architecture.
      Reported-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Cc: Yonghong Song <yhs@fb.com>
      Link: https://lkml.kernel.org/r/20190610184754.GU21245@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      04c41bcb
    • L
      perf trace: Exit when failing to build eBPF program · 012749ca
      Leo Yan 提交于
      On my Juno board with ARM64 CPUs, perf trace command reports the eBPF
      program building failure but the command will not exit and continue to
      run.  If we define an eBPF event in config file, the event will be
      parsed with below flow:
      
        perf_config()
          `> trace__config()
               `> parse_events_option()
                    `> parse_events__scanner()
                         `-> parse_events_parse()
                               `> parse_events_load_bpf()
                                    `> llvm__compile_bpf()
      
      Though the low level functions return back error values when detect eBPF
      building failure, but parse_events_option() returns 1 for this case and
      trace__config() passes 1 to perf_config(); perf_config() doesn't treat
      the returned value 1 as failure and it continues to parse other
      configurations.  Thus the perf command continues to run even without
      enabling eBPF event successfully.
      
      This patch changes error handling in trace__config(), when it detects
      failure it will return -1 rather than directly pass error value (1);
      finally, perf_config() will directly bail out and perf will exit for
      this case.
      
      Committer notes:
      
      Simplified the patch to just check directly the return of
      parse_events_option() and it it is non-zero, change err from its initial
      zero value to -1.
      Signed-off-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Yonghong Song <yhs@fb.com>
      Fixes: ac96287c ("perf trace: Allow specifying a set of events to add in perfconfig")
      Link: https://lkml.kernel.org/n/tip-x4i63f5kscykfok0hqim3zma@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      012749ca
  7. 05 6月, 2019 4 次提交
  8. 29 5月, 2019 6 次提交
    • A
      perf trace: Beautify 'sync_file_range' arguments · a9a187a7
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first arg, fd, assigned using the
      heuristic that looks for syscall arg names and associates SCA_FD with
      'fd' named argumes, and wire up the recently introduced sync_file_range
      flags table generator.
      
      Now it should be possible to just use:
      
         perf trace -e sync_file_range
      
      As root and see all sync_file_range syscalls with its args beautified.
      
        Doing a syscall strace like session looking for this syscall, then run
        postgresql's initdb command:
      
        # perf trace -e sync_file_range
        <SNIP>
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(7</var/lib/pgsql/data/base/1/2682>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(7</var/lib/pgsql/data/base/1/2682>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(4</var/lib/pgsql/data>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(4</var/lib/pgsql/data>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        ^C
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Amir Goldstein <amir73il@gmail.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-8tqy34xhpg8gwnaiv74xy93w@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a9a187a7
    • A
      perf trace: Beautify 'fsmount' arguments · f6af0956
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first arg, fd, assigned using the
      heuristic that looks for syscall arg names and associates SCA_FD with
      'fd' named argumes, and wire up the recently introduced fsmount
      attr_flags table generator.
      
      Now it should be possible to just use:
      
         perf trace -e fsmount
      
      As root and see all fsmount syscalls with its args beautified.
      
        # cat sys_fsmount.c
        #define _GNU_SOURCE        /* See feature_test_macros(7) */
        #include <unistd.h>
        #include <sys/syscall.h>   /* For SYS_xxx definitions */
      
        #define __NR_fsmount 432
      
        #define MOUNT_ATTR_RDONLY	 0x00000001 /* Mount read-only */
        #define MOUNT_ATTR_NOSUID	 0x00000002 /* Ignore suid and sgid bits */
        #define MOUNT_ATTR_NODEV	 0x00000004 /* Disallow access to device special files */
        #define MOUNT_ATTR_NOEXEC	 0x00000008 /* Disallow program execution */
        #define MOUNT_ATTR__ATIME	 0x00000070 /* Setting on how atime should be updated */
        #define MOUNT_ATTR_RELATIME	 0x00000000 /* - Update atime relative to mtime/ctime. */
        #define MOUNT_ATTR_NOATIME	 0x00000010 /* - Do not update access times. */
        #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
        #define MOUNT_ATTR_NODIRATIME	 0x00000080 /* Do not update directory access times */
      
        static inline int sys_fsmount(int fs_fd, int flags, int attr_flags)
        {
        	syscall(__NR_fsmount, fs_fd, flags, attr_flags);
        }
      
        int main(int argc, char *argv[])
        {
        	int attr_flags = 0, fs_fd = 0;
      
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_RDONLY;
        	sys_fsmount(fs_fd++, 1, attr_flags);
        	attr_flags |= MOUNT_ATTR_NOSUID;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_NODEV;
        	sys_fsmount(fs_fd++, 1, attr_flags);
        	attr_flags |= MOUNT_ATTR_NOEXEC;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_NOATIME;
        	sys_fsmount(fs_fd++, 1, attr_flags);
        	attr_flags |= MOUNT_ATTR_STRICTATIME;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_NODIRATIME;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	return 0;
        }
        #
        # perf trace -e fsmount ./sys_fsmount
        fsmount(0, 0, MOUNT_ATTR_RELATIME)      = -1 EINVAL (Invalid argument)
        fsmount(1, FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY|MOUNT_ATTR_RELATIME) = -1 EINVAL (Invalid argument)
        fsmount(2, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_RELATIME) = -1 EINVAL (Invalid argument)
        fsmount(3, FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_RELATIME) = -1 EBADF (Bad file descriptor)
        fsmount(4, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_RELATIME) = -1 EBADF (Bad file descriptor)
        fsmount(5, FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME) = -1 EBADF (Bad file descriptor)
        fsmount(6, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME|MOUNT_ATTR_STRICTATIME) = -1 EINVAL (Invalid argument)
        fsmount(7, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME|MOUNT_ATTR_STRICTATIME|MOUNT_ATTR_NODIRATIME) = -1 EINVAL (Invalid argument)
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-w71uge0sfo6ns9uclhwtthca@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f6af0956
    • A
      perf trace: Introduce syscall_arg__scnprintf_strarray_flags · f5b91dbb
      Arnaldo Carvalho de Melo 提交于
      So that one can just define a strarray and process it as a set of flags,
      similar to syscall_arg__scnprintf_strarray() with plain arrays.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-nnt25wkpkow2w0yefhi6sb7q@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f5b91dbb
    • A
      perf trace: Beautify 'fsconfig' arguments · dcc6fd64
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first arg, fd, assigned using the
      heuristic that looks for syscall arg names and associates SCA_FD with
      'fd' named argumes, and wire up the recently introduced fsconfig cmd
      table generator.
      
      Now it should be possible to just use:
      
         perf trace -e fsconfig
      
      As root and see all fsconfig syscalls with its args beautified, more
      work needed to look at the command and according to it handle the 'key',
      'value' and 'aux' args, using the 'fcntl' and 'futex' beautifiers as a
      starting point to see how to suppress sets of these last three args that
      may not be used by the 'cmd' arg, etc.
      
        # cat sys_fsconfig.c
        #define _GNU_SOURCE         /* See feature_test_macros(7) */
        #include <unistd.h>
        #include <sys/syscall.h>   /* For SYS_xxx definitions */
        #include <fcntl.h>
      
        #define __NR_fsconfig 431
      
        enum fsconfig_command {
        	FSCONFIG_SET_FLAG	= 0,	/* Set parameter, supplying no value */
        	FSCONFIG_SET_STRING	= 1,	/* Set parameter, supplying a string value */
        	FSCONFIG_SET_BINARY	= 2,	/* Set parameter, supplying a binary blob value */
        	FSCONFIG_SET_PATH	= 3,	/* Set parameter, supplying an object by path */
        	FSCONFIG_SET_PATH_EMPTY	= 4,	/* Set parameter, supplying an object by (empty) path */
        	FSCONFIG_SET_FD		= 5,	/* Set parameter, supplying an object by fd */
        	FSCONFIG_CMD_CREATE	= 6,	/* Invoke superblock creation */
        	FSCONFIG_CMD_RECONFIGURE = 7,	/* Invoke superblock reconfiguration */
        };
      
        static inline int sys_fsconfig(int fd, int cmd, const char *key, const void *value, int aux)
        {
        	syscall(__NR_fsconfig, fd, cmd, key, value, aux);
        }
      
        int main(int argc, char *argv[])
        {
        	int fd = 0, aux = 0;
      
        	open("/foo", 0);
        	sys_fsconfig(fd++, FSCONFIG_SET_FLAG,	     "/foo1", "/bar1", aux++);
        	sys_fsconfig(fd++, FSCONFIG_SET_STRING,	     "/foo2", "/bar2", aux++);
        	sys_fsconfig(fd++, FSCONFIG_SET_BINARY,	     "/foo3", "/bar3", aux++);
        	sys_fsconfig(fd++, FSCONFIG_SET_PATH,	     "/foo4", "/bar4", aux++);
        	sys_fsconfig(fd++, FSCONFIG_SET_PATH_EMPTY,  "/foo5", "/bar5", aux++);
        	sys_fsconfig(fd++, FSCONFIG_SET_FD,	     "/foo6", "/bar6", aux++);
        	sys_fsconfig(fd++, FSCONFIG_CMD_CREATE,	     "/foo7", "/bar7", aux++);
        	sys_fsconfig(fd++, FSCONFIG_CMD_RECONFIGURE, "/foo8", "/bar8", aux++);
        	return 0;
        }
        # trace -e fsconfig ./sys_fsconfig
        fsconfig(0, FSCONFIG_SET_FLAG, 0x40201b, 0x402015, 0) = -1 EINVAL (Invalid argument)
        fsconfig(1, FSCONFIG_SET_STRING, 0x402027, 0x402021, 1) = -1 EINVAL (Invalid argument)
        fsconfig(2, FSCONFIG_SET_BINARY, 0x402033, 0x40202d, 2) = -1 EINVAL (Invalid argument)
        fsconfig(3, FSCONFIG_SET_PATH, 0x40203f, 0x402039, 3) = -1 EBADF (Bad file descriptor)
        fsconfig(4, FSCONFIG_SET_PATH_EMPTY, 0x40204b, 0x402045, 4) = -1 EBADF (Bad file descriptor)
        fsconfig(5, FSCONFIG_SET_FD, 0x402057, 0x402051, 5) = -1 EINVAL (Invalid argument)
        fsconfig(6, FSCONFIG_CMD_CREATE, 0x402063, 0x40205d, 6) = -1 EINVAL (Invalid argument)
        fsconfig(7, FSCONFIG_CMD_RECONFIGURE, 0x40206f, 0x402069, 7) = -1 EINVAL (Invalid argument)
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-fb04b76cm59zfuv1wzu40uxy@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      dcc6fd64
    • A
      perf trace: Beautify 'fspick' arguments · 693bd394
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first 2 args (dfd, path) and wire up
      the recently introduced fspick flags table generator.
      
      Now it should be possible to just use:
      
         perf trace -e fspick
      
      As root and see all move_mount syscalls with its args beautified, either
      using the vfs_getname perf probe method or using the
      augmented_raw_syscalls.c eBPF helper to get the pathnames, the other
      args should work in all cases, i.e. all that is needed can be obtained
      directly from the raw_syscalls:sys_enter tracepoint args.
      
        # cat sys_fspick.c
        #define _GNU_SOURCE        /* See feature_test_macros(7) */
        #include <unistd.h>
        #include <sys/syscall.h>   /* For SYS_xxx definitions */
        #include <fcntl.h>
      
        #define __NR_fspick 433
      
        #define FSPICK_CLOEXEC          0x00000001
        #define FSPICK_SYMLINK_NOFOLLOW 0x00000002
        #define FSPICK_NO_AUTOMOUNT     0x00000004
        #define FSPICK_EMPTY_PATH       0x00000008
      
        static inline int sys_fspick(int fd, const char *path, int flags)
        {
        	syscall(__NR_fspick, fd, path, flags);
        }
      
        int main(int argc, char *argv[])
        {
        	int flags = 0, fd = 0;
      
        	open("/foo", 0);
        	sys_fspick(fd++, "/foo1", flags);
        	flags |= FSPICK_CLOEXEC;
        	sys_fspick(fd++, "/foo2", flags);
        	flags |= FSPICK_SYMLINK_NOFOLLOW;
        	sys_fspick(fd++, "/foo3", flags);
        	flags |= FSPICK_NO_AUTOMOUNT;
        	sys_fspick(fd++, "/foo4", flags);
        	flags |= FSPICK_EMPTY_PATH;
        	return sys_fspick(fd++, "/foo5", flags);
        }
        # perf trace -e fspick ./sys_fspick
        LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        fspick(0, "/foo1", 0)                   = -1 ENOENT (No such file or directory)
        fspick(1, "/foo2", FSPICK_CLOEXEC)      = -1 ENOENT (No such file or directory)
        fspick(2, "/foo3", FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
        fspick(3, "/foo4", FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW|FSPICK_NO_AUTOMOUNT) = -1 ENOENT (No such file or directory)
        fspick(4, "/foo5", FSPICK_CLOEXEC|FSPICK_SYMLINK_NOFOLLOW|FSPICK_NO_AUTOMOUNT|FSPICK_EMPTY_PATH) = -1 ENOENT (No such file or directory)
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-erau5xjtt8wvgnhvdbchstuk@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      693bd394
    • A
      perf trace: Beautify 'move_mount' arguments · 566e3022
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first 4 args (to/from fds, pathnames)
      and wire up the recently introduced move_mount flags table generator.
      
      Now it should be possible to just use:
      
            perf trace -e move_mount
      
      As root and see all move_mount syscalls with its args beautified, except
      for the filenames, that need work in the augmented_raw_syscalls.c eBPF
      helper to pass more than one, see comment in the
      augmented_raw_syscalls.c source code, the other args should work in all
      cases, i.e. all that is needed can be obtained directly from the
      raw_syscalls:sys_enter tracepoint args.
      
      Running without the strace "skin" (.perfconfig setting output formatting
      switches to look like strace output + BPF to collect strings, as we
      still need to support collecting multiple string args for the same
      syscall, like with move_mount):
      
        # cat sys_move_mount.c
        #define _GNU_SOURCE         /* See feature_test_macros(7) */
        #include <unistd.h>
        #include <sys/syscall.h>   /* For SYS_xxx definitions */
      
        #define __NR_move_mount 429
      
        #define MOVE_MOUNT_F_SYMLINKS		0x00000001 /* Follow symlinks on from path */
        #define MOVE_MOUNT_F_AUTOMOUNTS		0x00000002 /* Follow automounts on from path */
        #define MOVE_MOUNT_F_EMPTY_PATH		0x00000004 /* Empty from path permitted */
        #define MOVE_MOUNT_T_SYMLINKS		0x00000010 /* Follow symlinks on to path */
        #define MOVE_MOUNT_T_AUTOMOUNTS		0x00000020 /* Follow automounts on to path */
        #define MOVE_MOUNT_T_EMPTY_PATH		0x00000040 /* Empty to path permitted */
      
        static inline int sys_move_mount(int from_fd, const char *from_pathname,
        				 int to_fd, const char *to_pathname,
        				 int flags)
        {
        	  syscall(__NR_move_mount, from_fd, from_pathname, to_fd, to_pathname, flags);
        }
      
        int main(int argc, char *argv[])
        {
        	  int flags = 0, from_fd = 0, to_fd = 100;
      
        	  sys_move_mount(from_fd++, "/foo", to_fd++, "bar", flags);
        	  flags |= MOVE_MOUNT_F_SYMLINKS;
        	  sys_move_mount(from_fd++, "/foo1", to_fd++, "bar1", flags);
                flags |= MOVE_MOUNT_F_AUTOMOUNTS;
        	  sys_move_mount(from_fd++, "/foo2", to_fd++, "bar2", flags);
                flags |= MOVE_MOUNT_F_EMPTY_PATH;
        	  sys_move_mount(from_fd++, "/foo3", to_fd++, "bar3", flags);
                flags |= MOVE_MOUNT_T_SYMLINKS;
        	  sys_move_mount(from_fd++, "/foo4", to_fd++, "bar4", flags);
                flags |= MOVE_MOUNT_T_AUTOMOUNTS;
        	  sys_move_mount(from_fd++, "/foo5", to_fd++, "bar5", flags);
                flags |= MOVE_MOUNT_T_EMPTY_PATH;
        	  return sys_move_mount(from_fd++, "/foo6", to_fd++, "bar6", flags);
        }
        # mv ~/.perfconfig  ~/.perfconfig.OFF
        # perf trace -e move_mount ./sys_move_mount
             0.000 ( 0.009 ms): sys_move_mount/28971 move_mount(from_pathname: 0x402010, to_dfd: 100, to_pathname: 0x402015) = -1 ENOENT (No such file or directory)
             0.011 ( 0.003 ms): sys_move_mount/28971 move_mount(from_dfd: 1, from_pathname: 0x40201e, to_dfd: 101, to_pathname: 0x402019, flags: F_SYMLINKS) = -1 ENOENT (No such file or directory)
             0.016 ( 0.002 ms): sys_move_mount/28971 move_mount(from_dfd: 2, from_pathname: 0x402029, to_dfd: 102, to_pathname: 0x402024, flags: F_SYMLINKS|F_AUTOMOUNTS) = -1 ENOENT (No such file or directory)
             0.020 ( 0.002 ms): sys_move_mount/28971 move_mount(from_dfd: 3, from_pathname: 0x402034, to_dfd: 103, to_pathname: 0x40202f, flags: F_SYMLINKS|F_AUTOMOUNTS|F_EMPTY_PATH) = -1 ENOENT (No such file or directory)
             0.023 ( 0.002 ms): sys_move_mount/28971 move_mount(from_dfd: 4, from_pathname: 0x40203f, to_dfd: 104, to_pathname: 0x40203a, flags: F_SYMLINKS|F_AUTOMOUNTS|F_EMPTY_PATH|T_SYMLINKS) = -1 ENOENT (No such file or directory)
             0.027 ( 0.002 ms): sys_move_mount/28971 move_mount(from_dfd: 5, from_pathname: 0x40204a, to_dfd: 105, to_pathname: 0x402045, flags: F_SYMLINKS|F_AUTOMOUNTS|F_EMPTY_PATH|T_SYMLINKS|T_AUTOMOUNTS) = -1 ENOENT (No such file or directory)
             0.031 ( 0.017 ms): sys_move_mount/28971 move_mount(from_dfd: 6, from_pathname: 0x402055, to_dfd: 106, to_pathname: 0x402050, flags: F_SYMLINKS|F_AUTOMOUNTS|F_EMPTY_PATH|T_SYMLINKS|T_AUTOMOUNTS|T_EMPTY_PATH) = -1 ENOENT (No such file or directory)
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-83rim8g4k0s4gieieh5nnlck@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      566e3022
  9. 23 2月, 2019 1 次提交
    • J
      perf data: Add global path holder · 2d4f2799
      Jiri Olsa 提交于
      Add a 'path' member to 'struct perf_data'. It will keep the configured
      path for the data (const char *). The path in struct perf_data_file is
      now dynamically allocated (duped) from it.
      
      This scheme is useful/used in following patches where struct
      perf_data::path holds the 'configure' directory path and struct
      perf_data_file::path holds the allocated path for specific files.
      
      Also it actually makes the code little simpler.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lkml.kernel.org/r/20190221094145.9151-3-jolsa@kernel.org
      [ Fixup data-convert-bt.c missing conversion ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      2d4f2799
  10. 20 2月, 2019 1 次提交
    • A
      perf trace: Allow dumping a BPF map after setting up BPF events · ff7a4f98
      Arnaldo Carvalho de Melo 提交于
      Initial use case:
      
      Dumping the maps setup by tools/perf/examples/bpf/augmented_raw_syscalls.c,
      which so far are just booleans, showing just non-zeroed entries:
      
        # cat ~/.perfconfig
        [llvm]
      	dump-obj = true
      	clang-opt = -g
        [trace]
      	#add_events = /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
      	add_events = /wb/augmented_raw_syscalls.o
        $ date
        Tue Feb 19 16:29:33 -03 2019
        $ ls -la /wb/augmented_raw_syscalls.o
        -rwxr-xr-x. 1 root root 14048 Jan 24 12:09 /wb/augmented_raw_syscalls.o
        $ file /wb/augmented_raw_syscalls.o
        /wb/augmented_raw_syscalls.o: ELF 64-bit LSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped
        $
        # trace -e recvmmsg,sendmmsg --map-dump foobar
        ERROR: BPF map "foobar" not found
        # trace -e recvmmsg,sendmmsg --map-dump filtered_pids
        ERROR: BPF map "filtered_pids" not found
        # trace -e recvmmsg,sendmmsg --map-dump pids_filtered
        [2583] = 1,
        [2267] = 1,
        ^Z
        [1]+  Stopped                 trace -e recvmmsg,sendmmsg --map-dump pids_filtered
        # pidof trace
        2267
        # ps ax|grep gnome-terminal|grep -v grep
        2583 ?        Ssl   58:33 /usr/libexec/gnome-terminal-server
        ^C
        # trace -e recvmmsg,sendmmsg --map-dump syscalls
        [299] = 1,
        [307] = 1,
        ^C
        # grep x64_recvmmsg arch/x86/entry/syscalls/syscall_64.tbl
        299	64	recvmmsg		__x64_sys_recvmmsg
        # grep x64_sendmmsg arch/x86/entry/syscalls/syscall_64.tbl
        307	64	sendmmsg		__x64_sys_sendmmsg
        #
      
      Next step probably will be something like 'perf stat's --interval-print and
      --interval-clear.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Yonghong Song <yhs@fb.com>
      Link: https://lkml.kernel.org/n/tip-ztxj25rtx37ixo9cfajt8ocy@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ff7a4f98
  11. 15 2月, 2019 2 次提交
    • A
      perf trace: Filter out gnome-terminal* parent · ca2da70c
      Arnaldo Carvalho de Melo 提交于
      Just like it does with 'sshd', to reduce the feedback loop when doing
      system wide tracing on on a gnome GUI.
      
      Need to figure out how to auto-filter the calls to other UI components
      tho.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-rjopq5y92itgokppdhe8sc6z@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ca2da70c
    • A
      perf trace: Check if the 'fd' is negative when mapping it to pathname · 05107486
      Arnaldo Carvalho de Melo 提交于
      We were crashing when processing a negative fd:
      
        Program received signal SIGSEGV, Segmentation fault.
        0x0000000000609bbf in syscall_arg__scnprintf_ioctl_cmd (bf=0x1172eca "", size=2038, arg=0x7fffffff8360) at trace/beauty/ioctl.c:182
        182			if (file->dev_maj == USB_DEVICE_MAJOR)
        Missing separate debuginfos, use: dnf debuginfo-install bzip2-libs-1.0.6-28.fc29.x86_64 elfutils-libelf-0.174-5.fc29.x86_64 elfutils-libs-0.174-5.fc29.x86_64 glib2-2.58.3-1.fc29.x86_64 libbabeltrace-1.5.6-1.fc29.x86_64 libunwind-1.2.1-6.fc29.x86_64 libuuid-2.32.1-1.fc29.x86_64 libxcrypt-4.4.3-2.fc29.x86_64 numactl-libs-2.0.12-1.fc29.x86_64 openssl-libs-1.1.1a-1.fc29.x86_64 pcre-8.42-6.fc29.x86_64 perl-libs-5.28.1-427.fc29.x86_64 popt-1.16-15.fc29.x86_64 python2-libs-2.7.15-11.fc29.x86_64 slang-2.3.2-4.fc29.x86_64 xz-libs-5.2.4-3.fc29.x86_64
        (gdb) bt
        #0  0x0000000000609bbf in syscall_arg__scnprintf_ioctl_cmd (bf=0x1172eca "", size=2038, arg=0x7fffffff8360) at trace/beauty/ioctl.c:182
        #1  0x000000000048e295 in syscall__scnprintf_val (sc=0x123b500, bf=0x1172eca "", size=2038, arg=0x7fffffff8360, val=21519)
            at builtin-trace.c:1594
        #2  0x000000000048e60d in syscall__scnprintf_args (sc=0x123b500, bf=0x1172ec6 "-1, ", size=2042, args=0x7ffff6a7c034 "\377\377\377\377",
            augmented_args=0x7ffff6a7c064, augmented_args_size=4, trace=0x7fffffffa8d0, thread=0x1175cd0) at builtin-trace.c:1661
        #3  0x000000000048f04e in trace__sys_enter (trace=0x7fffffffa8d0, evsel=0xb260b0, event=0x7ffff6a7bfe8, sample=0x7fffffff84f0)
            at builtin-trace.c:1880
        #4  0x00000000004915a4 in trace__handle_event (trace=0x7fffffffa8d0, event=0x7ffff6a7bfe8, sample=0x7fffffff84f0) at builtin-trace.c:2590
        #5  0x0000000000491eed in __trace__deliver_event (trace=0x7fffffffa8d0, event=0x7ffff6a7bfe8) at builtin-trace.c:2818
        #6  0x0000000000492030 in trace__deliver_event (trace=0x7fffffffa8d0, event=0x7ffff6a7bfe8) at builtin-trace.c:2845
        #7  0x0000000000492896 in trace__run (trace=0x7fffffffa8d0, argc=0, argv=0x7fffffffdb58) at builtin-trace.c:3040
        #8  0x000000000049603a in cmd_trace (argc=0, argv=0x7fffffffdb58) at builtin-trace.c:3952
        #9  0x00000000004d5103 in main (argc=1, argv=0x7fffffffdb58) at perf.c:474
        (gdb) p fd
        $1 = -1
        (gdb) p file
        $7 = (struct file *) 0xfffffffffffffff0
        (gdb) p ((struct thread_trace *)arg->thread)->files.table + fd
        $8 = (struct file *) 0xfffffffffffffff0
        (gdb)
      
      Check for that and return NULL instead.
      
      This problem was introduced recently, the other codepaths leading to
      thread_trace__files_entry() check for negative fds, like thread__fd_path(),
      but we need to do it at thread_trace__files_entry() as more users are now
      calling it directly.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: 2d473389 ("perf trace beauty: Export function to get the files for a thread")
      Link: https://lkml.kernel.org/n/tip-oq7bvaaf07gsd4yqty3107u2@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      05107486
  12. 06 2月, 2019 2 次提交
  13. 05 2月, 2019 1 次提交
    • A
      perf trace: Support multiple "vfs_getname" probes · 6ab3bc24
      Arnaldo Carvalho de Melo 提交于
      With a suitably defined "probe:vfs_getname" probe, 'perf trace' can
      "beautify" its output, so syscalls like open() or openat() can print the
      "filename" argument instead of just its hex address, like:
      
        $ perf trace -e open -- touch /dev/null
        [...]
             0.590 ( 0.014 ms): touch/18063 open(filename: /dev/null, flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3
        [...]
      
      The output without such beautifier looks like:
      
           0.529 ( 0.011 ms): touch/18075 open(filename: 0xc78cf288, flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3
      
      However, when the vfs_getname probe expands to multiple probes and it is
      not the first one that is hit, the beautifier fails, as following:
      
           0.326 ( 0.010 ms): touch/18072 open(filename: , flags: CREAT|NOCTTY|NONBLOCK|WRONLY, mode: IRUGO|IWUGO) = 3
      
      Fix it by hooking into all the expanded probes (inlines), now, for instance:
      
        [root@quaco ~]# perf probe -l
          probe:vfs_getname    (on getname_flags:73@fs/namei.c with pathname)
          probe:vfs_getname_1  (on getname_flags:73@fs/namei.c with pathname)
        [root@quaco ~]# perf trace -e open* sleep 1
             0.010 ( 0.005 ms): sleep/5588 openat(dfd: CWD, filename: /etc/ld.so.cache, flags: RDONLY|CLOEXEC)   = 3
             0.029 ( 0.006 ms): sleep/5588 openat(dfd: CWD, filename: /lib64/libc.so.6, flags: RDONLY|CLOEXEC)   = 3
             0.194 ( 0.008 ms): sleep/5588 openat(dfd: CWD, filename: /usr/lib/locale/locale-archive, flags: RDONLY|CLOEXEC) = 3
        [root@quaco ~]#
      
      Works, further verified with:
      
        [root@quaco ~]# perf test vfs
        65: Use vfs_getname probe to get syscall args filenames   : Ok
        66: Add vfs_getname probe to get syscall args filenames   : Ok
        67: Check open filename arg using perf trace + vfs_getname: Ok
        [root@quaco ~]#
      Reported-by: NMichael Petlan <mpetlan@redhat.com>
      Tested-by: NMichael Petlan <mpetlan@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-mv8kolk17xla1smvmp3qabv1@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6ab3bc24