linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] perf: add support for profiling jitted code
@ 2015-02-10 23:42 Stephane Eranian
  2015-02-10 23:42 ` [PATCH 1/4] perf tools: add Java demangling support Stephane Eranian
                   ` (5 more replies)
  0 siblings, 6 replies; 26+ messages in thread
From: Stephane Eranian @ 2015-02-10 23:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, peterz, mingo, ak, jolsa, namhyung, cel, sukadev, sonnyrao,
	johnmccutchan

This patch series extends perf record/report/annotate to enable
profiling of jitted (just-in-time compiled) code. The current
perf tool provides very limited support for profiling jitted
code for some runtime environments. But the support is experimental
and cannot be used in complex environments. It relies on files
in /tmp, for instance. It does not support annotate mode or
rejitted code.

This patch series adds a better way of profiling jitted code
with the following advantages:
   - support any jitted code environment (some with modifications)
   - support Java runtime with JVMTI interface with no modifications
   - provides a portable JVMTI agent library
   - known to support V8 runtime
   - known to support DART runtime
   - supports code rejitting and movements
   - no files in /tmp
   - meta-data file is unique to each run
   - no changes to perf report/annotate

The support is based on cooperation with the runtime. For Java runtimes,
supporting the JVMTI interface, there is no change necessary. For other
runtimes, modifications are necessary to emit the meta-data necessary
to support symbolization and annotation of the samples. Those modifications
are fairly straighforward and already tested on V8 and DART.

The jit environment emits a binary dump file which contains the jitted
code (in raw format) and meta-data describing the mapping of functions.
The binary format is documented in the jitdump.h header file. It is
adapted from the OProfile jitdump format.

To enable synchronization of the runtime MMAPs with those recorded by
the kernel on behalf of the perf tool, the runtime needs to timestamp
any record in the dump file using the same time source. The current
patch series is relying on Sonny Rao's posix-clock patch series
posted on LKML in 2013. The link to the patches is:
	https://lkml.org/lkml/2013/12/6/1044

Without this driver installed, records emitted by the runtime cannot
be properly synchronized (inserted in the flow on MMAPS) and symbolization
may be incorrect, especially for runtimes moving code around.

The current support only works when the runtime is monitored from
start to finish: perf record java --agenpath:libpfmjvmti.so my_class.

Once the run is completed, the jitdump file needs to be injected into
the perf.data file. This is accomplished by using the perf inject command.
This will also generate an ELF image for each jitted function. The
inject MMAP records will point to those ELF images. The reasoning
behind using ELF images is that it makes processing for perf report
and annotate automatic and transparent. It also makes it easier to
package and analyze on a remote machine. 

The reporting is unchanged, simply invoke perf report or perf annotate
on the modified perf.data file. The jitted code will appear symbolized
and the assembly view will display the instruction level profile!

As an added bonus, the series includes support for demangling function
signature from OpenJDK.

The current patch series does not include support for source line
information. Therefore, the source code cannot yet be displayed
in perf annotate. This will come in a later update.

Furthermore, we believe there is a way to skip the perf inject phase
and have perf report/annotate directly inject the MMAP records 
on the fly during processing of the perf.data file. Perf report would
also generate the ELF files if necessary. Such optimization, would
make using this extension seamless in system-wide mode and larger
environments. This will be added in a later update as well.

To use the new feature:
  - install the posix clock driver
  - make sure you chmod 644 /dev/trace_clock
  - compile perf
  - cd tools/perf/jvmti; make; install wherever is appropriate

  Example using openJDK:
   $ perf record java -agentpath:libjvmti.so my_class
   java: jvmti: jitdump in $HOME/.debug/jit/java-jit-20150207.XXL9649H/jit-6320.dump
   $ perf inject -i perf.data -j $HOME/.debug/jit/java-jit-20150207.XXL9649H/jit-6320.dump -o perf.data.jitted
   $ perf report -i perf.data.jitted

