1. 20 5月, 2016 1 次提交
    • A
      perf tools: Fix usage of max_stack sysctl · fe176085
      Arnaldo Carvalho de Melo 提交于
      We cannot limit processing stacks from the current value of the sysctl,
      as we may be processing perf.data files, possibly from other machines.
      
      Instead use the old PERF_MAX_STACK_DEPTH, the sysctl default, that can
      be overriden using --max-stack or equivalent.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Milian Wolff <milian.wolff@kdab.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Zefan Li <lizefan@huawei.com>
      Fixes: 4cb93446 ("perf tools: Set the maximum allowed stack from /proc/sys/kernel/perf_event_max_stack")
      Link: http://lkml.kernel.org/n/tip-eqeutsr7n7wy0c36z24ytvii@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      fe176085
  2. 27 4月, 2016 1 次提交
  3. 25 4月, 2016 1 次提交
    • C
      perf script: Fix segfault when printing callchains · e557b674
      Chris Phlipot 提交于
      This fixes a bug caused by an unitialized callchain cursor. The crash
      frist appeared in:
      
      6f736735 ("perf evsel: Require that callchains be resolved before
      calling fprintf_{sym,callchain}")
      
      The callchain cursor is a struct that contains pointers, that when
      uninitialized will cause unpredictable behavior (usually a crash)
      when trying to append to the callchain.
      
      The existing implementation has the following issues:
      
      1. The callchain cursor used is not initialized, resulting in
      	unpredictable behavior when used.
      2. The cursor is declared on the stack. Even if it is properly initalized,
      	the implmentation will leak memory when the function returns,
      	since all the references to the callchain_nodes allocated by
      	callchain_cursor_append will be lost when the cursor goes out of
      	scope.
      3. Storing the cursor on the stack is inefficient. Even if memory is
      	properly freed when it goes out of scope, a performance penalty
      	will be incurred due to reallocation of callchain nodes.
      	callchain_cursor_append is designed to avoid these reallocations
      	when an existing cursor is reused.
      
      This patch fixes the crash by replacing cursor_callchain with a reference
      to the global callchain_cursor which also resolves all 3 issues mentioned
      above.
      
      How to reproduce the crash:
      
        $ perf record --call-graph=dwarf stress -t 1 -c 1
        $ perf script > /dev/null
        Segfault
      Signed-off-by: NChris Phlipot <cphlipot0@gmail.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Fixes: 6f736735 ("perf evsel: Require that callchains be resolved before calling fprintf_{sym,callchain}")
      Link: http://lkml.kernel.org/r/1461119531-2529-1-git-send-email-cphlipot0@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e557b674
  4. 18 4月, 2016 1 次提交
  5. 15 4月, 2016 3 次提交
  6. 13 4月, 2016 1 次提交
  7. 12 4月, 2016 3 次提交
  8. 08 4月, 2016 2 次提交
    • A
      perf script: Use readdir() instead of deprecated readdir_r() · a5e8e825
      Arnaldo Carvalho de Melo 提交于
      The readdir() function is thread safe as long as just one thread uses a
      DIR, which is the case in 'perf script', so, to avoid breaking the build
      with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
      
      See: http://man7.org/linux/man-pages/man3/readdir.3.html
      
      "However, in modern implementations (including the glibc implementation),
      concurrent calls to readdir() that specify different directory streams
      are thread-safe.  In cases where multiple threads must read from the
      same directory stream, using readdir() with external synchronization is
      still preferable to the use of the deprecated readdir_r(3) function."
      
      Noticed while building on a Fedora Rawhide docker container.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-mt3xz7n2hl49ni2vx7kuq74g@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a5e8e825
    • J
      perf script: Process event update events · 91daee30
      Jiri Olsa 提交于
      Andreas reported following command produces no output:
      
        # cat test.py
        #!/usr/bin/env python
      
        def stat__krava(cpu, thread, time, val, ena, run):
            print "event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" % \
                  ("krava", cpu, thread, time, val, ena, run)
        # perf stat -a -I 1000 -e cycles,"cpu/config=0x6530160,name=krava/" record | perf script -s test.py
        ^C
        #
      
      The reason is that 'perf script' does not process event update events and
      will never get the event name update thus the python callback is never
      called.
      
      The fix is just to add already existing callback we use in 'perf stat
      report'.
      
      Committer note:
      
      After the patch:
      
        # perf stat -a -I 1000 -e cycles,"cpu/config=0x6530160,name=krava/" record | perf script -s test.py
        event krava cpu -1, thread -1, time 1000239179, val 1789051, ena 4000690920, run 4000690920
        event krava cpu -1, thread -1, time 2000479061, val 2391338, ena 4000879596, run 4000879596
        event krava cpu -1, thread -1, time 3000740802, val 1939121, ena 4000977209, run 4000977209
        event krava cpu -1, thread -1, time 4001006730, val 2356115, ena 4001000489, run 4001000489
        ^C
        #
      Reported-by: NAndreas Hollmann <hollmann@in.tum.de>
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Milian Wolff <milian.wolff@kdab.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1460013073-18444-3-git-send-email-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      91daee30
  9. 23 3月, 2016 5 次提交
  10. 26 2月, 2016 1 次提交
  11. 24 2月, 2016 2 次提交
    • W
      perf script: Print bpf-output events in 'perf script' · 30372f04
      Wang Nan 提交于
      This patch allows 'perf script' output messages from BPF program.  For
      example, use test_bpf_output_3.c at the end of this commit message,
      
        # ./perf record -e bpf-output/no-inherit,name=evt/ \
                       -e ./test_bpf_output_3.c/map:channel.event=evt/ \
                       usleep 100000
      
        # ./perf script
                usleep  4882 21384.532523:                       evt:  ffffffff810e97d1 sys_nanosleep ([kernel.kallsyms])
            BPF output: 0000: 52 61 69 73 65 20 61 20  Raise a
                        0008: 42 50 46 20 65 76 65 6e  BPF even
                        0010: 74 21 00 00              t!..
            BPF string: "Raise a BPF event!"
      
                usleep  4882 21384.632606:                       evt:  ffffffff8105c609 kretprobe_trampoline_holder ([kernel.kallsyms
            BPF output: 0000: 52 61 69 73 65 20 61 20  Raise a
                        0008: 42 50 46 20 65 76 65 6e  BPF even
                        0010: 74 21 00 00              t!..
            BPF string: "Raise a BPF event!"
      
      Two samples from BPF output are printed by both binary and string
      format.
      
      If BPF program output something unprintable, string format is
      suppressed.
      
        /************************ BEGIN **************************/
        #include <uapi/linux/bpf.h>
        struct bpf_map_def {
               unsigned int type;
               unsigned int key_size;
               unsigned int value_size;
               unsigned int max_entries;
        };
        #define SEC(NAME) __attribute__((section(NAME), used))
        static u64 (*ktime_get_ns)(void) =
               (void *)BPF_FUNC_ktime_get_ns;
        static int (*trace_printk)(const char *fmt, int fmt_size, ...) =
               (void *)BPF_FUNC_trace_printk;
        static int (*get_smp_processor_id)(void) =
               (void *)BPF_FUNC_get_smp_processor_id;
        static int (*perf_event_output)(void *, struct bpf_map_def *, int, void *, unsigned long) =
               (void *)BPF_FUNC_perf_event_output;
      
        struct bpf_map_def SEC("maps") channel = {
               .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
               .key_size = sizeof(int),
               .value_size = sizeof(u32),
               .max_entries = __NR_CPUS__,
        };
      
        static inline int __attribute__((always_inline))
        func(void *ctx, int type)
        {
               char output_str[] = "Raise a BPF event!";
      
               perf_event_output(ctx, &channel, get_smp_processor_id(),
                                 &output_str, sizeof(output_str));
               return 0;
        }
        SEC("func_begin=sys_nanosleep")
        int func_begin(void *ctx) {return func(ctx, 1);}
        SEC("func_end=sys_nanosleep%return")
        int func_end(void *ctx) { return func(ctx, 2);}
        char _license[] SEC("license") = "GPL";
        int _version SEC("version") = LINUX_VERSION_CODE;
        /************************* END ***************************/
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1456312845-111583-3-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      30372f04
    • J
      perf script: Display data_src values · c19ac912
      Jiri Olsa 提交于
      Adding support to display data_src values, for events with data_src data
      in sample.
      
      Example:
        $ perf script
        ...
                 rcuos/3    32 [002] ... 68501042 Local RAM hit|SNP None or Hit|TLB L1 or L2 hit|LCK No   ...
                 rcuos/3    32 [002] ... 68100142 L1 hit|SNP None|TLB L1 or L2 hit|LCK No                 ...
                 swapper     0 [002] ... 68100242 LFB hit|SNP None|TLB L1 or L2 hit|LCK No                ...
                 swapper     0 [000] ... 68100142 L1 hit|SNP None|TLB L1 or L2 hit|LCK No                 ...
                 swapper     0 [000] ... 50100142 L1 hit|SNP None|TLB L2 miss|LCK No                      ...
                 rcuos/3    32 [002] ... 68100142 L1 hit|SNP None|TLB L1 or L2 hit|LCK No                 ...
         plugin-containe 16538 [000] ... 6a100142 L1 hit|SNP None|TLB L1 or L2 hit|LCK Yes                ...
                 gkrellm  1736 [000] ... 68100242 LFB hit|SNP None|TLB L1 or L2 hit|LCK No                ...
                 gkrellm  1736 [000] ... 6a100142 L1 hit|SNP None|TLB L1 or L2 hit|LCK Yes                ...
      
                                         ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                   data_src value                     data_src translation
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lkml.kernel.org/r/1456303616-26926-14-git-send-email-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c19ac912
  12. 23 2月, 2016 2 次提交
  13. 08 1月, 2016 1 次提交
    • J
      perf script: Align event name properly · 9cdbc409
      Jiri Olsa 提交于
      Adding code to align event names, so we get aligned output in case of
      multiple events with different names.
      
      Before:
        $ perf script
        :13757 13757 163918.230829: cpu/mem-snp-none/P: ffff88085f20d010
        :13757 13757 163918.230832: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
        :13757 13757 163918.230835: cpu/mem-loads,ldlat=30/P:     7f5a5f719f00
        :13758 13758 163918.230838: cpu/mem-snp-none/P: ffff88085f4ad810
        :13758 13758 163918.154093: cpu/mem-stores/P: ffff88085bb53f28
        :13757 13757 163918.155264: cpu/mem-snp-hitm/P:           601080
        ...
      
      After:
        $ perf script
        :13757 13757 163918.228831:       cpu/mem-snp-none/P: ffffffff81a841c0
        :13757 13757 163918.228834: cpu/mem-loads,ldlat=30/P:     7f5a5f719f08
        :13757 13757 163918.228837: cpu/mem-loads,ldlat=30/P:     7f5a5f719f08
        :13758 13758 163918.228837:       cpu/mem-snp-none/P: ffff88085f4ad800
        :13758 13758 163918.154093:         cpu/mem-stores/P: ffff88085bb53f28
        :13757 13757 163918.155264:       cpu/mem-snp-hitm/P:           601080
        ...
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Acked-by: NDavid Ahern <dsahern@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Noel Grandin <noelgrandin@gmail.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1452158050-28061-9-git-send-email-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9cdbc409
  14. 07 1月, 2016 4 次提交
  15. 18 12月, 2015 1 次提交
  16. 17 12月, 2015 1 次提交
  17. 11 12月, 2015 1 次提交
    • W
      perf script: Add support for PERF_TYPE_BREAKPOINT · 27cfef00
      Wang Nan 提交于
      Useful for getting stack traces for hardware breakpoint events.
      
      Test result:
      
      Before this patch:
       # ~/perf record -g -e mem:0x600980 ./sample
       [ perf record: Woken up 1 times to write data ]
       [ perf record: Captured and wrote 0.011 MB perf.data (12 samples) ]
      
       # ~/perf script
      
       # ~/perf script -F comm,tid,pid,time,event,ip,sym,dso
       sample 22520/22520 97457.836294: mem:0x600980:
                5a4ad8 __clear_user (/lib/modules/4.3.0-rc4+/build/vmlinux)
       ...
                3f41ba sys_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
                979395 return_from_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
          7f1b59719cf7 [unknown] ([unknown])
      
       sample 22520/22520 97457.836648: mem:0x600980:
                   532 main (/home/w00229757/DataBreakpoints/sample)
                 21bd5 __libc_start_main (/tmp/oxygen_root-root/lib64/libc-2.18.so)
       ...
      
      After this patch:
       # ~/perf script
       sample 22520 97457.836294: mem:0x600980:
                         5a4ad8 __clear_user (/lib/modules/4.3.0-rc4+/build/vmlinux)
       ...
                         3f41ba sys_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
                         979395 return_from_execve (/lib/modules/4.3.0-rc4+/build/vmlinux)
                   7f1b59719cf7 [unknown] ([unknown])
      
       sample 22520 97457.836648: mem:0x600980:
                            532 main (/home/w00229757/DataBreakpoints/sample)
                          21bd5 __libc_start_main (/tmp/oxygen_root-root/lib64/libc-2.18.so)
      
      Committer note:
      
      So, further testing, lets do it for a kernel global variable,
      tcp_hashinfo:
      
        # grep -w tcp_hashinfo /proc/kallsyms
        ffffffff8202fc00 B tcp_hashinfo
        #
      
      Note: allow specifying mem:tcp_hashinfo:
      
        # perf record -g -e mem:0xffffffff81c65ac0 -a
        ^C[ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.790 MB perf.data ]
        #
        # perf evlist
        mem:0xffffffff8202fc00
        # perf evlist -v
        mem:0xffffffff8202fc00: type: 5, size: 112, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CALLCHAIN|CPU, disabled: 1, inherit: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, bp_type: 3, { bp_addr, config1 }: 0xffffffff8202fc00, { bp_len, config2 }: 0x4
        #
      
      Then, after this patch:
      
        # perf script
        swapper 0 [000] 171036.986988: mem:0xffffffff8202fc00:
          8a0fb5 __inet_lookup_established (/lib/modules/4.3.0+/build/vmlinux)
          8bc09d tcp_v4_early_demux (/lib/modules/4.3.0+/build/vmlinux)
          896def ip_rcv_finish (/lib/modules/4.3.0+/build/vmlinux)
          8976c2 ip_rcv (/lib/modules/4.3.0+/build/vmlinux)
          855eba __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
          8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
          8572a8 process_backlog (/lib/modules/4.3.0+/build/vmlinux)
          856b11 net_rx_action (/lib/modules/4.3.0+/build/vmlinux)
          2a284b __do_softirq (/lib/modules/4.3.0+/build/vmlinux)
          2a2ba3 irq_exit (/lib/modules/4.3.0+/build/vmlinux)
          96b7a4 do_IRQ (/lib/modules/4.3.0+/build/vmlinux)
          969807 ret_from_intr (/lib/modules/4.3.0+/build/vmlinux)
          804c27 cpuidle_enter (/lib/modules/4.3.0+/build/vmlinux)
          2ded22 call_cpuidle (/lib/modules/4.3.0+/build/vmlinux)
          2defb6 cpu_startup_entry (/lib/modules/4.3.0+/build/vmlinux)
          95d5bc rest_init (/lib/modules/4.3.0+/build/vmlinux)
         1163ffa start_kernel ([kernel.vmlinux].init.text)
         11634d7 x86_64_start_reservations ([kernel.vmlinux].init.text)
         1163623 x86_64_start_kernel ([kernel.vmlinux].init.text)
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1449541544-67621-16-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      27cfef00
  18. 27 11月, 2015 2 次提交
  19. 30 10月, 2015 1 次提交
    • S
      perf script: Enable printing of branch stack · dc323ce8
      Stephane Eranian 提交于
      This patch improves perf script by enabling printing of the
      branch stack via the 'brstack' and 'brstacksym' arguments to
      the field selection option -F. The option is off by default
      and operates only if the perf.data file has branch stack content.
      
      The branches are printed in to/from pairs. The most recent branch
      is printed first. The number of branch entries vary based on the
      underlying hardware and filtering used.
      
      The brstack prints FROM/TO addresses in raw hexadecimal format.
      The brstacksym prints FROM/TO addresses in symbolic form wherever
      possible.
      
       $ perf script -F ip,brstack
        5d3000 0x401aa0/0x5d2000/M/-/-/-/0 ...
      
       $ perf script -F ip,brstacksym
        4011e0 noploop+0x0/noploop+0x0/P/-/-/0
      
      The notation F/T/M/X/A/C describes the attributes of the branch.
      F=from, T=to, M/P=misprediction/prediction, X=TSX, A=TSX abort, C=cycles (SKL)
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yuanfang Chen <cyfmxc@gmail.com>
      Link: http://lkml.kernel.org/r/1441039273-16260-5-git-send-email-eranian@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      dc323ce8
  20. 27 10月, 2015 1 次提交
  21. 20 10月, 2015 1 次提交
  22. 29 9月, 2015 4 次提交