1. 10 10月, 2019 3 次提交
    • A
      perf trace: Expand strings in filters to integers · 90df0249
      Arnaldo Carvalho de Melo 提交于
      So that one can try things like:
      
        # perf trace -e msr:* --filter="msr!=FS_BASE && msr != IA32_TSC_DEADLINE && msr != 0x830 && msr != 0x83f && msr !=IA32_SPEC_CTRL" --filter-pids 3750
      
      That, at this point in the patchset, without any strtoul in place for
      tracepoint arguments, will result in:
      
        No resolver (strtoul) for "msr" in "msr:read_msr", can't set filter "(msr!=FS_BASE && msr != IA32_TSC_DEADLINE && msr != 0x830 && msr != 0x83f && msr !=IA32_SPEC_CTRL) && (common_pid != 25407 && common_pid != 3750)"
        #
      
      See you in the next cset!
      
      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-dx5j70fv2rgkeezd1cb3hv2p@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      90df0249
    • A
      perf trace: Introduce a strtoul() method for 'struct strarrays' · d0a3a104
      Arnaldo Carvalho de Melo 提交于
      And also for 'struct strarray', since its needed to implement
      strarrays__strtoul(). This just traverses the entries and when finding a
      match, returns (offset + index), i.e. the value associated with the
      searched string.
      
      E.g. "EFER" (MSR_EFER) returns:
      
        # grep -w EFER -B2 /tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
        #define x86_64_specific_MSRs_offset 0xc0000080
        static const char *x86_64_specific_MSRs[] = {
      	[0xc0000080 - x86_64_specific_MSRs_offset] = "EFER",
        #
      
        0xc0000080
      
      This will be auto-attached to 'struct syscall_arg_fmt' entries
      associated with strarrays as soon as we add a ->strarray and ->strarrays
      to 'struct syscall_arg_fmt'.
      
      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-r2hpaahf8lishyb1owko9vs1@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d0a3a104
    • A
      perf trace: Add a strtoul() method to 'struct syscall_arg_fmt' · 3f41b778
      Arnaldo Carvalho de Melo 提交于
      This will go from a string to a number, so that filter expressions can
      be constructed with strings and then, before applying the tracepoint
      filters (or eBPF, in the future) we can map those strings to numbers.
      
      The first one will be for 'msr' tracepoint arguments, but real quickly
      we will be able to reuse all strarrays for that.
      
      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-wgqq48agcgr95b8dmn6fygtr@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3f41b778
  2. 09 10月, 2019 3 次提交
    • A
      perf trace: Introduce --filter for tracepoint events · d4097f19
      Arnaldo Carvalho de Melo 提交于
      Similar to what is in 'perf record', works just like there:
      
        # perf trace -e msr:*
         328.297 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.302 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.306 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.317 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.322 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.327 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.331 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.336 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
         328.340 :0/0 ^Cmsr:write_msr(msr: FS_BASE, val: 140240388381888)
        #
      
      So, for a system wide trace session looking at the write_msr tracepoint
      we see a flood of MSR_FS_BASE, we need to get the number for that:
      
        # grep FS_BASE /tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
      	[0xc0000100 - x86_64_specific_MSRs_offset] = "FS_BASE",
        #
      
      And then use it in a filter:
      
        # perf trace -e msr:* --filter="msr!=0xc0000100"
        <SNIP>
         942.177 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056931068232)
         942.199 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3057135655252)
         942.203 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056931068222)
         942.231 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056998373022)
         942.241 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056931068236)
        <SNIP>
        #
      
      Ok, lets filter that too, too noisy:
      
        # grep TSC_DEADLINE /tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
      	[0x000006E0] = "IA32_TSC_DEADLINE",
        #
      
        # perf trace -e msr:* --filter="msr!=0xc0000100 && msr!=0x6e0" -a sleep 0.1
           0.000 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
           0.066 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
           0.070 CPU 0/KVM/4895 msr:write_msr(msr: 0x830, val: 34359740667)
           0.099 CPU 0/KVM/4895 msr:read_msr(msr: IA32_SYSENTER_ESP, val: -2199021993472)
           0.100 CPU 0/KVM/4895 msr:read_msr(msr: IA32_APICBASE, val: 4276096000)
           0.101 CPU 0/KVM/4895 msr:read_msr(msr: IA32_DEBUGCTLMSR)
           0.109 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL)
           1.000 :0/0 msr:write_msr(msr: 0x830, val: 17179871485)
          18.893 :0/0 msr:write_msr(msr: 0x83f, val: 246)
          28.810 :0/0 msr:write_msr(msr: 0x830, val: 68719479037)
          40.117 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
          40.127 CPU 0/KVM/4895 msr:read_msr(msr: IA32_DEBUGCTLMSR)
          40.139 CPU 0/KVM/4895 msr:write_msr(msr: LSTAR, val: -2130661312)
          40.141 CPU 0/KVM/4895 msr:write_msr(msr: SYSCALL_MASK, val: 14080)
          40.142 CPU 0/KVM/4895 msr:write_msr(msr: TSC_AUX)
          40.144 CPU 0/KVM/4895 msr:write_msr(msr: KERNEL_GS_BASE)
          40.147 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL)
          40.148 CPU 0/KVM/4895 msr:write_msr(msr: IA32_FLUSH_CMD, val: 1)
          40.151 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
        ^C
        #
      
      One can combine that with filtering pids as well:
      
        # perf trace -e msr:* --filter="msr!=0xc0000100 && msr!=0x6e0" --filter-pids 4895 -a sleep 0.09
           0.000 :0/0 msr:write_msr(msr: 0x830, val: 4294969597)
           0.291 gnome-terminal/2790 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
           0.294 gnome-terminal/2790 msr:write_msr(msr: LSTAR, val: -1935671280)
           0.295 gnome-terminal/2790 msr:write_msr(msr: TSC_AUX, val: 6)
          10.940 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
          15.943 gnome-shell/2096 msr:write_msr(msr: 0x830, val: 4294969597)
          16.975 :0/0 msr:write_msr(msr: 0x830, val: 4294969597)
          19.560 :0/0 msr:write_msr(msr: 0x83f, val: 246)
          25.162 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
          25.807 JS Watchdog/3635 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
          25.820 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL)
          25.941 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
          26.941 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
          29.942 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
          45.313 :0/0 msr:write_msr(msr: 0x83f, val: 246)
          56.945 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
          60.946 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
          74.096 JS Watchdog/8971 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
          74.130 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL)
          79.673 :0/0 msr:write_msr(msr: 0x83f, val: 246)
          79.947 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 17179871485)
        #
      
      Or for just a pid, with callchains:
      
        # grep SYSCALL_MAS /tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
      	[0xc0000084 - x86_64_specific_MSRs_offset] = "SYSCALL_MASK",
        # perf trace -e msr:* --filter="msr==0xc0000084" --pid 2790 --call-graph=dwarf
      
           0.000 gnome-terminal/2790 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
                                             do_trace_write_msr ([kernel.kallsyms])
                                             do_trace_write_msr ([kernel.kallsyms])
                                             kvm_on_user_return ([kvm])
                                             fire_user_return_notifiers ([kernel.kallsyms])
                                             exit_to_usermode_loop ([kernel.kallsyms])
                                             do_syscall_64 ([kernel.kallsyms])
                                             entry_SYSCALL_64 ([kernel.kallsyms])
                                             __GI___poll (inlined)
        9299.073 gnome-terminal/2790 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
                                             do_trace_write_msr ([kernel.kallsyms])
                                             do_trace_write_msr ([kernel.kallsyms])
                                             kvm_on_user_return ([kvm])
                                             fire_user_return_notifiers ([kernel.kallsyms])
                                             exit_to_usermode_loop ([kernel.kallsyms])
                                             do_syscall_64 ([kernel.kallsyms])
                                             entry_SYSCALL_64 ([kernel.kallsyms])
                                             __GI___poll (inlined)
        9348.374 gnome-terminal/2790 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
                                             do_trace_write_msr ([kernel.kallsyms])
                                             do_trace_write_msr ([kernel.kallsyms])
                                             kvm_on_user_return ([kvm])
                                             fire_user_return_notifiers ([kernel.kallsyms])
                                             exit_to_usermode_loop ([kernel.kallsyms])
                                             do_syscall_64 ([kernel.kallsyms])
                                             entry_SYSCALL_64 ([kernel.kallsyms])
                                             __GI___poll (inlined)
        <SNIP>
        #
      
      Ok, just another form of KVM to emit MSRs :-)
      
      Next step: elliminate those greps by getting the filter expression,
      looking for arg names, then for the arrays associated with it to do a
      reverse lookup.
      
      Also allow those filters to be associated with strace-like syscall
      names.
      
      After that: augment the 'val' arg for 'msr:write_msr' based on the first
      arg, 'msr'.
      
      Then, do that with eBPF too, not just with tracepoint filters.
      
      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: Marcelo Tosatti <mtosatti@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-95bfe5d4tzy5f66bx49d05rj@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d4097f19
    • A
      perf trace: Associate the "msr" tracepoint arg name with x86_MSR__scnprintf() · c330ef28
      Arnaldo Carvalho de Melo 提交于
      So that we can go from:
      
        # perf trace -e msr:write_msr --max-stack=16 sleep 1
             0.000 sleep/6740 msr:write_msr(msr: 3221225728, val: 139636317451648)
                                               do_trace_write_msr ([kernel.kallsyms])
                                               do_trace_write_msr ([kernel.kallsyms])
                                               do_arch_prctl_64 ([kernel.kallsyms])
                                               __x64_sys_arch_prctl ([kernel.kallsyms])
                                               do_syscall_64 ([kernel.kallsyms])
                                               entry_SYSCALL_64 ([kernel.kallsyms])
                                               init_tls (/usr/lib64/ld-2.29.so)
                                               dl_main (/usr/lib64/ld-2.29.so)
                                               _dl_sysdep_start (/usr/lib64/ld-2.29.so)
                                               _dl_start (/usr/lib64/ld-2.29.so)
        #
      
      To:
      
        # perf trace -e msr:write_msr --max-stack=16 sleep 1
           0.000 sleep/8519 msr:write_msr(msr: FS_BASE, val: 139878031705472)
                                             do_trace_write_msr ([kernel.kallsyms])
                                             do_trace_write_msr ([kernel.kallsyms])
                                             do_arch_prctl_64 ([kernel.kallsyms])
                                             __x64_sys_arch_prctl ([kernel.kallsyms])
                                             do_syscall_64 ([kernel.kallsyms])
                                             entry_SYSCALL_64 ([kernel.kallsyms])
                                             init_tls (/usr/lib64/ld-2.29.so)
                                             dl_main (/usr/lib64/ld-2.29.so)
                                             _dl_sysdep_start (/usr/lib64/ld-2.29.so)
                                             _dl_start (/usr/lib64/ld-2.29.so)
        #
      
      This, in reverse, will allow for symbolic system call/tracepoint
      filtering.
      
      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-q1q4unmqja5ex7dy0kb5cjaa@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c330ef28
    • A
      perf trace: Allow associating scnprintf routines with well known arg names · 5d88099b
      Arnaldo Carvalho de Melo 提交于
      For instance 'msr' appears in several tracepoints, so we can associate
      it with a single scnprintf() routine auto-generated from kernel headers,
      as will be done in followup patches.
      
      Start with an empty array of associations.
      
      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-89ptht6s5fez82lykuwq1eyb@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5d88099b
  3. 07 10月, 2019 12 次提交
    • A
      perf trace: Allow choosing how to augment the tracepoint arguments · f11b2803
      Arnaldo Carvalho de Melo 提交于
      So far we used the libtraceevent printing routines when showing
      tracepoint arguments, but since 'perf trace' has a lot of beautifiers
      for syscall arguments, and since some of those can be used to augment
      tracepoint arguments, add a routine to make use of those beautifiers
      and allow the user to choose which one to use.
      
      The default now is to use the same beautifiers used for the strace-like
      sys_enter+sys_exit lines, but the user can choose the libtraceevent ones
      by either using the:
      
          perf trace --libtraceevent_print
      
      command line option, or by setting:
      
        # cat ~/.perfconfig
        [trace]
      	tracepoint_beautifiers = libtraceevent
      
      For instance, here are some examples:
      
        # perf trace -e sched:*switch,*sleep,sched:*wakeup,exit*,sched:*exit sleep 1
             0.000 sched:sched_wakeup(comm: "perf", pid: 5273 (perf), prio: 120, success: 1, target_cpu: 6)
             0.621 nanosleep(rqtp: 0x7ffdd06d1140, rmtp: NULL) ...
             0.628 sched:sched_switch(prev_comm: "sleep", prev_pid: 5273 (sleep), prev_prio: 120, prev_state: 1, next_comm: "swapper/6", next_pid: 0, next_prio: 120)
          1000.879 sched:sched_wakeup(comm: "sleep", pid: 5273 (sleep), prio: 120, success: 1, target_cpu: 6)
             0.621  ... [continued]: nanosleep())          = 0
          1001.026 exit_group(error_code: 0)               = ?
          1001.216 sched:sched_process_exit(comm: "sleep", pid: 5273 (sleep), prio: 120)
        #
      
      And then using libtraceevent, as before:
      
        # perf trace --libtraceevent_print -e sched:*switch,*sleep,sched:*wakeup,exit*,sched:*exit sleep 1
             0.000 sched:sched_wakeup(comm=perf pid=5288 prio=120 target_cpu=001)
             0.739 nanosleep(rqtp: 0x7ffeba6c2f40, rmtp: NULL) ...
             0.747 sched:sched_switch(prev_comm=sleep prev_pid=5288 prev_prio=120 prev_state=S ==> next_comm=swapper/1 next_pid=0 next_prio=120)
          1000.902 sched:sched_wakeup(comm=sleep pid=5288 prio=120 target_cpu=001)
             0.739  ... [continued]: nanosleep())          = 0
          1001.012 exit_group(error_code: 0)               = ?
        #
      
      The new default allocates an array of 'struct syscall_arg_fmt' for the
      tracepoint arguments and, just like with syscall arguments, tries to
      find suitable syscall_arg__scnprintf_NAME() routines to augment those
      tracepoint arguments based on their type (as in the tracefs "format"
      file), or even in their name + type, for instance arguntents with names
      ending in "fd" with type "int" get the fd scnprintf beautifier attached,
      etc.
      
      Soon this will take advantage of the kernel BTF information to augment
      enumerations based on the tracefs "format" type info.
      
      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-o8qdluotkcb3b1x2gjqrejcl@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f11b2803
    • A
      perf trace: Enclose all events argument lists with () · 311baaf9
      Arnaldo Carvalho de Melo 提交于
      So that they look a bit like normal strace-like syscall enter+exit
      lines.
      
      They will look even more when we switch from using libtraceevent's
      tep_print_event() routine in favour of using all the perf beautifiers
      used by the strace-like syscall enter+exit lines.
      
      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-y4fcej6v6u1m644nbxd2r4pg@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      311baaf9
    • A
      perf trace: Add array of chars scnprintf beautifier · 9597945d
      Arnaldo Carvalho de Melo 提交于
      Needed for sched's traceoints prev/next comm, where, unlike with
      syscalls, we are not dealing with an integer or pointer, but an array
      straight out from the ring buffer.
      
      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-rlll7tmcqe1g4odtaifil5re@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9597945d
    • A
      perf trace: Add the syscall_arg_fmt pointer to syscall_arg · 888ca854
      Arnaldo Carvalho de Melo 提交于
      So that the scnprintf beautifiers can access it, as will be the case
      with the char array one in the following csets, that needs to know
      the number of elements in an 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-01qmjqv6cb1nj1qy4khdexce@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      888ca854
    • A
      perf trace: Move some scnprintf methods from syscall to syscall_arg_fmt · 3e0c9b2c
      Arnaldo Carvalho de Melo 提交于
      Since all they operate on is on a syscall_arg_fmt instance, so move them
      to allow use it from the upcoming tracepoint fprintf routine.
      
      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-ynttrs1l75f0x9tk67spd7jd@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3e0c9b2c
    • A
      perf trace: Allocate an array of beautifiers for tracepoint args · 947b843c
      Arnaldo Carvalho de Melo 提交于
      This will work similar to the syscall args, we'll allocate an array
      of 'struct syscall_arg_fmt' for the tracepoint args and then init them
      using the same algorithm used for the defaults for syscall args, i.e.
      using its types and sometimes names as hints to find the right scnprintf
      routine to beautify them from numbers into strings.
      
      Next step is to stop using libtracevent to printf tracepoints, as we'll
      have more beautifiers than int provides, modulo perhaps some plugins.
      
      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-dcl135relxvf6ljisjg13aqg@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      947b843c
    • A
      perf trace: Factor out the initialization of syscal_arg_fmt->scnprintf · 8d1d4ff5
      Arnaldo Carvalho de Melo 提交于
      We set the default scnprint routines for the syscall args based on its
      type or on heuristics based on its names, now we'll use this for
      tracepoints as well, so move it out of syscall__set_arg_fmts() and into
      a routine that receive just an array of syscall_arg_fmt entries + the
      tracepoint format fields list.
      
      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-xs3x0zzyes06c7scdsjn01ty@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8d1d4ff5
    • A
      perf trace augmented_syscalls: Do not show syscalls when none was asked for · 8bd436b0
      Arnaldo Carvalho de Melo 提交于
      When not using augmented syscalls, i.e. not passing thru the command
      line a eBPF source or object file event that provides the
      __augmented_syscalls__ BPF_MAP_TYPE_PERF_EVENT_ARRAY, etc, as with:
      
         perf trace -e tools/perf/examples/bpf/augmented_raw_syscalls.c
      
      or passing that augmented eBPF source/object via the trace.add_events in
      .perfconfig file, we were assuming that syscalls were asked for,
      differing from when not using augmented syscalls at all.
      
      This is confusing when using .perfconfig to hide the fact we're using
      the augmenter, i.e. using:
      
       # perf trace -e sched:* sleep 1
      
      Will show both the scheduler tracepoints and the syscalls, where what we
      want is to show just the scheduler tracepoints.
      
      To see the scheduler tracepoints and some specific syscall strace-like
      formatting, one has to use:
      
        # perf trace -e sched:*,nanosleep sleep 1
      
      Or, if wanting all the syscalls:
      
        # perf trace -e sched:* --syscalls sleep 1
      
      This way 'perf trace' can be used to trace just a set of tracepoints
      while allowing for mixing with strace-like when desired, by simply
      adding to the mix the name of the syscalls to show in addition to the
      tracepoints.
      
      Fix it so that the behaviour using the eBPF based syscall augmenter is
      the same as when not using one.
      
      Testing:
      
      Before this patch, with this ~/.perfconfig:
      
        # egrep -B1 ^[[:space:]]+add_events ~/.perfconfig
        [trace]
        	add_events = /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        #
      
      That points to this pre-compiled eBPF syscall augmenter:
      
        # file /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o: ELF 64-bit LSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped
      
      And when asking for _only_ sched:sched_switch and sched:sched_wakeup we
      were unconditionally getting all the syscalls formatted strace-like:
      
        # perf trace -e sched:*switch,sched:*wakeup sleep 1 |& tail
           0.633 fstat(3, 0x7fe11d030ac0)                = 0
           0.635 mmap(NULL, 217750512, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe10fec5000
           0.643 close(3)                                = 0
           0.668 nanosleep(0x7fff649a3a90, NULL)      ...
           0.672 sched:sched_switch:prev_comm=sleep prev_pid=4417 prev_prio=120 prev_state=S ==> next_comm=swapper/6 next_pid=0 next_prio=120
        1000.822 sched:sched_wakeup:comm=sleep pid=4417 prio=120 target_cpu=006
           0.668  ... [continued]: nanosleep())          = 0
        1000.923 close(1)                                = 0
        1000.941 close(2)                                = 0
        1000.974 exit_group(0)                           = ?
        #
      
      After the patch:
      
        # perf trace -e sched:*switch,sched:*wakeup sleep 1
           0.000 sched:sched_wakeup:comm=perf pid=5529 prio=120 target_cpu=005
           1.186 sched:sched_switch:prev_comm=sleep prev_pid=5529 prev_prio=120 prev_state=S ==> next_comm=swapper/5 next_pid=0 next_prio=120
        1001.573 sched:sched_wakeup:comm=sleep pid=5529 prio=120 target_cpu=005
        #
      
      If we add the "open*" syscalls to the mix then the eBPF augmented _will_
      be used and these syscalls will be traced together with the specified
      sched tracepoints:
      
        # cd /sys/kernel/debug/tracing/events/syscalls/
        # ls -1d sys_enter_open*
        sys_enter_open
        sys_enter_openat
        sys_enter_open_by_handle_at
        sys_enter_open_tree
        #
      
        # perf trace -e open*,sched:*switch,sched:*wakeup sleep 1
             0.000 sched:sched_wakeup:comm=perf pid=5580 prio=120 target_cpu=005
             0.590 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
             0.616 openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
             0.846 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
             0.891 sched:sched_switch:prev_comm=sleep prev_pid=5580 prev_prio=120 prev_state=S ==> next_comm=swapper/5 next_pid=0 next_prio=120
          1001.005 sched:sched_wakeup:comm=sleep pid=5580 prio=120 target_cpu=005
        #
      
      And as we can see, the pathnames were collected via the eBPF augmenters.
      
      If we don't specify anything it'll trace all syscalls:
      
        # perf trace sleep 1 |& tail
             0.299 brk(0x5597543a3000)                     = 0x5597543a3000
             0.302 brk(NULL)                               = 0x5597543a3000
             0.307 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
             0.313 fstat(3, 0x7feece50cac0)                = 0
             0.315 mmap(NULL, 217750512, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7feec13a1000
             0.323 close(3)                                = 0
             0.354 nanosleep(0x7ffe338856e0, NULL)         = 0
          1000.641 close(1)                                = 0
          1000.655 close(2)                                = 0
          1000.673 exit_group(0)                           = ?
        #
      
      Ditto if we don't use .perfconfig's trace.add_events but instead pass
      just the augmenter as a command line event:
      
        # vim ~/.perfconfig
        # egrep -B1 ^[[:space:]]+add_events ~/.perfconfig
        # perf trace -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o sleep 1 |& tail
             0.294 brk(0x55ae08ec3000)                     = 0x55ae08ec3000
             0.297 brk(NULL)                               = 0x55ae08ec3000
             0.302 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
             0.309 fstat(3, 0x7f726488fac0)                = 0
             0.311 mmap(NULL, 217750512, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7257724000
             0.319 close(3)                                = 0
             0.347 nanosleep(0x7ffe23643a70, NULL)         = 0
          1000.560 close(1)                                = 0
          1000.575 close(2)                                = 0
          1000.593 exit_group(0)                           = ?
        #
      
      As well as that + some syscall names for strace-like formatting:
      
        # perf trace -e socket,connect,/home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o ssh localhost
             0.000 socket(PF_LOCAL, SOCK_STREAM|CLOEXEC|NONBLOCK, 0) = 3
             0.021 connect(3, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
             0.034 socket(PF_LOCAL, SOCK_STREAM|CLOEXEC|NONBLOCK, 0) = 3
             0.041 connect(3, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
             0.163 socket(PF_LOCAL, SOCK_STREAM, 0)        = 4
             0.185 connect(4, { .family: PF_LOCAL, path: /var/lib/sss/pipes/nss }, 110) = 0
             0.670 socket(PF_LOCAL, SOCK_STREAM|CLOEXEC|NONBLOCK, 0) = 7
             0.684 connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
             0.694 socket(PF_LOCAL, SOCK_STREAM|CLOEXEC|NONBLOCK, 0) = 7
             0.701 connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
             0.994 socket(PF_LOCAL, SOCK_STREAM|CLOEXEC|NONBLOCK, 0) = 5
             1.006 connect(5, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
             1.014 socket(PF_LOCAL, SOCK_STREAM|CLOEXEC|NONBLOCK, 0) = 5
             1.022 connect(5, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
             1.068 socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 5
             1.087 connect(5, { .family: PF_INET, port: 22, addr: 127.0.0.1 }, 16) = 0
            24.299 socket(PF_LOCAL, SOCK_STREAM, 0)        = 6
            24.337 connect(6, { .family: PF_LOCAL, path: /var/run/.heim_org.h5l.kcm-socket }, 110) = 0
            28.441 socket(PF_LOCAL, SOCK_STREAM, 0)        = 6
            28.516 connect(6, { .family: PF_LOCAL, path: /var/run/.heim_org.h5l.kcm-socket }, 110) = 0
        root@localhost's password:^C
        #
      
      Everything works without augmenters:
      
        # egrep -B1 ^[[:space:]]+add_events ~/.perfconfig
        # perf trace sleep 1 |& tail
             0.261 brk(0x5635068ac000)                     = 0x5635068ac000
             0.264 brk(NULL)                               = 0x5635068ac000
             0.268 openat(AT_FDCWD, 0xdce642a0, O_RDONLY|O_CLOEXEC) = 3
             0.275 fstat(3, 0x7f3fdce97ac0)                = 0
             0.277 mmap(NULL, 217750512, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f3fcfd2c000
             0.284 close(3)                                = 0
             0.310 nanosleep(0x7ffdaea6ecd0, NULL)         = 0
          1000.552 close(1)                                = 0
          1000.565 close(2)                                = 0
          1000.580 exit_group(0)                           = ?
        #
      
        # perf trace -e connect ssh localhost
             0.000 connect(3, 0x58266930, 110)             = -1 ENOENT (No such file or directory)
             0.022 connect(3, 0x58266af0, 110)             = -1 ENOENT (No such file or directory)
             0.150 connect(4, 0x58266b00, 110)             = 0
             0.490 connect(7, 0x58264150, 110)             = -1 ENOENT (No such file or directory)
             0.505 connect(7, 0x58264300, 110)             = -1 ENOENT (No such file or directory)
             0.832 connect(5, 0x58266220, 110)             = -1 ENOENT (No such file or directory)
             0.847 connect(5, 0x582663e0, 110)             = -1 ENOENT (No such file or directory)
             0.899 connect(5, 0x95ba0630, 16)              = 0
            25.619 connect(6, 0x58266360, 110)             = 0
            40.564 connect(6, 0x58266330, 110)             = 0
        root@localhost's password: ^C
        #
      
      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-624f6jxic04031tnt40va4dd@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8bd436b0
    • A
      perf trace: Postpone parsing .perfconfig trace.add_events to after --verbose is processed · 7e035929
      Arnaldo Carvalho de Melo 提交于
      When we add events via the '[trace]' section in perfconfig the command
      line options are not yet processed, so when something goes wrong with
      parsing those events and using --verbose is advised, we end up not
      getting any more verbosity by doing so.
      
      So just copy the trace.add_events string for later processing, after we
      processed --verbose and the other command line options.
      
      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-d6wbnz85ftqljdll6ynjyjd8@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7e035929
    • A
      perf trace: Generalize the syscall_fmt find routines · bcddbfc5
      Arnaldo Carvalho de Melo 提交于
      To allow them to be used with other stuff, such as tracepoints.
      
      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-od3gzg77ppqgnnrxqv40fvgx@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      bcddbfc5
    • A
      perf trace: Separate 'struct syscall_fmt' definition from syscall_fmts variable · 9b2036cd
      Arnaldo Carvalho de Melo 提交于
      As this has all the things needed to format tracepoints events, not just
      syscalls, that, after all, are just tracepoints with a set in stone ABI,
      i.e. order and number of parameters.
      
      For tracepoints we'll create a
      
        static struct syscall_fmt tracepoint_fmts[]
      
      array and will fill the ->arg[] entries with the beautifier for each
      positional argument and record the name, then, when we need it, we'll
      just check that the position has the same name, maybe even type, so that
      we can do some check that the tracepoint hasn't changed, if it has, we
      can even reorder things.
      
      Keep calling it syscall_fmt but use it as well for tracepoints, do it
      this way to minimize changes and reuse what is in place for syscalls,
      we'll see.
      
      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-2x1jgiev13zt4njaanlnne0d@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9b2036cd
    • A
      perf trace: Make evlist__set_evsel_handler() affect just entries without a handler · 206d635a
      Arnaldo Carvalho de Melo 提交于
      Renaming it to evlist__set_default_evsel_handler(), to better reflect
      what we want to do, which is to set a default handler for events we
      still haven't set a custom handler, like the ones for "msr:write_msr",
      etc that are coming soon.
      
      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-e1bit7upnpmtsayh8039kfuw@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      206d635a
  4. 26 9月, 2019 2 次提交
  5. 25 9月, 2019 7 次提交
  6. 21 9月, 2019 1 次提交
  7. 20 9月, 2019 1 次提交
  8. 01 9月, 2019 2 次提交
  9. 30 8月, 2019 1 次提交
  10. 29 8月, 2019 2 次提交
  11. 26 8月, 2019 1 次提交
  12. 23 8月, 2019 1 次提交
  13. 15 8月, 2019 1 次提交
    • A
      perf trace: Add --switch-on/--switch-off events · 22ac4318
      Arnaldo Carvalho de Melo 提交于
      Just like with 'perf script':
      
        # perf trace -e sched:*,syscalls:*sleep* sleep 1
             0.000 :28345/28345 sched:sched_waking:comm=perf pid=28346 prio=120 target_cpu=005
             0.005 :28345/28345 sched:sched_wakeup:perf:28346 [120] success=1 CPU:005
             0.383 sleep/28346 sched:sched_process_exec:filename=/usr/bin/sleep pid=28346 old_pid=28346
             0.613 sleep/28346 sched:sched_stat_runtime:comm=sleep pid=28346 runtime=607375 [ns] vruntime=23289041218 [ns]
             0.689 sleep/28346 syscalls:sys_enter_nanosleep:rqtp: 0x7ffc491789b0
             0.693 sleep/28346 sched:sched_stat_runtime:comm=sleep pid=28346 runtime=72021 [ns] vruntime=23289113239 [ns]
             0.694 sleep/28346 sched:sched_switch:sleep:28346 [120] S ==> swapper/5:0 [120]
          1000.787 :0/0 sched:sched_waking:comm=sleep pid=28346 prio=120 target_cpu=005
          1000.824 :0/0 sched:sched_wakeup:sleep:28346 [120] success=1 CPU:005
          1000.908 sleep/28346 syscalls:sys_exit_nanosleep:0x0
          1001.218 sleep/28346 sched:sched_process_exit:comm=sleep pid=28346 prio=120
        # perf trace -e sched:*,syscalls:*sleep* --switch-on=syscalls:sys_enter_nanosleep sleep 1
             0.000 sleep/28349 sched:sched_stat_runtime:comm=sleep pid=28349 runtime=603036 [ns] vruntime=23873537697 [ns]
             0.001 sleep/28349 sched:sched_switch:sleep:28349 [120] S ==> swapper/4:0 [120]
          1000.392 :0/0 sched:sched_waking:comm=sleep pid=28349 prio=120 target_cpu=004
          1000.443 :0/0 sched:sched_wakeup:sleep:28349 [120] success=1 CPU:004
          1000.540 sleep/28349 syscalls:sys_exit_nanosleep:0x0
          1000.852 sleep/28349 sched:sched_process_exit:comm=sleep pid=28349 prio=120
        # perf trace -e sched:*,syscalls:*sleep* --switch-on=syscalls:sys_enter_nanosleep --switch-off=syscalls:sys_exit_nanosleep sleep 1
             0.000 sleep/28352 sched:sched_stat_runtime:comm=sleep pid=28352 runtime=610543 [ns] vruntime=24811686681 [ns]
             0.001 sleep/28352 sched:sched_switch:sleep:28352 [120] S ==> swapper/0:0 [120]
          1000.397 :0/0 sched:sched_waking:comm=sleep pid=28352 prio=120 target_cpu=000
          1000.440 :0/0 sched:sched_wakeup:sleep:28352 [120] success=1 CPU:000
        #
        # perf trace -e sched:*,syscalls:*sleep* --switch-on=syscalls:sys_enter_nanosleep --switch-off=syscalls:sys_exit_nanosleep --show-on-off sleep 1
             0.000 sleep/28367 syscalls:sys_enter_nanosleep:rqtp: 0x7fffd1a25fc0
             0.004 sleep/28367 sched:sched_stat_runtime:comm=sleep pid=28367 runtime=628760 [ns] vruntime=22170052672 [ns]
             0.005 sleep/28367 sched:sched_switch:sleep:28367 [120] S ==> swapper/2:0 [120]
          1000.367 :0/0 sched:sched_waking:comm=sleep pid=28367 prio=120 target_cpu=002
          1000.412 :0/0 sched:sched_wakeup:sleep:28367 [120] success=1 CPU:002
          1000.512 sleep/28367 syscalls:sys_exit_nanosleep:0x0
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Florian Weimer <fweimer@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: William Cohen <wcohen@redhat.com>
      Link: https://lkml.kernel.org/n/tip-t3ngpt1brcc1fm9gep9gxm4q@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      22ac4318
  14. 13 8月, 2019 1 次提交
    • L
      perf trace: Fix segmentation fault when access syscall info on arm64 · 3e70008a
      Leo Yan 提交于
      'perf trace' reports the segmentation fault as below on Arm64:
      
        # perf trace -e string -e augmented_raw_syscalls.c
        LLVM: dumping tools/perf/examples/bpf/augmented_raw_syscalls.o
        perf: Segmentation fault
        Obtained 12 stack frames.
        perf(sighandler_dump_stack+0x47) [0xaaaaac96ac87]
        linux-vdso.so.1(+0x5b7) [0xffffadbeb5b7]
        /lib/aarch64-linux-gnu/libc.so.6(strlen+0x10) [0xfffface7d5d0]
        /lib/aarch64-linux-gnu/libc.so.6(_IO_vfprintf+0x1ac7) [0xfffface49f97]
        /lib/aarch64-linux-gnu/libc.so.6(__vsnprintf_chk+0xc7) [0xffffacedfbe7]
        perf(scnprintf+0x97) [0xaaaaac9ca3ff]
        perf(+0x997bb) [0xaaaaac8e37bb]
        perf(cmd_trace+0x28e7) [0xaaaaac8ec09f]
        perf(+0xd4a13) [0xaaaaac91ea13]
        perf(main+0x62f) [0xaaaaac8a147f]
        /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe3) [0xfffface22d23]
        perf(+0x57723) [0xaaaaac8a1723]
        Segmentation fault
      
      This issue is introduced by commit 30a910d7 ("perf trace:
      Preallocate the syscall table"), it allocates trace->syscalls.table[]
      array and the element count is 'trace->sctbl->syscalls.nr_entries'; but
      on Arm64, the system call number is not continuously used; e.g. the
      syscall maximum id is 436 but the real entries is only 281.
      
      So the table is allocated with 'nr_entries' as the element count, but it
      accesses the table with the syscall id, which might be out of the bound
      of the array and cause the segmentation fault.
      
      This patch allocates trace->syscalls.table[] with the element count is
      'trace->sctbl->syscalls.max_id + 1', this allows any id to access the
      table without out of the bound.
      Signed-off-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Yonghong Song <yhs@fb.com>
      Fixes: 30a910d7 ("perf trace: Preallocate the syscall table")
      Link: http://lkml.kernel.org/r/20190809104752.27338-1-leo.yan@linaro.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3e70008a
  15. 30 7月, 2019 2 次提交