1. 05 9月, 2020 4 次提交
  2. 01 9月, 2020 1 次提交
  3. 07 8月, 2020 1 次提交
    • J
      perf record: Skip side-band event setup if HAVE_LIBBPF_SUPPORT is not set · 1101c872
      Jin Yao 提交于
      We received an error report that perf-record caused 'Segmentation fault'
      on a newly system (e.g. on the new installed ubuntu).
      
        (gdb) backtrace
        #0  __read_once_size (size=4, res=<synthetic pointer>, p=0x14) at /root/0-jinyao/acme/tools/include/linux/compiler.h:139
        #1  atomic_read (v=0x14) at /root/0-jinyao/acme/tools/include/asm/../../arch/x86/include/asm/atomic.h:28
        #2  refcount_read (r=0x14) at /root/0-jinyao/acme/tools/include/linux/refcount.h:65
        #3  perf_mmap__read_init (map=map@entry=0x0) at mmap.c:177
        #4  0x0000561ce5c0de39 in perf_evlist__poll_thread (arg=0x561ce68584d0) at util/sideband_evlist.c:62
        #5  0x00007fad78491609 in start_thread (arg=<optimized out>) at pthread_create.c:477
        #6  0x00007fad7823c103 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      
      The root cause is, evlist__add_bpf_sb_event() just returns 0 if
      HAVE_LIBBPF_SUPPORT is not defined (inline function path). So it will
      not create a valid evsel for side-band event.
      
      But perf-record still creates BPF side band thread to process the
      side-band event, then the error happpens.
      
      We can reproduce this issue by removing the libelf-dev. e.g.
      1. apt-get remove libelf-dev
      2. perf record -a -- sleep 1
      
        root@test:~# ./perf record -a -- sleep 1
        perf: Segmentation fault
        Obtained 6 stack frames.
        ./perf(+0x28eee8) [0x5562d6ef6ee8]
        /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7fbfdc65f210]
        ./perf(+0x342e74) [0x5562d6faae74]
        ./perf(+0x257e39) [0x5562d6ebfe39]
        /lib/x86_64-linux-gnu/libpthread.so.0(+0x9609) [0x7fbfdc990609]
        /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7fbfdc73b103]
        Segmentation fault (core dumped)
      
      To fix this issue,
      
      1. We either install the missing libraries to let HAVE_LIBBPF_SUPPORT
         be defined.
         e.g. apt-get install libelf-dev and install other related libraries.
      
      2. Use this patch to skip the side-band event setup if HAVE_LIBBPF_SUPPORT
         is not set.
      
      Committer notes:
      
      The side band thread is not used just with BPF, it is also used with
      --switch-output-event, so narrow the ifdef to the BPF specific part.
      
      Fixes: 23cbb41c ("perf record: Move side band evlist setup to separate routine")
      Signed-off-by: NJin Yao <yao.jin@linux.intel.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jin Yao <yao.jin@intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20200805022937.29184-1-yao.jin@linux.intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1101c872
  4. 06 8月, 2020 3 次提交
    • J
      perf tools: Move clockid_res_ns under clock struct · 9d88a1a1
      Jiri Olsa 提交于
      Move the clockid_res_ns struct member to the clock struct, so we have
      the clock related stuff in one place.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Geneviève Bastien <gbastien@versatic.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jeremie Galarneau <jgalar@efficios.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lore.kernel.org/lkml/20200805093444.314999-5-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9d88a1a1
    • J
      perf header: Store clock references for -k/--clockid option · d1e325cf
      Jiri Olsa 提交于
      Add a new CLOCK_DATA feature that stores reference times when
      -k/--clockid option is specified.
      
      It contains the clock id and its reference time together with wall clock
      time taken at the 'same time', both values are in nanoseconds.
      
      The format of data is as below:
      
        struct {
             u32 version;  /* version = 1 */
             u32 clockid;
             u64 wall_clock_ns;
             u64 clockid_time_ns;
        };
      
      This clock reference times will be used in following changes to display
      wall clock for perf events.
      
      It's available only for recording with clockid specified, because it's
      the only case where we can get reference time to wallclock time. It's
      can't do that with perf clock yet.
      
      Committer testing:
      
        $ perf record -h -k
      
         Usage: perf record [<options>] [<command>]
            or: perf record [<options>] -- <command> [<options>]
      
            -k, --clockid <clockid>
                                  clockid to use for events, see clock_gettime()
      
        $ perf record -k monotonic sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.017 MB perf.data (8 samples) ]
        $ perf report --header-only | grep clockid -A1
        # event : name = cycles:u, , id = { 88815, 88816, 88817, 88818, 88819, 88820, 88821, 88822 }, size = 120, { sample_period, sample_freq } = 4000, sample_type = IP|TID|TIME|PERIOD, read_format = ID, disabled = 1, inherit = 1, exclude_kernel = 1, mmap = 1, comm = 1, freq = 1, enable_on_exec = 1, task = 1, precise_ip = 3, sample_id_all = 1, exclude_guest = 1, mmap2 = 1, comm_exec = 1, use_clockid = 1, ksymbol = 1, bpf_event = 1, clockid = 1
        # CPU_TOPOLOGY info available, use -I to display
        --
        # clockid frequency: 1000 MHz
        # cpu pmu capabilities: branches=32, max_precise=3, pmu_name=skylake
        # clockid: monotonic (1)
        # reference time: 2020-08-06 09:40:21.619290 = 1596717621.619290 (TOD) = 21931.077673635 (monotonic)
        $
      Original-patch-by: NDavid Ahern <dsahern@gmail.com>
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Geneviève Bastien <gbastien@versatic.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jeremie Galarneau <jgalar@efficios.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lore.kernel.org/lkml/20200805093444.314999-4-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d1e325cf
    • J
      perf clockid: Move parse_clockid() to new clockid object · 6953beb4
      Jiri Olsa 提交于
      Move parse_clockid and all needed clcckid related stuff into clockid
      object. We are going to add clockid_name function in following change,
      so it's better it's placed in separated object and not in
      builtin-record.c.
      
      No functional change is intended.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Geneviève Bastien <gbastien@versatic.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jeremie Galarneau <jgalar@efficios.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lore.kernel.org/lkml/20200805093444.314999-2-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6953beb4
  5. 04 8月, 2020 3 次提交
  6. 10 7月, 2020 1 次提交
  7. 03 7月, 2020 1 次提交
    • A
      perf record: Fix duplicated sideband events with Intel PT system wide tracing · 442ad225
      Adrian Hunter 提交于
      Commit 0a892c1c ("perf record: Add dummy event during system wide
      synthesis") reveals an issue with Intel PT system wide tracing.
      Specifically that Intel PT already adds a dummy tracking event, and it
      is not the first event.  Adding another dummy tracking event causes
      duplicated sideband events.  Fix by checking for an existing dummy
      tracking event first.
      
      Example showing duplicated switch events:
      
       Before:
      
         # perf record -a -e intel_pt//u uname
         Linux
         [ perf record: Woken up 1 times to write data ]
         [ perf record: Captured and wrote 0.895 MB perf.data ]
         # perf script --no-itrace --show-switch-events | head
                  swapper     0 [007]  6390.516222: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:    11/11
                  swapper     0 [007]  6390.516222: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:    11/11
                rcu_sched    11 [007]  6390.516223: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:     0/0
                rcu_sched    11 [007]  6390.516224: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:     0/0
                rcu_sched    11 [007]  6390.516227: PERF_RECORD_SWITCH_CPU_WIDE OUT          next pid/tid:     0/0
                rcu_sched    11 [007]  6390.516227: PERF_RECORD_SWITCH_CPU_WIDE OUT          next pid/tid:     0/0
                  swapper     0 [007]  6390.516228: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:    11/11
                  swapper     0 [007]  6390.516228: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:    11/11
                  swapper     0 [002]  6390.516415: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:  5556/5559
                  swapper     0 [002]  6390.516416: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:  5556/5559
      
       After:
      
         # perf record -a -e intel_pt//u uname
         Linux
         [ perf record: Woken up 1 times to write data ]
         [ perf record: Captured and wrote 0.868 MB perf.data ]
         #  perf script --no-itrace --show-switch-events | head
                  swapper     0 [005]  6450.567013: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:  7179/7181
                     perf  7181 [005]  6450.567014: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:     0/0
                     perf  7181 [005]  6450.567028: PERF_RECORD_SWITCH_CPU_WIDE OUT          next pid/tid:     0/0
                  swapper     0 [005]  6450.567029: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:  7179/7181
                  swapper     0 [005]  6450.571699: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:    11/11
                rcu_sched    11 [005]  6450.571700: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:     0/0
                rcu_sched    11 [005]  6450.571702: PERF_RECORD_SWITCH_CPU_WIDE OUT          next pid/tid:     0/0
                  swapper     0 [005]  6450.571703: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:    11/11
                  swapper     0 [005]  6450.579703: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt  next pid/tid:    11/11
                rcu_sched    11 [005]  6450.579704: PERF_RECORD_SWITCH_CPU_WIDE IN           prev pid/tid:     0/0
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lore.kernel.org/lkml/20200629091955.17090-3-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      442ad225
  8. 23 6月, 2020 2 次提交
  9. 30 5月, 2020 1 次提交
    • S
      perf tools: Add optional support for libpfm4 · 70943490
      Stephane Eranian 提交于
      This patch links perf with the libpfm4 library if it is available and
      LIBPFM4 is passed to the build. The libpfm4 library contains hardware
      event tables for all processors supported by perf_events. It is a helper
      library that helps convert from a symbolic event name to the event
      encoding required by the underlying kernel interface. This library is
      open-source and available from: http://perfmon2.sf.net.
      
      With this patch, it is possible to specify full hardware events by name.
      Hardware filters are also supported. Events must be specified via the
      --pfm-events and not -e option. Both options are active at the same time
      and it is possible to mix and match:
      
        $ perf stat --pfm-events inst_retired:any_p:c=1:i -e cycles ....
      
      One needs to explicitely ask for its inclusion by using the LIBPFM4 make
      command line option, ie its opt-in rather than opt-out of feature
      detection and build support.
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Reviewed-by: NIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Andrii Nakryiko <andriin@fb.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Igor Lubashev <ilubashe@akamai.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Jiwei Sun <jiwei.sun@windriver.com>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Yonghong Song <yhs@fb.com>
      Cc: bpf@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Cc: yuzhoujian <yuzhoujian@didichuxing.com>
      Link: http://lore.kernel.org/lkml/20200505182943.218248-2-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      70943490
  10. 28 5月, 2020 3 次提交
    • A
      perf record: Respect --no-switch-events · 16b4b4e1
      Adrian Hunter 提交于
      Context switch events are added automatically by Intel PT and Coresight.
      
      Make it possible to suppress them. That is useful for tracing the
      scheduler without the disturbance that the switch event processing
      creates.
      
      Example:
      
        Prerequisites:
      
          $ which perf
          ~/bin/perf
          $ sudo setcap "cap_sys_rawio,cap_sys_admin,cap_sys_ptrace,cap_syslog,cap_ipc_lock=ep" ~/bin/perf
          $ sudo chmod +r /proc/kcore
      
        Before:
      
          $ perf record --no-switch-events --kcore -a -e intel_pt//k -- sleep 0.001
          [ perf record: Woken up 1 times to write data ]
          [ perf record: Captured and wrote 0.938 MB perf.data ]
          $ perf script -D | grep PERF_RECORD_SWITCH | wc -l
          572
      
        After:
      
          $ perf record --no-switch-events --kcore -a -e intel_pt//k -- sleep 0.001
          Warning:
          Intel Processor Trace decoding will not be possible except for kernel tracing!
          [ perf record: Woken up 1 times to write data ]
          [ perf record: Captured and wrote 0.838 MB perf.data ]
          $ perf script -D | grep PERF_RECORD_SWITCH | wc -l
          0
      
          $ sudo chmod go-r /proc/kcore
          $ sudo setcap -r ~/bin/perf
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Link: http://lore.kernel.org/lkml/20200528120859.21604-1-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      16b4b4e1
    • A
      perf record: Use an eventfd to wakeup when done · da231338
      Anand K Mistry 提交于
      The setting and checking of 'done' contains a rare race where the signal
      handler setting 'done' is run after checking to break the loop, but
      before waiting in evlist__poll(). In this case, the main loop won't wake
      up until either another signal is sent, or the perf data fd causes a
      wake up.
      
      The following simple script can trigger this condition (but you might
      need to run it for several hours):
      
      for ((i = 0; i >= 0; i++)) ; do
        echo "Loop $i"
        delay=$(echo "scale=4; 0.1 * $RANDOM/32768" | bc)
        ./perf record -- sleep 30000000 >/dev/null&
        pid=$!
        sleep $delay
        kill -TERM $pid
        echo "PID $pid"
        wait $pid
      done
      
      At some point, the loop will stall. Adding logging, even though perf has
      received the SIGTERM and set 'done = 1', perf will remain sleeping until
      a second signal is sent.
      
      Committer notes:
      
      Make this dependent on HAVE_EVENTFD_SUPPORT, so that we continue
      building on older systems without the eventfd syscall.
      Signed-off-by: NAnand K Mistry <amistry@google.com>
      Acked-by: NJiri Olsa <jolsa@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.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/20200513122012.v3.1.I4d7421c6bbb1f83ea58419082481082e19097841@changeidSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      da231338
    • I
      perf record: Add dummy event during system wide synthesis · 0a892c1c
      Ian Rogers 提交于
      During the processing of /proc during event synthesis new processes may
      start. Add a dummy event if /proc is to be processed, to capture mmaps
      for starting processes. This reuses the existing logic for
      initial-delay.
      
      v3 fixes the attr test of test-record-C0
      v2 fixes the dummy event configuration and a branch stack issue.
      Suggested-by: NStephane Eranian <eranian@google.com>
      Signed-off-by: NIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      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: http://lore.kernel.org/lkml/20200422173615.59436-1-irogers@google.com
      [ split from a larger patch ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0a892c1c
  11. 06 5月, 2020 8 次提交
    • A
      perf evsel: Rename perf_evsel__group_idx() to evsel__group_idx() · 2bb72dbb
      Arnaldo Carvalho de Melo 提交于
      As it is a 'struct evsel' method, not part of tools/lib/perf/, aka
      libperf, to whom the perf_ prefix belongs.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      2bb72dbb
    • A
      perf evsel: Rename perf_evsel__fallback() to evsel__fallback() · ae430892
      Arnaldo Carvalho de Melo 提交于
      As it is a 'struct evsel' method, not part of tools/lib/perf/, aka
      libperf, to whom the perf_ prefix belongs.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ae430892
    • A
      perf evsel: Rename *perf_evsel__*name() to *evsel__*name() · 8ab2e96d
      Arnaldo Carvalho de Melo 提交于
      As they are 'struct evsel' methods or related routines, not part of
      tools/lib/perf/, aka libperf, to whom the perf_ prefix belongs.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8ab2e96d
    • A
      perf record: Move side band evlist setup to separate routine · 23cbb41c
      Arnaldo Carvalho de Melo 提交于
      It is quite big by now, move that code to a separate
      record__setup_sb_evlist() routine.
      Suggested-by: NJiri Olsa <jolsa@redhat.com>
      Acked-by: NJiri Olsa <jolsa@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Link: http://lore.kernel.org/lkml/20200429131106.27974-9-acme@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      23cbb41c
    • A
      perf record: Introduce --switch-output-event · 899e5ffb
      Arnaldo Carvalho de Melo 提交于
      Now we can use it with --overwrite to have a flight recorder mode that
      gets snapshot requests from arbitrary events that are processed in the
      side band thread together with the PERF_RECORD_BPF_EVENT processing.
      
      Example:
      
      To collect scheduler events until a recvmmsg syscall happens, system
      wide:
      
        [root@five a]# rm -f perf.data.2020042717*
        [root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg
        [ perf record: dump data: Woken up 1 times ]
        [ perf record: Dump perf.data.2020042717585458 ]
        [ perf record: dump data: Woken up 1 times ]
        [ perf record: Dump perf.data.2020042717590235 ]
        [ perf record: dump data: Woken up 1 times ]
        [ perf record: Dump perf.data.2020042717590398 ]
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Dump perf.data.2020042717590511 ]
        [ perf record: Captured and wrote 7.244 MB perf.data.<timestamp> ]
      
      So in the above case we had 3 snapshots, the fourth was forced by
      control+C:
      
        [root@five a]# ls -la
        total 20440
        drwxr-xr-x.  2 root root    4096 Apr 27 17:59 .
        dr-xr-x---. 12 root root    4096 Apr 27 17:46 ..
        -rw-------.  1 root root 3936125 Apr 27 17:58 perf.data.2020042717585458
        -rw-------.  1 root root 5074869 Apr 27 17:59 perf.data.2020042717590235
        -rw-------.  1 root root 4291037 Apr 27 17:59 perf.data.2020042717590398
        -rw-------.  1 root root 7617037 Apr 27 17:59 perf.data.2020042717590511
        [root@five a]#
      
      One can make this more precise by adding the switch output event to the
      main -e events list, as since this is done asynchronously, a few events
      after the signal event will appear in the snapshots, as can be seen
      with:
      
        [root@five a]# rm -f perf.data.20200427175*
        [root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg
        [ perf record: dump data: Woken up 1 times ]
        [ perf record: Dump perf.data.2020042718024203 ]
        [ perf record: dump data: Woken up 1 times ]
        [ perf record: Dump perf.data.2020042718024301 ]
        [ perf record: dump data: Woken up 1 times ]
        [ perf record: Dump perf.data.2020042718024484 ]
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Dump perf.data.2020042718024562 ]
        [ perf record: Captured and wrote 7.337 MB perf.data.<timestamp> ]
        [root@five a]# perf script -i perf.data.2020042718024203 | tail -15
             PacerThread 148586 [005] 122.830729: sched:sched_switch: prev_comm=PacerThread prev_pid=148586...
                 swapper      0 [000] 122.833588: sched:sched_switch: prev_comm=swapper/0 prev_pid=...
          NetworkManager   1251 [000] 122.833619: syscalls:sys_enter_recvmmsg: fd: 0x0000001c, mmsg: 0x7ffe83054a1...
                 swapper      0 [002] 122.833624: sched:sched_switch: prev_comm=swapper/2 prev_pid=...
                 swapper      0 [003] 122.833624: sched:sched_switch: prev_comm=swapper/3 prev_pid=...
          NetworkManager   1251 [000] 122.833626: syscalls:sys_exit_recvmmsg: 0x1
         kworker/3:3-eve 158946 [003] 122.833628: sched:sched_switch: prev_comm=kworker/3:3 prev_pid=15894...
                 swapper      0 [004] 122.833641: sched:sched_switch: prev_comm=swapper/4 prev_pid=...
          NetworkManager   1251 [000] 122.833642: sched:sched_switch: prev_comm=NetworkManage...
                    perf 228273 [002] 122.833645: sched:sched_switch: prev_comm=perf prev_pid=22827...
                 swapper      0 [011] 122.833646: sched:sched_switch: prev_comm=swapper/1...
                 swapper      0 [002] 122.833648: sched:sched_switch: prev_comm=swapper/...
         kworker/0:2-eve 207387 [000] 122.833648: sched:sched_switch: prev_comm=kworker/0:2 prev_pid=20738...
         kworker/2:3-eve 232038 [002] 122.833652: sched:sched_switch: prev_comm=kworker/2:3 prev_pid=23203...
                    perf 235825 [003] 122.833653: sched:sched_switch: prev_comm=perf prev_pid=23582...
        [root@five a]#
      Acked-by: NJiri Olsa <jolsa@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lore.kernel.org/lkml/20200429131106.27974-8-acme@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      899e5ffb
    • A
      perf bpf: Decouple creating the evlist from adding the SB event · b38d85ef
      Arnaldo Carvalho de Melo 提交于
      Renaming bpf_event__add_sb_event() to evlist__add_sb_event() and
      requiring that the evlist be allocated beforehand.
      
      This will allow using the same side band thread and evlist to be used
      for multiple purposes in addition to react to PERF_RECORD_BPF_EVENT soon
      after they are generated.
      Acked-by: NJiri Olsa <jolsa@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Link: http://lore.kernel.org/lkml/20200429131106.27974-4-acme@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b38d85ef
    • A
      perf record: Move sb_evlist to 'struct record' · bc477d79
      Arnaldo Carvalho de Melo 提交于
      Where state related to a 'perf record' session is grouped.
      Acked-by: NJiri Olsa <jolsa@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Link: http://lore.kernel.org/lkml/20200429131106.27974-2-acme@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      bc477d79
    • A
      perf tools: Move routines that probe for perf API features to separate file · 40c7d246
      Arnaldo Carvalho de Melo 提交于
      Trying to disentangle this a bit further, unfortunately it uses
      parse_events(), its interesting to have it separated anyway, so do it.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      40c7d246
  12. 23 4月, 2020 1 次提交
    • S
      perf record: Add num-synthesize-threads option · d99c22ea
      Stephane Eranian 提交于
      To control degree of parallelism of the synthesize_mmap() code which
      is scanning /proc/PID/task/PID/maps and can be time consuming.
      Mimic perf top way of handling the option.
      If not specified will default to 1 thread, i.e. default behavior before
      this option.
      
      On a desktop computer the processing of /proc/PID/task/PID/maps isn't
      slow enough to warrant parallel processing and the thread creation has
      some cost - hence the default of 1. On a loaded server with
      >100 cores it is possible to see synthesis times in the order of
      seconds and in this case having the option is desirable.
      
      As the processing is a synchronization point, it is legitimate to worry if
      Amdahl's law will apply to this patch. Profiling with this patch in
      place:
      https://lore.kernel.org/lkml/20200415054050.31645-4-irogers@google.com/
      shows:
      ...
            - 32.59% __perf_event__synthesize_threads
               - 32.54% __event__synthesize_thread
                  + 22.13% perf_event__synthesize_mmap_events
                  + 6.68% perf_event__get_comm_ids.constprop.0
                  + 1.49% process_synthesized_event
                  + 1.29% __GI___readdir64
                  + 0.60% __opendir
      ...
      That is the processing is 1.49% of execution time and there is plenty to
      make parallel. This is shown in the benchmark in this patch:
      
      https://lore.kernel.org/lkml/20200415054050.31645-2-irogers@google.com/
      
        Computing performance of multi threaded perf event synthesis by
        synthesizing events on CPU 0:
         Number of synthesis threads: 1
           Average synthesis took: 127729.000 usec (+- 3372.880 usec)
           Average num. events: 21548.600 (+- 0.306)
           Average time per event 5.927 usec
         Number of synthesis threads: 2
           Average synthesis took: 88863.500 usec (+- 385.168 usec)
           Average num. events: 21552.800 (+- 0.327)
           Average time per event 4.123 usec
         Number of synthesis threads: 3
           Average synthesis took: 83257.400 usec (+- 348.617 usec)
           Average num. events: 21553.200 (+- 0.327)
           Average time per event 3.863 usec
         Number of synthesis threads: 4
           Average synthesis took: 75093.000 usec (+- 422.978 usec)
           Average num. events: 21554.200 (+- 0.200)
           Average time per event 3.484 usec
         Number of synthesis threads: 5
           Average synthesis took: 64896.600 usec (+- 353.348 usec)
           Average num. events: 21558.000 (+- 0.000)
           Average time per event 3.010 usec
         Number of synthesis threads: 6
           Average synthesis took: 59210.200 usec (+- 342.890 usec)
           Average num. events: 21560.000 (+- 0.000)
           Average time per event 2.746 usec
         Number of synthesis threads: 7
           Average synthesis took: 54093.900 usec (+- 306.247 usec)
           Average num. events: 21562.000 (+- 0.000)
           Average time per event 2.509 usec
         Number of synthesis threads: 8
           Average synthesis took: 48938.700 usec (+- 341.732 usec)
           Average num. events: 21564.000 (+- 0.000)
           Average time per event 2.269 usec
      
      Where average time per synthesized event goes from 5.927 usec with 1
      thread to 2.269 usec with 8. This isn't a linear speed up as not all of
      synthesize code has been made parallel. If the synthesis time was about
      10 seconds then using 8 threads may bring this down to less than 4.
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Reviewed-by: NIan Rogers <irogers@google.com>
      Acked-by: NJiri Olsa <jolsa@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tony Jones <tonyj@suse.de>
      Cc: yuzhoujian <yuzhoujian@didichuxing.com>
      Link: http://lore.kernel.org/lkml/20200422155038.9380-1-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d99c22ea
  13. 03 4月, 2020 2 次提交
  14. 06 1月, 2020 1 次提交
  15. 29 11月, 2019 1 次提交
  16. 22 11月, 2019 1 次提交
  17. 18 11月, 2019 1 次提交
  18. 07 11月, 2019 3 次提交
    • J
      perf record: Add support for limit perf output file size · 6d575816
      Jiwei Sun 提交于
      The patch adds a new option to limit the output file size, then based on
      it, we can create a wrapper of the perf command that uses the option to
      avoid exhausting the disk space by the unconscious user.
      
      In order to make the perf.data parsable, we just limit the sample data
      size, since the perf.data consists of many headers and sample data and
      other data, the actual size of the recorded file will bigger than the
      setting value.
      
      Testing it:
      
        # ./perf record -a -g --max-size=10M
        Couldn't synthesize bpf events.
        [ perf record: perf size limit reached (10249 KB), stopping session ]
        [ perf record: Woken up 32 times to write data ]
        [ perf record: Captured and wrote 10.133 MB perf.data (71964 samples) ]
      
        # ls -lh perf.data
        -rw------- 1 root root 11M Oct 22 14:32 perf.data
      
        # ./perf record -a -g --max-size=10K
        [ perf record: perf size limit reached (10 KB), stopping session ]
        Couldn't synthesize bpf events.
        [ perf record: Woken up 0 times to write data ]
        [ perf record: Captured and wrote 1.546 MB perf.data (69 samples) ]
      
        # ls -l perf.data
        -rw------- 1 root root 1626952 Oct 22 14:36 perf.data
      
      Committer notes:
      
      Fixed the build in multiple distros by using PRIu64 to print u64 struct
      members, fixing this:
      
        builtin-record.c: In function 'record__write':
        builtin-record.c:150:5: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'u64' [-Werror=format=]
             rec->bytes_written >> 10);
             ^
          CC       /tmp/build/pe
      Signed-off-by: NJiwei Sun <jiwei.sun@windriver.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Richard Danter <richard.danter@windriver.com>
      Link: http://lore.kernel.org/lkml/20191022080901.3841-1-jiwei.sun@windriver.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6d575816
    • A
      perf record: Put a copy of kcore into the perf.data directory · eeb399b5
      Adrian Hunter 提交于
      Add a new 'perf record' option '--kcore' which will put a copy of
      /proc/kcore, kallsyms and modules into a perf.data directory. Note, that
      without the --kcore option, output goes to a file as previously.  The
      tools' -o and -i options work with either a file name or directory name.
      
      Example:
      
        $ sudo perf record --kcore uname
      
        $ sudo tree perf.data
        perf.data
        ├── kcore_dir
        │   ├── kallsyms
        │   ├── kcore
        │   └── modules
        └── data
      
        $ sudo perf script -v
        build id event received for vmlinux: 1eaa285996affce2d74d8e66dcea09a80c9941de
        build id event received for [vdso]: 8bbaf5dc62a9b644b4d4e4539737e104e4a84541
        Samples for 'cycles' event do not have CPU attribute set. Skipping 'cpu' field.
        Using CPUID GenuineIntel-6-8E-A
        Using perf.data/kcore_dir/kcore for kernel data
        Using perf.data/kcore_dir/kallsyms for symbols
                   perf 19058 506778.423729:          1 cycles:  ffffffffa2caa548 native_write_msr+0x8 (vmlinux)
                   perf 19058 506778.423733:          1 cycles:  ffffffffa2caa548 native_write_msr+0x8 (vmlinux)
                   perf 19058 506778.423734:          7 cycles:  ffffffffa2caa548 native_write_msr+0x8 (vmlinux)
                   perf 19058 506778.423736:        117 cycles:  ffffffffa2caa54a native_write_msr+0xa (vmlinux)
                   perf 19058 506778.423738:       2092 cycles:  ffffffffa2c9b7b0 native_apic_msr_write+0x0 (vmlinux)
                   perf 19058 506778.423740:      37380 cycles:  ffffffffa2f121d0 perf_event_addr_filters_exec+0x0 (vmlinux)
                  uname 19058 506778.423751:     582673 cycles:  ffffffffa303a407 propagate_protected_usage+0x147 (vmlinux)
                  uname 19058 506778.423892:    2241841 cycles:  ffffffffa2cae0c9 unwind_next_frame.part.5+0x79 (vmlinux)
                  uname 19058 506778.424430:    2457397 cycles:  ffffffffa3019232 check_memory_region+0x52 (vmlinux)
      
      Committer testing:
      
        # rm -rf perf.data*
        # perf record sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.024 MB perf.data (7 samples) ]
        # ls -l perf.data
        -rw-------. 1 root root 34772 Oct 21 11:08 perf.data
        # perf record --kcore uname
        Linux
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.024 MB perf.data (7 samples) ]
        ls[root@quaco ~]# ls -lad perf.data*
        drwx------. 3 root root  4096 Oct 21 11:08 perf.data
        -rw-------. 1 root root 34772 Oct 21 11:08 perf.data.old
        # perf evlist -v
        cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
        # perf evlist -v -i perf.data/data
        cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
        #
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Link: http://lore.kernel.org/lkml/20191004083121.12182-6-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      eeb399b5
    • A
      perf data: Support single perf.data file directory · 46e201ef
      Adrian Hunter 提交于
      Support directory output that contains a regular perf.data file, named
      "data". By default the directory is named perf.data i.e.
      	perf.data
      	└── data
      
      Most of the infrastructure to support a directory is already there. This
      patch makes the changes needed to support the format above.
      
      Presently there is no 'perf record' option to output a directory.
      
      This is preparation for adding support for putting a copy of /proc/kcore in
      the directory.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Link: http://lore.kernel.org/lkml/20191004083121.12182-5-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      46e201ef
  19. 10 10月, 2019 2 次提交