1. 14 Dec, 2022 3 commits
    • Tiezhu Yang's avatar
      perf tools: Use "grep -E" instead of "egrep" · 818448e9
      Tiezhu Yang authored
      The latest version of grep claims the egrep is now obsolete so the build
      now contains warnings that look like:
      
      	egrep: warning: egrep is obsolescent; using grep -E
      
      fix this up by moving the related file to use "grep -E" instead.
      
        sed -i "s/egrep/grep -E/g" `grep egrep -rwl tools/perf`
      
      Here are the steps to install the latest grep:
      
        wget http://ftp.gnu.org/gnu/grep/grep-3.8.tar.gz
      
      
        tar xf grep-3.8.tar.gz
        cd grep-3.8 && ./configure && make
        sudo make install
        export PATH=/usr/local/bin:$PATH
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/1668762999-9297-1-git-send-email-yangtiezhu@loongson.cn
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      818448e9
    • Arnaldo Carvalho de Melo's avatar
      perf tools: Check if libtracevent has TEP_FIELD_IS_RELATIVE · b9a49f8c
      Arnaldo Carvalho de Melo authored
      
      Some distros have older versions of libtraceevent where
      TEP_FIELD_IS_RELATIVE and its associated semantics are not present, so
      we need to check if the version has it, it was introduced in
      libtraceevent 1.5.0.
      Reported-by: default avatarAthira Jajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarAthira Jajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>,
      Cc: Stephane Eranian <eranian@google.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b9a49f8c
    • Ian Rogers's avatar
      perf build: Use libtraceevent from the system · 378ef0f5
      Ian Rogers authored
      Remove the LIBTRACEEVENT_DYNAMIC and LIBTRACEFS_DYNAMIC make command
      line variables.
      
      If libtraceevent isn't installed or NO_LIBTRACEEVENT=1 is passed to the
      build, don't compile in libtraceevent and libtracefs support.
      
      This also disables CONFIG_TRACE that controls "perf trace".
      
      CONFIG_LIBTRACEEVENT is used to control enablement in Build/Makefiles,
      HAVE_LIBTRACEEVENT is used in C code.
      
      Without HAVE_LIBTRACEEVENT tracepoints are disabled and as such the
      commands kmem, kwork, lock, sched and timechart are removed.  The
      majority of commands continue to work including "perf test".
      
      Committer notes:
      
      Fixed up a tools/perf/util/Build reject and added:
      
        #include <traceevent/event-parse.h>
      
      to tools/perf/util/scripting-engines/trace-event-perl.c.
      
      Committer testing:
      
        $ rpm -qi libtraceevent-devel
        Name        : libtraceevent-devel
        Version     : 1.5.3
        Release     : 2.fc36
        Architecture: x86_64
        Install Date: Mon 25 Jul 2022 03:20:19 PM -03
        Group       : Unspecified
        Size        : 27728
        License     : LGPLv2+ and GPLv2+
        Signature   : RSA/SHA256, Fri 15 Apr 2022 02:11:58 PM -03, Key ID 999f7cbf38ab71f4
        Source RPM  : libtraceevent-1.5.3-2.fc36.src.rpm
        Build Date  : Fri 15 Apr 2022 10:57:01 AM -03
        Build Host  : buildvm-x86-05.iad2.fedoraproject.org
        Packager    : Fedora Project
        Vendor      : Fedora Project
        URL         : https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
        Bug URL     : https://bugz.fedoraproject.org/libtraceevent
      
      
        Summary     : Development headers of libtraceevent
        Description :
        Development headers of libtraceevent-libs
        $
      
      Default build:
      
        $ ldd ~/bin/perf | grep tracee
        	libtraceevent.so.1 => /lib64/libtraceevent.so.1 (0x00007f1dcaf8f000)
        $
      
        # perf trace -e sched:* --max-events 10
             0.000 migration/0/17 sched:sched_migrate_task(comm: "", pid: 1603763 (perf), prio: 120, dest_cpu: 1)
             0.005 migration/0/17 sched:sched_wake_idle_without_ipi(cpu: 1)
             0.011 migration/0/17 sched:sched_switch(prev_comm: "", prev_pid: 17 (migration/0), prev_state: 1, next_comm: "", next_prio: 120)
             1.173 :0/0 sched:sched_wakeup(comm: "", pid: 3138 (gnome-terminal-), prio: 120)
             1.180 :0/0 sched:sched_switch(prev_comm: "", prev_prio: 120, next_comm: "", next_pid: 3138 (gnome-terminal-), next_prio: 120)
             0.156 migration/1/21 sched:sched_migrate_task(comm: "", pid: 1603763 (perf), prio: 120, orig_cpu: 1, dest_cpu: 2)
             0.160 migration/1/21 sched:sched_wake_idle_without_ipi(cpu: 2)
             0.166 migration/1/21 sched:sched_switch(prev_comm: "", prev_pid: 21 (migration/1), prev_state: 1, next_comm: "", next_prio: 120)
             1.183 :0/0 sched:sched_wakeup(comm: "", pid: 1602985 (kworker/u16:0-f), prio: 120, target_cpu: 1)
             1.186 :0/0 sched:sched_switch(prev_comm: "", prev_prio: 120, next_comm: "", next_pid: 1602985 (kworker/u16:0-f), next_prio: 120)
        #
      
      Had to tweak tools/perf/util/setup.py to make sure the python binding
      shared object links with libtraceevent if -DHAVE_LIBTRACEEVENT is
      present in CFLAGS.
      
      Building with NO_LIBTRACEEVENT=1 uncovered some more build failures:
      
      - Make building of data-convert-bt.c to CONFIG_LIBTRACEEVENT=y
      
      - perf-$(CONFIG_LIBTRACEEVENT) += scripts/
      
      - bpf_kwork.o needs also to be dependent on CONFIG_LIBTRACEEVENT=y
      
      - The python binding needed some fixups and util/trace-event.c can't be
        built and linked with the python binding shared object, so remove it
        in tools/perf/util/setup.py and exclude it from the list of
        dependencies in the python/perf.so Makefile.perf target.
      
      Building without libtraceevent-devel installed uncovered more build
      failures:
      
      - The python binding tools/perf/util/python.c was assuming that
        traceevent/parse-events.h was always available, which was the case
        when we defaulted to using the in-kernel tools/lib/traceevent/ files,
        now we need to enclose it under ifdef HAVE_LIBTRACEEVENT, just like
        the other parts of it that deal with tracepoints.
      
      - We have to ifdef the rules in the Build files with
        CONFIG_LIBTRACEEVENT=y to build builtin-trace.c and
        tools/perf/trace/beauty/ as we only ifdef setting CONFIG_TRACE=y when
        setting NO_LIBTRACEEVENT=1 in the make command line, not when we don't
        detect libtraceevent-devel installed in the system. Simplification here
        to avoid these two ways of disabling builtin-trace.c and not having
        CONFIG_TRACE=y when libtraceevent-devel isn't installed is the clean
        way.
      
      From Athira:
      
      <quote>
      tools/perf/arch/powerpc/util/Build
      -perf-y += kvm-stat.o
      +perf-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
      </quote>
      
      Then, ditto for arm64 and s390, detected by container cross build tests.
      
      - s/390 uses test__checkevent_tracepoint() that is now only available if
        HAVE_LIBTRACEEVENT is defined, enclose the callsite with ifder HAVE_LIBTRACEEVENT.
      
      Also from Athira:
      
      <quote>
      With this change, I could successfully compile in these environment:
      - Without libtraceevent-devel installed
      - With libtraceevent-devel installed
      - With “make NO_LIBTRACEEVENT=1”
      </quote>
      
      Then, finally rename CONFIG_TRACEEVENT to CONFIG_LIBTRACEEVENT for
      consistency with other libraries detected in tools/perf/.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Tested-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: bpf@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20221205225940.3079667-3-irogers@google.com
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      378ef0f5
  2. 23 Nov, 2022 4 commits
    • Leo Yan's avatar
      perf trace: Remove unused bpf map 'syscalls' · 8daf87f5
      Leo Yan authored
      
      augmented_raw_syscalls.c defines the bpf map 'syscalls' which is
      initialized by perf tool in user space to indicate which system calls
      are enabled for tracing, on the other flip eBPF program relies on the
      map to filter out the trace events which are not enabled.
      
      The map also includes a field 'string_args_len[6]' which presents the
      string length if the corresponding argument is a string type.
      
      Now the map 'syscalls' is not used, bpf program doesn't use it as filter
      anymore, this is replaced by using the function bpf_tail_call() and
      PROG_ARRAY syscalls map.  And we don't need to explicitly set the string
      length anymore, bpf_probe_read_str() is smart to copy the string and
      return string length.
      
      Therefore, it's safe to remove the bpf map 'syscalls'.
      
      To consolidate the code, this patch removes the definition of map
      'syscalls' from augmented_raw_syscalls.c and drops code for using
      the map in the perf trace.
      
      Note, since function trace__set_ev_qualifier_bpf_filter() is removed,
      calling trace__init_syscall_bpf_progs() from it is also removed.  We
      don't need to worry it because trace__init_syscall_bpf_progs() is
      still invoked from trace__init_syscalls_bpf_prog_array_maps() for
      initialization the system call's bpf program callback.
      
      After:
      
        # perf trace -e examples/bpf/augmented_raw_syscalls.c,open* --max-events 10 perf stat --quiet sleep 0.001
        openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libelf.so.1", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libdw.so.1", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libunwind.so.8", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libunwind-aarch64.so.8", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libcrypto.so.3", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libslang.so.2", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libperl.so.5.34", O_RDONLY|O_CLOEXEC) = 3
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
      
        # perf trace -e examples/bpf/augmented_raw_syscalls.c --max-events 10 perf stat --quiet sleep 0.001
        ... [continued]: execve())             = 0
        brk(NULL)                               = 0xaaaab1d28000
        faccessat(-100, "/etc/ld.so.preload", 4) = -1 ENOENT (No such file or directory)
        openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
        close(3</usr/lib/aarch64-linux-gnu/libcrypto.so.3>) = 0
        openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
        read(3</usr/lib/aarch64-linux-gnu/libcrypto.so.3>, 0xfffff33f70d0, 832) = 832
        munmap(0xffffb5519000, 28672)           = 0
        munmap(0xffffb55b7000, 32880)           = 0
        mprotect(0xffffb55a6000, 61440, PROT_NONE) = 0
      Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20221121075237.127706-6-leo.yan@linaro.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8daf87f5
    • Leo Yan's avatar
      perf trace: Handle failure when trace point folder is missed · 03e9a5d8
      Leo Yan authored
      On Arm64 a case is perf tools fails to find the corresponding trace
      point folder for system calls listed in the table 'syscalltbl_arm64',
      e.g. the generated system call table contains "lookup_dcookie" but we
      cannot find out the matched trace point folder for it.
      
      We need to figure out if there have any issue for the generated system
      call table, on the other hand, we need to handle the case when trace
      point folder is missed under sysfs, this patch sets the flag
      syscall::nonexistent as true and returns the error from
      trace__read_syscall_info().
      
      Another problem is for trace__syscall_info(), it returns two different
      values if a system call doesn't exist: at the first time calling
      trace__syscall_info() it returns NULL when the system call doesn't exist,
      later if call trace__syscall_info() again for the same missed system
      call, it returns pointer of syscall.  trace__syscall_info() checks the
      condition 'syscalls.table[id].name == NULL', but the name will be
      assigned in the first invoking even the system call is not found.
      
      So checking system call's name in trace__syscall_info() is not the right
      thing to do, this patch simply checks flag syscall::nonexistent to make
      decision if a system call exists or not, finally trace__syscall_info()
      returns the consistent result (NULL) if a system call doesn't existed.
      
      Fixes: b8b1033f
      
       ("perf trace: Mark syscall ids that are not allocated to avoid unnecessary error messages")
      Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: bpf@vger.kernel.org
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20221121075237.127706-4-leo.yan@linaro.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      03e9a5d8
    • Leo Yan's avatar
      perf trace: Return error if a system call doesn't exist · d4223e17
      Leo Yan authored
      When a system call is not detected, the reason is either because the
      system call ID is out of scope or failure to find the corresponding path
      in the sysfs, trace__read_syscall_info() returns zero.  Finally, without
      returning an error value it introduces confusion for the caller.
      
      This patch lets the function trace__read_syscall_info() to return
      -EEXIST when a system call doesn't exist.
      
      Fixes: b8b1033f
      
       ("perf trace: Mark syscall ids that are not allocated to avoid unnecessary error messages")
      Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: bpf@vger.kernel.org
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20221121075237.127706-3-leo.yan@linaro.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d4223e17
    • Leo Yan's avatar
      perf trace: Use macro RAW_SYSCALL_ARGS_NUM to replace number · eadcab4c
      Leo Yan authored
      
      This patch defines a macro RAW_SYSCALL_ARGS_NUM to replace the open
      coded number '6'.
      Signed-off-by: default avatarLeo Yan <leo.yan@linaro.org>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20221121075237.127706-2-leo.yan@linaro.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      eadcab4c
  3. 16 Nov, 2022 1 commit
  4. 10 Nov, 2022 1 commit
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Add augmenter for clock_gettime's rqtp timespec arg · 6ac73820
      Arnaldo Carvalho de Melo authored
      
      One more before going the BTF way:
      
        # perf trace -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o,*nanosleep
               ? pool-gsd-smart/2893  ... [continued]: clock_nanosleep())    = 0
               ? gpm/1042  ... [continued]: clock_nanosleep())    = 0
           1.232 pool-gsd-smart/2893 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 0 }, rmtp: 0x7f64d7ffec50) ...
           1.232 pool-gsd-smart/2893  ... [continued]: clock_nanosleep())    = 0
         327.329 gpm/1042 clock_nanosleep(rqtp: { .tv_sec: 2, .tv_nsec: 0 }, rmtp: 0x7ffddfd1cf20) ...
        1002.482 pool-gsd-smart/2893 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 0 }, rmtp: 0x7f64d7ffec50) = 0
         327.329 gpm/1042  ... [continued]: clock_nanosleep())    = 0
        2003.947 pool-gsd-smart/2893 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 0 }, rmtp: 0x7f64d7ffec50) ...
        2003.947 pool-gsd-smart/2893  ... [continued]: clock_nanosleep())    = 0
        2327.858 gpm/1042 clock_nanosleep(rqtp: { .tv_sec: 2, .tv_nsec: 0 }, rmtp: 0x7ffddfd1cf20) ...
               ? crond/1384  ... [continued]: clock_nanosleep())    = 0
        3005.382 pool-gsd-smart/2893 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 0 }, rmtp: 0x7f64d7ffec50) ...
        3005.382 pool-gsd-smart/2893  ... [continued]: clock_nanosleep())    = 0
        3675.633 crond/1384 clock_nanosleep(rqtp: { .tv_sec: 60, .tv_nsec: 0 }, rmtp: 0x7ffcc02b66b0) ...
      ^C#
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6ac73820
  5. 07 Nov, 2022 1 commit
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Add BPF augmenter to perf_event_open()'s 'struct perf_event_attr' arg · a9cd6c67
      Arnaldo Carvalho de Melo authored
      
      Using BPF for that, doing a cleverish reuse of perf_event_attr__fprintf(),
      that really needs to be turned into __snprintf(), etc.
      
      But since the plan is to go the BTF way probably use libbpf's
      btf_dump__dump_type_data().
      
      Example:
      
      [root@quaco ~]# perf trace -e ~acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c,perf_event_open --max-events 10 perf stat --quiet sleep 0.001
      fg
           0.000 perf_event_open(attr_uptr: { type: 1, size: 128, config: 0x1, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
           0.067 perf_event_open(attr_uptr: { type: 1, size: 128, config: 0x3, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 4
           0.120 perf_event_open(attr_uptr: { type: 1, size: 128, config: 0x4, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 5
           0.172 perf_event_open(attr_uptr: { type: 1, size: 128, config: 0x2, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 7
           0.190 perf_event_open(attr_uptr: { size: 128, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 8
           0.199 perf_event_open(attr_uptr: { size: 128, config: 0x1, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 9
           0.204 perf_event_open(attr_uptr: { size: 128, config: 0x4, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 10
           0.210 perf_event_open(attr_uptr: { size: 128, config: 0x5, sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 258859 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 11
      [root@quaco ~]#
      Suggested-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/r/Y2V2Tpu+2vzJyon2@kernel.org
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a9cd6c67
  6. 03 Nov, 2022 1 commit
  7. 04 Oct, 2022 3 commits
    • Chen Zhongjin's avatar
      perf trace: Fix incorrectly parsed hexadecimal value for flags in filter · 96b73141
      Chen Zhongjin authored
      When parsing flags in filter, the strtoul function uses wrong parsing
      condition (tok[1] = 'x'), which can make the flags be corrupted and
      treat all numbers start with 0 as hex.
      
      In fact strtoul() will auto test hex format when base == 0 (See
      _parse_integer_fixup_radix). So there is no need to test this again.
      
      Remove the unnessesary is_hexa test.
      
      Fixes: 154c978d
      
       ("libbeauty: Introduce strarray__strtoul_flags()")
      Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20220926031440.28275-3-chenzhongjin@huawei.com
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      96b73141
    • Chen Zhongjin's avatar
      perf trace: Fix show_arg_names not working for tp arg names · 888964a0
      Chen Zhongjin authored
      trace__fprintf_tp_fields() will always print arg names because when
      implemented it is forced to print arg_names with:
      
        (1 || trace->show_arg_names)
      
      So the printing looks like:
      
      > cat ~/.perfconfig
          [trace]
              show_arg_names = no
      
      > perf trace -e syscalls:*mmap sleep 1
          0.000 sleep/1119 syscalls:sys_enter_mmap(NULL, 8192, READ|WRITE, PRIVATE|ANONYMOUS)
          0.179 sleep/1119 syscalls:sys_exit_mmap(__syscall_nr: 9, ret: 140535426170880)
          ...
      
      Although the comment said that perhaps we need a show_tp_arg_names.
      
      I don't think it's necessary to control them separately because it's not
      so clean that part of the log shows arg names but other not.
      
      Also when we are tracing functions it's rare to especially distinguish
      syscalls and tp trace.
      
      Only use one option to control arg names printing is more resonable and
      simple. So remove the force condition and commit.
      
      After fix:
      
      > perf trace -e syscalls:*mmap sleep 1
          0.000 sleep/1121 syscalls:sys_enter_mmap(NULL, 8192, READ|WRITE, PRIVATE|ANONYMOUS)
          0.163 sleep/1121 syscalls:sys_exit_mmap(9, 140454467661824)
          ...
      
      Fixes: f11b2803
      
       ("perf trace: Allow choosing how to augment the tracepoint arguments")
      Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20220926031440.28275-2-chenzhongjin@huawei.com
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      888964a0
    • Shang XiaoJing's avatar
      perf trace: Use zalloc() to save initialization of syscall_stats · e3e7572f
      Shang XiaoJing authored
      
      As most members of syscall_stats is set to 0 in thread__update_stats,
      using zalloc() directly.
      Signed-off-by: default avatarShang XiaoJing <shangxiaojing@huawei.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20220908021141.27134-2-shangxiaojing@huawei.com
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e3e7572f
  8. 12 Aug, 2022 1 commit
  9. 02 Aug, 2022 1 commit
    • Ian Rogers's avatar
      perf parse-events: Break out tracepoint and printing · 9b7c7728
      Ian Rogers authored
      
      Move print_*_events functions out of parse-events.c into a new
      print-events.c. Move tracepoint code into tracepoint.c or
      trace-event-info.c (sole user). This reduces the dependencies of
      parse-events.c and makes it more amenable to being a library in the
      future.
      
      Remove some unnecessary definitions from parse-events.h. Fix a
      checkpatch.pl warning on using unsigned rather than unsigned int.  Fix
      some line length warnings too.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: https://lore.kernel.org/r/20220729204217.250166-3-irogers@google.com
      
      
      [ Add include linux/stddef.h before perf_events.h for systems where __always_inline isn't pulled in before used, such as older Alpine Linux ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9b7c7728
  10. 17 Jul, 2022 1 commit
    • Naveen N. Rao's avatar
      perf trace: Fix SIGSEGV when processing syscall args · 4b335e1e
      Naveen N. Rao authored
      On powerpc, 'perf trace' is crashing with a SIGSEGV when trying to
      process a perf.data file created with 'perf trace record -p':
      
        #0  0x00000001225b8988 in syscall_arg__scnprintf_augmented_string <snip> at builtin-trace.c:1492
        #1  syscall_arg__scnprintf_filename <snip> at builtin-trace.c:1492
        #2  syscall_arg__scnprintf_filename <snip> at builtin-trace.c:1486
        #3  0x00000001225bdd9c in syscall_arg_fmt__scnprintf_val <snip> at builtin-trace.c:1973
        #4  syscall__scnprintf_args <snip> at builtin-trace.c:2041
        #5  0x00000001225bff04 in trace__sys_enter <snip> at builtin-trace.c:2319
      
      That points to the below code in tools/perf/builtin-trace.c:
      	/*
      	 * If this is raw_syscalls.sys_enter, then it always comes with the 6 possible
      	 * arguments, even if the syscall being handled, say "openat", uses only 4 arguments
      	 * this breaks syscall__augmented_args() check for augmented args, as we calculate
      	 * syscall->args_size using each syscalls:sys_enter_NAME...
      4b335e1e
  11. 16 Feb, 2022 1 commit
    • Changbin Du's avatar
      perf trace: Avoid early exit due SIGCHLD from non-workload processes · de9f498d
      Changbin Du authored
      
      The function trace__symbols_init() runs "perf-read-vdso32" and that ends up
      with a SIGCHLD delivered to 'perf'. And this SIGCHLD make perf exit early.
      
      'perf trace' should exit only if the SIGCHLD is from our workload process.
      So let's use sigaction() instead of signal() to match such condition.
      
      Committer notes:
      
      Use memset to zero the 'struct sigaction' variable as the '= { 0 }'
      method isn't accepted in many compiler versions, e.g.:
      
         4    34.02 alpine:3.6                    : FAIL clang version 4.0.0 (tags/RELEASE_400/final)
          builtin-trace.c:4897:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
                  struct sigaction sigchld_act = { 0 };
                                                   ^
                                                   {}
          builtin-trace.c:4897:37: error: missing field 'sa_mask' initializer [-Werror,-Wmissing-field-initializers]
                  struct sigaction sigchld_act = { 0 };
                                                     ^
          2 errors generated.
         6    32.60 alpine:3.8                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
          builtin-trace.c:4897:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
                  struct sigaction sigchld_act = { 0 };
                                                   ^
                                                   {}
          builtin-trace.c:4897:37: error: missing field 'sa_mask' initializer [-Werror,-Wmissing-field-initializers]
                  struct sigaction sigchld_act = { 0 };
                                                     ^
          2 errors generated.
         7    34.82 alpine:3.9                    : FAIL gcc version 8.3.0 (Alpine 8.3.0)
          builtin-trace.c:4897:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
                  struct sigaction sigchld_act = { 0 };
                                                   ^
                                                   {}
          builtin-trace.c:4897:37: error: missing field 'sa_mask' initializer [-Werror,-Wmissing-field-initializers]
                  struct sigaction sigchld_act = { 0 };
                                                     ^
          2 errors generated.
      Signed-off-by: default avatarChangbin Du <changbin.du@gmail.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20220208140725.3947-1-changbin.du@gmail.com
      
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      de9f498d
  12. 10 Feb, 2022 1 commit
  13. 07 Jan, 2022 1 commit
  14. 14 Dec, 2021 1 commit
  15. 08 Dec, 2021 1 commit
  16. 06 Dec, 2021 1 commit
  17. 12 Nov, 2021 2 commits
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Beautify the 'level' argument of setsockopt · 0826b7fd
      Arnaldo Carvalho de Melo authored
      
        # perf trace -e setsockopt
           0.000 ( 0.019 ms): systemd-resolv/1121 setsockopt(fd: 22, level: IP, optname: 50, optval: 0x7ffee2c0c134, optlen: 4) = 0
           0.022 ( 0.003 ms): systemd-resolv/1121 setsockopt(fd: 22, level: IP, optname: 11, optval: 0x7ffee2c0c114, optlen: 4) = 0
           0.027 ( 0.003 ms): systemd-resolv/1121 setsockopt(fd: 22, level: IP, optname: 8, optval: 0x7ffee2c0c134, optlen: 4) = 0
           0.032 ( 0.002 ms): systemd-resolv/1121 setsockopt(fd: 22, level: IP, optname: 10, optval: 0x7ffee2c0c134, optlen: 4) = 0
           0.036 ( 0.002 ms): systemd-resolv/1121 setsockopt(fd: 22, level: IP, optname: 25, optval: 0x7ffee2c0c114, optlen: 4) = 0
           0.043 ( 0.003 ms): systemd-resolv/1121 setsockopt(fd: 22, level: 1, optname: 62, optval: 0x7ffee2c0c0fc, optlen: 4) = 0
           0.055 ( 0.003 ms): systemd-resolv/1121 setsockopt(fd: 22, level: 1, optname: 25)
        ^C#
      
      So the simple straight STRARRAY method is not enough as SOL_SOCKET is
      '1' in most architectures but some use 0xffff (alpha, mips, parisc and
      sparc), so a followup patch will create a specialized scnprintf to cover
      that.
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0826b7fd
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Beautify the 'level' argument of getsockopt · f1c1e45e
      Arnaldo Carvalho de Melo authored
      
        # perf trace -e getsockopt
             0.000 ( 0.006 ms): systemd-resolv/1121 getsockopt(fd: 21, level: 1, optname: 17, optval: 0x7ffee2c0c6cc, optlen: 0x7ffee2c0c6c8) = 0
             0.301 ( 0.003 ms): systemd-resolv/1121 getsockopt(fd: 22, level: IP, optname: 14, optval: 0x7ffee2c0c1a0, optlen: 0x7ffee2c0c1a4) = -1 ENOTCONN (Transport endpoint is not connected)
             2.215 ( 0.005 ms): systemd-resolv/1121 getsockopt(fd: 21, level: 1, optname: 17, optval: 0x7ffee2c0c6cc, optlen: 0x7ffee2c0c6c8) = 0
             2.422 ( 0.005 ms): systemd-resolv/1121 getsockopt(fd: 22, level: IP, optname: 14, optval: 0x7ffee2c0c1a0, optlen: 0x7ffee2c0c1a4) = -1 ENOTCONN (Transport endpoint is not connected)
          1001.308 ( 0.006 ms): systemd-resolv/1121 getsockopt(fd: 21, level: 1, optname: 17, optval: 0x7ffee2c0c6cc, optlen: 0x7ffee2c0c6c8) = 0
          1001.586 ( 0.003 ms): systemd-resolv/1121 getsockopt(fd: 22, level: IP, optname: 14, optval: 0x7ffee2c0c1a0, optlen: 0x7ffee2c0c1a4) = -1 ENOTCONN (Transport endpoint is not connected)
          1001.647 ( 0.002 ms): systemd-resolv/1121 getsockopt(fd: 23, level: IP, optname: 14, optval: 0x7ffee2c0c1a0, optlen: 0x7ffee2c0c1a4) = -1 ENOTCONN (Transport endpoint is not connected)
          1003.868 ( 0.010 ms): systemd-resolv/1121 getsockopt(fd: 21, level: 1, optname: 17, optval: 0x7ffee2c0c6cc, optlen: 0x7ffee2c0c6c8) = 0
          1004.036 ( 0.006 ms): systemd-resolv/1121 getsockopt(fd: 22, level: IP, optname: 14, optval: 0x7ffee2c0c1a0, optlen: 0x7ffee2c0c1a4) = -1 ENOTCONN (Transport endpoint is not connected)
          1004.087 ( 0.002 ms): systemd-resolv/1121 getsockopt(fd: 23, level: IP, optname: 14, optval: 0x7ffee2c0c1a0, optlen: 0x7ffee2c0c1a4) = -1 ENOTCONN (Transport endpoint is not connected)
        ^C#
      
      So the simple straight STRARRAY method is not enough as SOL_SOCKET is
      '1' in most architectures but some use 0xffff (alpha, mips, parisc and
      sparc), so a followup patch will create a specialized scnprintf to cover
      that.
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f1c1e45e
  18. 07 Nov, 2021 2 commits
  19. 17 Sep, 2021 1 commit
  20. 02 Aug, 2021 2 commits
  21. 15 Jul, 2021 4 commits
  22. 06 Mar, 2021 1 commit
  23. 30 Nov, 2020 5 commits