Re: [PATCH 4/4] perf tools: add JVMTI agent library

Namhyung Kim
2015-02-12T08:22:40Z

On Wed, Feb 11, 2015 at 12:42:45AM +0100, Stephane Eranian wrote:
> 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 .......
>
> 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 next step is to inject the jitdump information into the
> perf.data file:
> $ perf inject -j $HOME/.debug/java/jit/java-jit-XXXX/jit-ZZZ.dump \
> -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 OProfile's opagent code.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
> ---
> 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 ++++++++++++++++++
> 4 files changed, 591 insertions(+)
> 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
>
> diff --git a/tools/perf/jvmti/Makefile b/tools/perf/jvmti/Makefile
> new file mode 100644
> index 0000000..9eda64b
> --- /dev/null
> +++ b/tools/perf/jvmti/Makefile
> @@ -0,0 +1,70 @@
> +ARCH=$(shell uname -m)
> +
> +ifeq ($(ARCH), x86_64)
> +JARCH=amd64
> +endif
> +ifeq ($(ARCH), armv7l)
> +JARCH=armhf
> +endif
> +ifeq ($(ARCH), armv6l)
> +JARCH=armhf
> +endif
> +ifeq ($(ARCH), ppc64)
> +JARCH=powerpc
> +endif
> +ifeq ($(ARCH), ppc64le)
> +JARCH=powerpc
> +endif
> +
> +DESTDIR=/usr/local
> +
> +VERSION=1
> +REVISION=0
> +AGE=0
> +
> +LN=ln -sf
> +RM=rm
> +
> +SJVMTI=libjvmti.so.$(VERSION).$(REVISION).$(AGE)
> +VJVMTI=libjvmti.so.$(VERSION)
> +SLDFLAGS=-shared -Wl,-soname -Wl,$(VLIBPFM)

s/VLIBPFM/VLIBJVMTI/ ?

Thanks,
Namhyung

> +SOLIBEXT=so
> +
> +JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | cut -d ' ' -f 3)
> +# -lrt required in 32-bit mode for clock_gettime()
> +LIBS=-lelf -lrt
> +INCDIR=-I $(JDIR)/include -I $(JDIR)/include/linux
> +
> +TARGETS=$(SJVMTI)
> +
> +SRCS=libjvmti.c jvmti_agent.c
> +OBJS=$(SRCS:.c=.o)
> +SOBJS=$(OBJS:.o=.lo)
> +OPT=-O2 -g -Werror -Wall
> +
> +CFLAGS=$(INCDIR) $(OPT)
> +
> +all: $(TARGETS)
> +
> +.c.o:
> + $(CC) $(CFLAGS) -c $*.c
> +.c.lo:
> + $(CC) -fPIC -DPIC $(CFLAGS) -c $*.c -o $*.lo
> +
> +$(OBJS) $(SOBJS): Makefile jvmti_agent.h ../util/jitdump.h
> +
> +$(SJVMTI): $(SOBJS)
> + $(CC) $(CFLAGS) $(SLDFLAGS) -o $@ $(SOBJS) $(LIBS)
> + $(LN) $@ libjvmti.$(SOLIBEXT)
> +
> +clean:
> + $(RM) -f *.o *.so.* *.so *.lo
> +
> +install:
> + -mkdir -p $(DESTDIR)/lib
> + install -m 755 $(SJVMTI) $(DESTDIR)/lib/
> + (cd $(DESTDIR)/lib; $(LN) $(SJVMTI) $(VJVMTI))
> + (cd $(DESTDIR)/lib; $(LN) $(SJVMTI) libjvmti.$(SOLIBEXT))
> + ldconfig
> +
> +.SUFFIXES: .c .S .o .lo