1. 20 2月, 2016 10 次提交
    • A
      perf tools: Introduce opt_event_config nonterminal · 1d55e8ef
      Arnaldo Carvalho de Melo 提交于
      To remove duplicated code that differs only in using the matching
      '/a,b,c/' part or NULL if no event configuration is done ('//' or no
      pair of slashes at all).
      
      Will be used by some new targets allowing the configuration of hardware
      events, etc.
      
      Lifted part of the 'opt_event_config' nonterminal from a patch by Wang
      Nan.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Cody P Schafer <dev@codyps.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kirill Smelkov <kirr@nexedi.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/n/tip-e3xzpx9cqsmwnaguaxyw6r42@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1d55e8ef
    • W
      perf tools: Rename and move pmu_event_name to get_config_name · e814fddd
      Wang Nan 提交于
      Following commits will make more events obey /name=newname/ options.
      This patch makes pmu_event_name() a generic helper.
      
      Makes new get_config_name() accept NULL input to make life easier.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Cody P Schafer <dev@codyps.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kirill Smelkov <kirr@nexedi.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1455882283-79592-12-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e814fddd
    • W
      perf stat: Bail out on unsupported event config modifiers · 1669e509
      Wang Nan 提交于
      'perf stat' accepts some config terms but doesn't apply them. For
      example:
      
        # perf stat -e 'instructions/no-inherit/' -e 'instructions/inherit/' bash
        # ls
        # exit
      
        Performance counter stats for 'bash':
      
               266258061      instructions/no-inherit/
               266258061      instructions/inherit/
      
             1.402183915 seconds time elapsed
      
      The result is confusing, because user may expect the first
      'instructions' event exclude the 'ls' command.
      
      This patch forbid most of these config terms for 'perf stat'.
      
      Result:
      
        # ./perf stat -e 'instructions/no-inherit/' -e 'instructions/inherit/' bash
        event syntax error: 'instructions/no-inherit/'
                             \___ 'no-inherit' is not usable in 'perf stat'
        ...
      
      We can add blocked config terms back when 'perf stat' really supports them.
      
      This patch also removes unavailable config term from error message:
      
        # ./perf stat -e 'instructions/badterm/' ls
        event syntax error: 'instructions/badterm/'
                                          \___ unknown term
      
        valid terms: config,config1,config2,name
      
        # ./perf stat -e 'cpu/badterm/' ls
        event syntax error: 'cpu/badterm/'
                                 \___ unknown term
      
        valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name
      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: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Cody P Schafer <dev@codyps.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kirill Smelkov <kirr@nexedi.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1455882283-79592-11-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1669e509
    • W
      perf tools: Create config_term_names array · 17cb5f84
      Wang Nan 提交于
      config_term_names[] is introduced for future commits which will be able
      to retrieve the config name through the config term.
      
      Utilize this array in parse_events_formats_error_string() so the missing
      '{,no-}inherit' terms are added.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Cody P Schafer <dev@codyps.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kirill Smelkov <kirr@nexedi.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1455882283-79592-10-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      17cb5f84
    • W
      perf tools: Fix checking asprintf return value · 26dee028
      Wang Nan 提交于
      According to man pages, asprintf returns -1 when failure. This patch
      fixes two incorrect return value checker.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Cody P Schafer <dev@codyps.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kirill Smelkov <kirr@nexedi.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Cc: stable@vger.kernel.org # v4.4+
      Fixes: ffeb883e ("perf tools: Show proper error message for wrong terms of hw/sw events")
      Link: http://lkml.kernel.org/r/1455882283-79592-5-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      26dee028
    • W
      perf bpf: Rename bpf_prog_priv__clear() to clear_prog_priv() · 80cdce76
      Wang Nan 提交于
      The name of bpf_prog_priv__clear() doesn't follow perf's naming
      convention. bpf_prog_priv__delete() seems to be a better name. However,
      bpf_prog_priv__delete() should be a method of 'struct bpf_prog_priv',
      but its first parameter is 'struct bpf_program'.
      
      It is callback from libbpf to clear priv structures when destroying a
      bpf program. It is actually a method of bpf_program (libbpf object), but
      bpf_program__ functions should be provided by libbpf.
      
      This patch removes the prefix of that function.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Cody P Schafer <dev@codyps.com>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kirill Smelkov <kirr@nexedi.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Link: http://lkml.kernel.org/r/1455882283-79592-4-git-send-email-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      80cdce76
    • A
      perf stat: Handled scaled == -1 case for counters · b002f3bb
      Andi Kleen 提交于
      Arnaldo pointed out that the earlier cb110f47 ("perf stat: Move
      noise/running printing into printout") change changed behavior for not
      counted counters. This patch fixes it again.
      Signed-off-by: NAndi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Stephane Eranian <eranian@google.com>
      Fixes: cb110f47 ("perf stat: Move noise/running printing into printout")
      Link: http://lkml.kernel.org/r/1455749045-18098-2-git-send-email-andi@firstfloor.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b002f3bb
    • A
      perf test: Reduce the sample_freq for the 'object code reading' test · 5243ba76
      Arnaldo Carvalho de Melo 提交于
      Using 4 kHz is not necessary and sometimes is more than what was
      auto-tuned:
      
        # dmesg | grep max_sample_rate | tail -2
        [ 2499.144373] perf interrupt took too long (2501 > 2500), lowering kernel.perf_event_max_sample_rate to 50000
        [ 3592.413606] perf interrupt took too long (5069 > 5000), lowering kernel.perf_event_max_sample_rate to 25000
      
      Simulating a auto-tune of 2000 we make the test fail, as reported
      by Steven Noonan for one of his machines, so reduce it to 500 HZ,
      it is enough to get a good number of samples for this test:
      
        # perf test -v 21 2>&1  | grep '^Reading object code for memory address' | tee /tmp/out | tail -5
        Reading object code for memory address: 0x479f40
        Reading object code for memory address: 0x7f29b7eea80d
        Reading object code for memory address: 0x7f29b7eea80d
        Reading object code for memory address: 0x7f29b7eea800
        Reading object code for memory address: 0xffffffff813b2f23
        [root@jouet ~]# wc -l /tmp/out
        40 /tmp/out
        [root@jouet ~]#
      
      For systems that auto-tune below that, the previous patches will tell the
      user what is happening so that he may either ignore the result of this test or
      bump /proc/sys/kernel/perf_event_max_sample_rate.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Steven Noonan <steven@uplinklabs.net>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-6kufyy1iprdfzrbtuqgxir70@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5243ba76
    • A
      perf tests: Use perf_evlist__strerror_open() to provide hints about max_freq · 6880bbf9
      Arnaldo Carvalho de Melo 提交于
      Before:
      
        # perf test -v "code reading" 2>&1 | tail -4
        perf_evlist__open failed
        test child finished with -1
        ---- end ----
        Test object code reading: FAILED!
        #
      
      After:
      
        # perf test -v "code reading" 2>&1 | tail -7
        perf_evlist__open() failed!
        Error: Invalid argument.
        Hint:  Check /proc/sys/kernel/perf_event_max_sample_rate.
        Hint:  The current value is 1000 and 4000 is being requested.
        test child finished with -1
        ---- end ----
        Test object code reading: FAILED!
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Steven Noonan <steven@uplinklabs.net>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-ifbx7vmrc38loe6317owz2jx@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6880bbf9
    • A
      perf evlist: Handle -EINVAL for sample_freq > max_sample_rate in strerror_open() · d9aade7f
      Arnaldo Carvalho de Melo 提交于
      When running the "code reading" test we get:
      
        # perf test -v "code reading" 2>&1 | tail -5
        Parsing event 'cycles:u'
        perf_evlist__open failed
        test child finished with -1
        ---- end ----
        Test object code reading: FAILED!
        #
      
      And with -vv we get the errno value, -22, i.e. -EINVAL, but we can do
      better and handle the case at hand, with this patch it becomes:
      
        # perf test -v "code reading" 2>&1 | tail -7
        perf_evlist__open() failed!
        Error: Invalid argument.
        Hint:  Check /proc/sys/kernel/perf_event_max_sample_rate.
        Hint:  The current value is 1000 and 4000 is being requested.
        test child finished with -1
        ---- end ----
        Test object code reading: FAILED!
        #
      
      Next patch will make this 'perf test' entry to use perf_evlist__strerror()
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Steven Noonan <steven@uplinklabs.net>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-i31ai6kfefn75eapejjokfhc@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d9aade7f
  2. 18 2月, 2016 2 次提交
    • J
      perf record: Add --all-user/--all-kernel options · 85723885
      Jiri Olsa 提交于
      Allow user to easily switch all events to user or kernel space with simple
      --all-user or --all-kernel options.
      
      This will be handy within perf mem/c2c wrappers to switch easily monitoring
      modes.
      
      Committer note:
      
      Testing it:
      
        # perf record --all-kernel --all-user -a sleep 2
         Error: option `all-user' cannot be used with all-kernel
         Usage: perf record [<options>] [<command>]
            or: perf record [<options>] -- <command> [<options>]
      
              --all-user        Configure all used events to run in user space.
              --all-kernel      Configure all used events to run in kernel space.
        # perf record --all-user --all-kernel -a sleep 2
         Error: option `all-kernel' cannot be used with all-user
         Usage: perf record [<options>] [<command>]
            or: perf record [<options>] -- <command> [<options>]
      
              --all-kernel      Configure all used events to run in kernel space.
              --all-user        Configure all used events to run in user space.
        # perf record --all-user -a sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 1.416 MB perf.data (162 samples) ]
        # perf report | grep '\[k\]'
        # perf record --all-kernel -a sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 1.423 MB perf.data (296 samples) ]
        # perf report | grep '\[\.\]'
        #
      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/1455525293-8671-2-git-send-email-jolsa@kernel.org
      [ Made those options to be mutually exclusive ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      85723885
    • A
      perf evlist: Reference count the cpu and thread maps at set_maps() · a55e5663
      Arnaldo Carvalho de Melo 提交于
      We were dropping the reference we possibly held but not obtaining one
      for the new maps, which we will drop at perf_evlist__delete(), fix it.
      
      This was caught by Steven Noonan in some of the machines which would
      produce this output when caught by glibc debug mechanisms:
      
        $ sudo perf test 21
        21: Test object code reading                                 :***
        Error in `perf': corrupted double-linked list: 0x00000000023ffcd0 ***
        ======= Backtrace: =========
        /usr/lib/libc.so.6(+0x72055)[0x7f25be0f3055]
        /usr/lib/libc.so.6(+0x779b6)[0x7f25be0f89b6]
        /usr/lib/libc.so.6(+0x7a0ed)[0x7f25be0fb0ed]
        /usr/lib/libc.so.6(__libc_calloc+0xba)[0x7f25be0fceda]
        perf(parse_events_lex_init_extra+0x38)[0x4cfff8]
        perf(parse_events+0x55)[0x4a0615]
        perf(perf_evlist__config+0xcf)[0x4eeb2f]
        perf[0x479f82]
        perf(test__code_reading+0x1e)[0x47ad4e]
        perf(cmd_test+0x5dd)[0x46452d]
        perf[0x47f4e3]
        perf(main+0x603)[0x42c723]
        /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7f25be0a1610]
        perf(_start+0x29)[0x42c859]
      
      Further investigation using valgrind led to the reference count imbalance fixed
      in this patch.
      Reported-and-Tested-by: NSteven Noonan <steven@uplinklabs.net>
      Report-Link: http://lkml.kernel.org/r/CAKbGBLjC2Dx5vshxyGmQkcD+VwiAQLbHoXA9i7kvRB2-2opHZQ@mail.gmail.com
      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>
      Fixes: f30a79b0 ("perf tools: Add reference counting for cpu_map object")
      Link: http://lkml.kernel.org/n/tip-j0u1bdhr47sa511sgg76kb8h@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a55e5663
  3. 17 2月, 2016 8 次提交
  4. 16 2月, 2016 1 次提交
    • A
      perf tests: Fix build on older systems where 'signal' is reserved · 1ad826ba
      Arnaldo Carvalho de Melo 提交于
      fixing the following problems, for instance, on RHEL6.7:
      
          CC       /tmp/build/perf/tests/bp_signal.o
        cc1: warnings being treated as errors
        tests/bp_signal.c: In function ‘__event’:
        tests/bp_signal.c:106: error: declaration of ‘signal’ shadows a global declaration
        /usr/include/signal.h:101: error: shadowed declaration is here
        tests/bp_signal.c: In function ‘bp_event’:
        tests/bp_signal.c:144: error: declaration of ‘signal’ shadows a global declaration
        /usr/include/signal.h:101: error: shadowed declaration is here
        tests/bp_signal.c: In function ‘wp_event’:
        tests/bp_signal.c:149: error: declaration of ‘signal’ shadows a global declaration
        /usr/include/signal.h:101: error: shadowed declaration is here
        mv: cannot stat `/tmp/build/perf/tests/.bp_signal.o.tmp': No such file or directory
        make[3]: *** [/tmp/build/perf/tests/bp_signal.o] Error 1
        make[2]: *** [tests] Error 2
        make[1]: *** [/tmp/build/perf/perf-in.o] Error 2
        make[1]: *** Waiting for unfinished jobs....
      Reported-by: NVinson Lee <vlee@freedesktop.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: He Kuang <hekuang@huawei.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: pi3orama@163.com
      Fixes: 8fd34e1c ("perf test: Improve bp_signal")
      Link: http://lkml.kernel.org/n/tip-wlpx6tik1b0jirlkw64bv400@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1ad826ba
  5. 13 2月, 2016 6 次提交
  6. 12 2月, 2016 6 次提交
  7. 05 2月, 2016 7 次提交
    • S
      perf jit: add source line info support · 598b7c69
      Stephane Eranian 提交于
      This patch adds source line information support to perf for jitted code.
      
      The source line info must be emitted by the runtime, such as JVMTI.
      
      Perf injects extract the source line info from the jitdump file and adds
      the corresponding .debug_lines section in the ELF image generated for
      each jitted function.
      
      The source line enables matching any address in the profile with a
      source file and line number.
      
      The improvement is visible in perf annotate with the source code
      displayed alongside the assembly code.
      
      The dwarf code leverages the support from OProfile which is also
      released under GPLv2.  Copyright 2007 OProfile authors.
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Carl Love <cel@us.ibm.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John McCutchan <johnmccutchan@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pawel Moll <pawel.moll@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sonny Rao <sonnyrao@chromium.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/1448874143-7269-5-git-send-email-eranian@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      598b7c69
    • S
      perf tools: add JVMTI agent library · 209045ad
      Stephane Eranian 提交于
      This is a standalone JVMTI library to help  profile Java jitted code with perf
      record/perf report. The library is not installed or compiled automatically by
      perf Makefile. It is not used directly by perf. It is arch agnostic and has
      been tested on X86 and ARM. It needs to be used with a Java runtime, such as
      OpenJDK, as follows:
      
        $ java -agentpath:libjvmti.so .......
      
      See the "Committer Notes" below on how to build it.
      
      When used this way, java will generate a jitdump binary file in
      $HOME/.debug/java/jit/java-jit-*
      
      This binary dump file contains information to help symbolize and
      annotate jitted code.
      
      The jitdump information must be injected into the perf.data file
      using:
      
        $ perf inject --jit -i perf.data -o perf.data.jitted
      
      This injects the MMAP records to cover the jitted code and also generates
      one ELF image for each jitted function. The ELF images are created in the
      same subdir as the jitdump file. The MMAP records point there too.
      
      Then, to visualize the function or asm profile, simply use the regular
      perf commands:
      
        $ perf report -i perf.data.jitted
      
      or
      
        $ perf annotate -i perf.data.jitted
      
      JVMTI agent code adapted from the OProfile's opagent code.
      
      This version of the JVMTI agent is using the CLOCK_MONOTONIC as the time
      source to timestamp jit samples. To correlate with perf_events samples,
      it needs to run on kernel 4.0.0-rc5+ or later with the following commit
      from Peter Zijlstra:
      
        34f43927 ("perf: Add per event clockid support")
      
      With this patch recording jitted code is done as follows:
      
         $ perf record -k mono -- java -agentpath:libjvmti.so .......
      
       --------------------------------------------------------------------------
      
      Committer Notes:
      
      Extended testing instructions:
      
        $ cd tools/perf/jvmti/
        $ dnf install java-devel
        $ make
      
      Then, create some simple java stuff to record some samples:
      
        $ cat hello.java
        public class hello {
      	public static void main(String[] args) {
                       System.out.println("Hello, World");
             	}
        }
        $ javac hello.java
        $ java hello
        Hello, World
        $
      
      And then record it using this jvmti thing:
      
        $ perf record -k mono java -agentpath:/home/acme/git/linux/tools/perf/jvmti/libjvmti.so hello
        java: jvmti: jitdump in /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jit-1908.dump
        Hello, World
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.030 MB perf.data (268 samples) ]
        $
      
      Now lets insert the PERF_RECORD_MMAP2 records to point jitted mmaps to
      files created by the agent:
      
        $ perf inject --jit -i perf.data -o perf.data.jitted
      
      And finally see that it did its job:
      
        $ perf report -D -i perf.data.jitted | grep PERF_RECORD_MMAP2 | tail -5
        79197149129422 0xfe10 [0xa0]: PERF_RECORD_MMAP2 1908/1923: [0x7f172428bd60(0x80) @ 0x40 fd:02 1840554 1]: --xs /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-283.so
        79197149235701 0xfeb0 [0xa0]: PERF_RECORD_MMAP2 1908/1923: [0x7f172428ba60(0x180) @ 0x40 fd:02 1840555 1]: --xs /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-284.so
        79197149250558 0xff50 [0xa0]: PERF_RECORD_MMAP2 1908/1923: [0x7f172428b860(0x180) @ 0x40 fd:02 1840556 1]: --xs /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-285.so
        79197149714746 0xfff0 [0xa0]: PERF_RECORD_MMAP2 1908/1923: [0x7f172428b660(0x180) @ 0x40 fd:02 1840557 1]: --xs /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-286.so
        79197149806558 0x10090 [0xa0]: PERF_RECORD_MMAP2 1908/1923: [0x7f172428b460(0x180) @ 0x40 fd:02 1840558 1]: --xs /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-287.so
        $
      
      So:
      
        $ perf report -D -i perf.data | grep PERF_RECORD_MMAP2 | wc -l
        Failed to open /tmp/perf-1908.map, continuing without symbols
        21
        $ perf report -D -i perf.data.jitted | grep PERF_RECORD_MMAP2 | wc -l
        307
        $ echo $((307 - 21))
        286
        $
      
      286 extra PERF_RECORD_MMAP2 records.
      
      All for thise tiny, with just one function, ELF files:
      
        $ file /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-9.so
        /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-9.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), corrupted program header size, BuildID[sha1]=ae54a2ebc3ecf0ba547bfc8cabdea1519df5203f, not stripped
        $ readelf -sw /home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-9.so
      
        Symbol table '.symtab' contains 2 entries:
         Num:    Value          Size Type    Bind   Vis      Ndx Name
           0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
           1: 0000000000000040     9 FUNC    LOCAL  DEFAULT    1 atomic_cmpxchg_long
        $
      
      Inserted into the build-id cache:
      
        $ ls -la ~/.debug/.build-id/ae/54a2ebc3ecf0ba547bfc8cabdea1519df5203f
        lrwxrwxrwx. 1 acme acme 111 Feb  5 11:30 /home/acme/.debug/.build-id/ae/54a2ebc3ecf0ba547bfc8cabdea1519df5203f -> ../../home/acme/.debug/jit/java-jit-20160205.XXWIEDls/jitted-1908-9.so/ae54a2ebc3ecf0ba547bfc8cabdea1519df5203f
      
      Note: check why 'file' reports that 'corrupted program header size'.
      
      With a stupid java hog to do some profiling:
      
      $ cat hog.java
        public class hog {
      	private static double do_something_else(int i) {
      		double total = 0;
      		while (i > 0) {
      			total += Math.log(i--);
      		}
      		return total;
      	}
      	private static double do_something(int i) {
      		double total = 0;
      		while (i > 0) {
      			total += Math.sqrt(i--) + do_something_else(i / 100);
      		}
      		return total;
      	}
      	public static void main(String[] args) {
      		System.out.println(String.format("%s=%f & %f", args[0],
      				   do_something(Integer.parseInt(args[0])),
      				   do_something_else(Integer.parseInt(args[1]))));
      	}
        }
        $ javac hog.java
        $ perf record -F 10000 -g -k mono java -agentpath:/home/acme/git/linux/tools/perf/jvmti/libjvmti.so hog 100000 2345000
        java: jvmti: jitdump in /home/acme/.debug/jit/java-jit-20160205.XX4sqd14/jit-8670.dump
        100000=291561592.669602 & 32050989.778714
        [ perf record: Woken up 6 times to write data ]
        [ perf record: Captured and wrote 1.536 MB perf.data (12538 samples) ]
        $ perf inject --jit -i perf.data -o perf.data.jitted
      
      Looking at the 'perf report' TUI, at one expanded callchain leading
      to the jitted code:
      
        $ perf report --no-children -i perf.data.jitted
      
      Samples: 12K of event 'cycles:pp', Event count (approx.): 3829569932
        Overhead  Comm  Shared Object       Symbol
      -   93.38%  java  jitted-8670-291.so  [.] class hog.do_something_else(int)
           class hog.do_something_else(int)
         - Interpreter
            - 75.86% call_stub
                 JavaCalls::call_helper
                 jni_invoke_static
                 jni_CallStaticVoidMethod
                 JavaMain
                 start_thread
            - 17.52% JavaCalls::call_helper
                 jni_invoke_static
                 jni_CallStaticVoidMethod
                 JavaMain
                 start_thread
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Carl Love <cel@us.ibm.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John McCutchan <johnmccutchan@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pawel Moll <pawel.moll@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sonny Rao <sonnyrao@chromium.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/1448874143-7269-4-git-send-email-eranian@google.com
      [ Made it build on fedora23, added some build/usage instructions ]
      [ Check if filename != NULL in compiled_method_load_cb, fixing segfault ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      209045ad
    • S
      perf inject: Add jitdump mmap injection support · 9b07e27f
      Stephane Eranian 提交于
      This patch adds a --jit/-j option to perf inject.
      
      This options injects MMAP records into the perf.data file to cover the
      jitted code mmaps. It also emits ELF images for each function in the
      jidump file.  Those images are created where the jitdump file is.  The
      MMAP records point to that location as well.
      
      Typical flow:
      
        $ perf record -k mono -- java -agentpath:libpjvmti.so java_class
        $ perf inject --jit -i perf.data -o perf.data.jitted
        $ perf report -i perf.data.jitted
      
      Note that jitdump.h support is not limited to Java, it works with any
      jitted environment modified to emit the jitdump file format, include
      those where code can be jitted multiple times and moved around.
      
      The jitdump.h format is adapted from the Oprofile project.
      
      The genelf.c (ELF binary generation) depends on MD5 hash encoding for
      the buildid. To enable this, libssl-dev must be installed. If not, then
      genelf.c defaults to using urandom to generate the buildid, which is not
      ideal.  The Makefile auto-detects the presence on libssl-dev.
      
      This version mmaps the jitdump file to create a marker MMAP record in
      the perf.data file. The marker is used to detect jitdump and cause perf
      inject to inject the jitted mmaps and generate ELF images for jitted
      functions.
      
      In V8, the following fixes and changes were made among other things:
      
        -  the jidump header format include a new flags field to be used
           to carry information about the configuration of the runtime agent.
           Contributed by: Adrian Hunter <adrian.hunter@intel.com>
      
        - Fix mmap pgoff: MMAP event pgoff must be the offset within the ELF file
          at which the code resides.
          Contributed by: Adrian Hunter <adrian.hunter@intel.com>
      
        - Fix ELF virtual addresses: perf tools expect the ELF virtual addresses of dynamic
          objects to match the file offset.
          Contributed by: Adrian Hunter <adrian.hunter@intel.com>
      
        - JIT MMAP injection does not obey finished_round semantics. JIT MMAP injection injects all
          MMAP events in one go, so it does not obey finished_round semantics, so drop the
          finished_round events from the output perf.data file.
          Contributed by: Adrian Hunter <adrian.hunter@intel.com>
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Carl Love <cel@us.ibm.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John McCutchan <johnmccutchan@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pawel Moll <pawel.moll@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sonny Rao <sonnyrao@chromium.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/1448874143-7269-3-git-send-email-eranian@google.com
      [ Moved inject.build_ids ordering bits to a separate patch, fixed the NO_LIBELF=1 build ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9b07e27f
    • A
      perf inject: Make sure mmap records are ordered when injecting build_ids · 921f3fad
      Arnaldo Carvalho de Melo 提交于
      To make sure the mmap records are ordered correctly and so that the
      correct especially due to jitted code mmaps.
      
      We cannot generate the buildid hit list and inject the jit mmaps (will
      come right after this patch) in at the same time for now.
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Carl Love <cel@us.ibm.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John McCutchan <johnmccutchan@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pawel Moll <pawel.moll@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sonny Rao <sonnyrao@chromium.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/1448874143-7269-3-git-send-email-eranian@google.com
      [ Carved out from a larger patch ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      921f3fad
    • S
      perf build: Add libcrypto feature detection · 8ee46460
      Stephane Eranian 提交于
      Will be used to generate build-ids in the jitdump code.
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Carl Love <cel@us.ibm.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John McCutchan <johnmccutchan@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pawel Moll <pawel.moll@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sonny Rao <sonnyrao@chromium.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/1448874143-7269-3-git-send-email-eranian@google.com
      [ tools/perf/Makefile.perf comment about NO_LIBCRYPTO and added it to tests/make ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8ee46460
    • S
      perf symbols: add Java demangling support · e9c4bcdd
      Stephane Eranian 提交于
      Add Java function descriptor demangling support.  Something bfd cannot
      do.
      
      Use the JAVA_DEMANGLE_NORET flag to avoid decoding the return type of
      functions.
      Signed-off-by: NStephane Eranian <eranian@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Carl Love <cel@us.ibm.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John McCutchan <johnmccutchan@google.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pawel Moll <pawel.moll@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sonny Rao <sonnyrao@chromium.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Link: http://lkml.kernel.org/r/1448874143-7269-2-git-send-email-eranian@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e9c4bcdd
    • M
      perf tools: handle spaces in file names obtained from /proc/pid/maps · 89fee59b
      Marcin Ślusarz 提交于
      Steam frequently puts game binaries in folders with spaces.
      
      Note: "(deleted)" markers are now treated as part of the file name.
      Signed-off-by: NMarcin Ślusarz <marcin.slusarz@gmail.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Fixes: 60648033 ("perf tools: Use sscanf for parsing /proc/pid/maps")
      Link: http://lkml.kernel.org/r/20160119190303.GA17579@marcin-Inspiron-7720Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      89fee59b