1. 08 4月, 2016 1 次提交
    • 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
  2. 23 3月, 2016 5 次提交
  3. 26 2月, 2016 1 次提交
  4. 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
  5. 23 2月, 2016 2 次提交
  6. 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
  7. 07 1月, 2016 4 次提交
  8. 18 12月, 2015 1 次提交
  9. 17 12月, 2015 1 次提交
  10. 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
  11. 27 11月, 2015 2 次提交
  12. 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
  13. 27 10月, 2015 1 次提交
  14. 20 10月, 2015 1 次提交
  15. 29 9月, 2015 4 次提交
  16. 03 9月, 2015 1 次提交
    • A
      perf tools: Fix use of wrong event when processing exit events · 53ff6bc3
      Adrian Hunter 提交于
      In a couple of cases the 'comm' member of 'union event' has been used
      instead of the correct member ('fork') when processing exit events.
      
      In the cases where it has been used incorrectly, only the 'pid' and
      'tid' are affected.  The 'pid' value would be correct anyway because it
      is in the same position in 'comm' and 'fork' events, but the 'tid' would
      have been incorrectly assigned from 'ppid'.
      
      However, for exit events, the kernel puts the current task in the 'ppid'
      and 'ttid' which is the same as the exiting task.  That is 'ppid' ==
      'pid' and if the task is not multi-threaded, 'pid' == 'tid' i.e. the
      data goes wrong only when tracing multi-threaded programs.
      
      It is hard to find an example of how this would produce an error in
      practice.  There are 3 occurences of the fix:
      
      1. perf script is only affected if !sample_id_all which only happens on
        old kernels.
      
      2. intel_pt is only affected when decoding without timestamps
         and would probably still decode correctly - the exit event is
         only used to flush out data which anyway gets flushed at the
         end of the session
      
      3. intel_bts also uses the exit event to flush data which
         would probably not cause errors as it would get flushed at
         the end of the session instead
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/1439888825-27708-1-git-send-email-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      53ff6bc3
  17. 01 9月, 2015 1 次提交
  18. 28 8月, 2015 1 次提交
  19. 17 8月, 2015 1 次提交
  20. 10 8月, 2015 1 次提交
  21. 04 8月, 2015 1 次提交
  22. 24 7月, 2015 3 次提交
  23. 09 5月, 2015 1 次提交
    • A
      perf machine: Protect the machine->threads with a rwlock · b91fc39f
      Arnaldo Carvalho de Melo 提交于
      In addition to using refcounts for the struct thread lifetime
      management, we need to protect access to machine->threads from
      concurrent access.
      
      That happens in 'perf top', where a thread processes events, inserting
      and deleting entries from that rb_tree while another thread decays
      hist_entries, that end up dropping references and ultimately deleting
      threads from the rb_tree and releasing its resources when no further
      hist_entry (or other data structures, like in 'perf sched') references
      it.
      
      So the rule is the same for refcounts + protected trees in the kernel,
      get the tree lock, find object, bump the refcount, drop the tree lock,
      return, use object, drop the refcount if no more use of it is needed,
      keep it if storing it in some other data structure, drop when releasing
      that data structure.
      
      I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
      "perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
      
      The addr_location__put() one is because as we return references to
      several data structures, we may end up adding more reference counting
      for the other data structures and then we'll drop it at
      addr_location__put() time.
      Acked-by: NDavid Ahern <dsahern@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Don Zickus <dzickus@redhat.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b91fc39f
  24. 04 5月, 2015 1 次提交
  25. 29 4月, 2015 1 次提交
    • A
      perf script: Add field option 'flags' to print sample flags · 400ea6d3
      Adrian Hunter 提交于
      Instruction tracing will typically have access to information about the
      instruction being executed for a particular ip sample.  Some of that
      information will be available in the 'flags' member of struct
      perf_sample.
      
      With the addition of transactions events synthesis to Instruction
      Tracing options, there is a need to be able easily to see the flags
      because they show whether the ip is at the start, commit or abort of a
      tranasaction.
      
      Consequently add an option to display the flags.
      
      The flags are "bcrosyiABEx" which stand for branch, call, return,
      conditional, system, asynchronous, interrupt, transaction abort, trace
      begin, trace end, and in transaction, respectively.
      
      Example using Intel PT:
      
      perf script -fip,time,event,sym,addr,flags
      
      ...
       1288.721584105: branches:u:   bo              401146 main =>           401152 main
       1288.721584105: transactions:   x                   0           401164 main
       1288.721584105: branches:u:   bx              40117c main =>           40119b main
       1288.721584105: branches:u:   box             4011a4 main =>           40117e main
       1288.721584105: branches:u:   bcx             401187 main =>           401094 g
      ...
       1288.721591645: branches:u:   bx              4010c4 g =>           4010cb g
       1288.721591645: branches:u:   brx             4010cc g =>           401189 main
       1288.721591645: transactions:                       0           4011a6 main
       1288.721593199: branches:u:   b               4011a9 main =>           4011af main
       1288.721593199: branches:u:   bo              4011bc main =>           40113e main
       1288.721593199: branches:u:   b               401150 main =>           40115a main
       1288.721593199: transactions:   x                   0           401164 main
       1288.721593199: branches:u:   bx              40117c main =>           40119b main
       1288.721593199: branches:u:   box             4011a4 main =>           40117e main
       1288.721593199: branches:u:   bcx             401187 main =>           40105e f
      ...
       1288.722284747: branches:u:   brx             401093 f =>           401189 main
       1288.722284747: branches:u:   box             4011a4 main =>           40117e main
       1288.722284747: branches:u:   bcx             401187 main =>           40105e f
       1288.722285883: transactions:   bA                  0           401071 f
       1288.722285883: branches:u:   bA              401071 f =>           40116a main
       1288.722285883: branches:u:   bE              40116a main =>                0 [unknown]
       1288.722297174: branches:u:   bB                   0 [unknown] =>           40116a main
      ...
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lkml.kernel.org/r/1428594864-29309-26-git-send-email-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      400ea6d3