Thanks to all the contributors and testers.

Enjoy,

Stephane Eranian (4):
  perf tools: add Java demangling support
  perf tools: pass timestamp to map_init
  perf inject: add jitdump mmap injection support
  perf tools: add JVMTI agent library

 tools/perf/Documentation/perf-inject.txt |  11 +
 tools/perf/Makefile.perf                 |   6 +-
 tools/perf/builtin-inject.c              | 205 ++++++++++++++
 tools/perf/jvmti/Makefile                |  70 +++++
 tools/perf/jvmti/jvmti_agent.c           | 349 +++++++++++++++++++++++
 tools/perf/jvmti/jvmti_agent.h           |  23 ++
 tools/perf/jvmti/libjvmti.c              | 149 ++++++++++
 tools/perf/util/genelf.c                 | 463 +++++++++++++++++++++++++++++++
 tools/perf/util/genelf.h                 |   6 +
 tools/perf/util/jit.h                    |  27 ++
 tools/perf/util/jitdump.c                | 233 ++++++++++++++++
 tools/perf/util/jitdump.h                |  92 ++++++
 tools/perf/util/machine.c                |   8 +-
 tools/perf/util/map.c                    |   9 +-
 tools/perf/util/map.h                    |   5 +-
 tools/perf/util/symbol-elf.c             |   2 +
 tools/perf/util/symbol.c                 | 195 ++++++++++++-
 tools/perf/util/symbol.h                 |   1 +
 18 files changed, 1844 insertions(+), 10 deletions(-)
 create mode 100644 tools/perf/jvmti/Makefile
 create mode 100644 tools/perf/jvmti/jvmti_agent.c
 create mode 100644 tools/perf/jvmti/jvmti_agent.h
 create mode 100644 tools/perf/jvmti/libjvmti.c
 create mode 100644 tools/perf/util/genelf.c
 create mode 100644 tools/perf/util/genelf.h
 create mode 100644 tools/perf/util/jit.h
 create mode 100644 tools/perf/util/jitdump.c
 create mode 100644 tools/perf/util/jitdump.h

-- 
1.9.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-02-18  8:45 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10 23:42 [PATCH 0/4] perf: add support for profiling jitted code Stephane Eranian
2015-02-10 23:42 ` [PATCH 1/4] perf tools: add Java demangling support Stephane Eranian
2015-02-12  8:12   ` Namhyung Kim
2015-02-12 11:27   ` Jiri Olsa
2015-02-10 23:42 ` [PATCH 2/4] perf tools: pass timestamp to map_init Stephane Eranian
2015-02-16  6:55   ` Adrian Hunter
2015-02-10 23:42 ` [PATCH 3/4] perf inject: add jitdump mmap injection support Stephane Eranian
2015-02-11 11:59   ` Peter Zijlstra
2015-02-11 13:13     ` Stephane Eranian
2015-02-11 15:27   ` David Ahern
2015-02-12  8:19     ` Namhyung Kim
2015-02-10 23:42 ` [PATCH 4/4] perf tools: add JVMTI agent library Stephane Eranian
2015-02-12  8:21   ` Namhyung Kim
2015-02-12 13:25   ` Jiri Olsa
2015-02-12 16:09     ` Stephane Eranian
2015-02-12 16:58   ` Andi Kleen
2015-02-12 17:11     ` Stephane Eranian
2015-02-16  7:01   ` Adrian Hunter
2015-02-16 20:22     ` Stephane Eranian
2015-02-18  8:43       ` Adrian Hunter
2015-02-11 11:39 ` [PATCH 0/4] perf: add support for profiling jitted code Peter Zijlstra
2015-02-11 13:18   ` Stephane Eranian
2015-02-11 16:15     ` Peter Zijlstra
2015-02-11 16:25       ` David Ahern
2015-02-12 13:42 ` Jiri Olsa
2015-02-12 17:27   ` Stephane Eranian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).