new port: java/lightweight-java-profiler

A port of the lightweight-java-profiler (ljp). ljp acts as a bare-bones agentlib to produce profiling stacks that can be digested, e.g., by Brendan Gregg's flamegraph scripts.

Reviewed by:	mat, swills (mentor)
Approved by:	swills (mentor)
Differential Revision:	https://reviews.freebsd.org/D10194
This commit is contained in:
jmd
2017-04-01 17:58:59 +00:00
parent ce0df77c65
commit f66d7c64c8
9 changed files with 158 additions and 0 deletions
+1
View File
@@ -90,6 +90,7 @@
SUBDIR += junit
SUBDIR += jxgrabkey
SUBDIR += langspec
SUBDIR += lightweight-java-profiler
SUBDIR += linux-oracle-jdk18
SUBDIR += linux-oracle-jre18
SUBDIR += mmake
+47
View File
@@ -0,0 +1,47 @@
# Created by: Johannes Dieterich <jmd@FreeBSD.org>
# $FreeBSD$
PORTNAME= lightweight-java-profiler
PORTVERSION= g20170308
CATEGORIES= java devel
MAINTAINER= jmd@FreeBSD.org
COMMENT= Lightweight Java profiler which can be used for flamegraphs
LICENSE= APACHE20
LICENSE_FILE= ${WRKSRC}/COPYING
BUILD_DEPENDS= bash>=0:shells/bash
RUN_DEPENDS= bash>=0:shells/bash
ONLY_FOR_ARCHS= amd64 i386
ONLY_FOR_ARCHS_REASON= assembly only available for x86
USE_GITHUB= yes
GH_ACCOUNT= inevity
GH_TAGNAME= e8041b5
USE_JAVA= yes
JAVA_VERSION= 1.8
USE_LDCONFIG= yes
USES= gmake shebangfix
SHEBANG_FILES= Makefile
MAKE_ENV= JAVA_HOME=${LOCALBASE}/openjdk8
.include <bsd.port.pre.mk>
.if ${ARCH} == "i386"
MAKE_ENV+= BITS=32
.else
MAKE_ENV+= BITS=64
.endif
PLIST_FILES= lib/liblagent.so
do-install:
${INSTALL_LIB} ${WRKSRC}/build/liblagent.so ${STAGEDIR}/${LOCALBASE}/lib/liblagent.so
.include <bsd.port.post.mk>
+3
View File
@@ -0,0 +1,3 @@
TIMESTAMP = 1490927903
SHA256 (inevity-lightweight-java-profiler-g20170308-e8041b5_GH0.tar.gz) = b5a64716586407ff69c3c77a0621e6b65e9580686ae9ec29b145becd65fa678e
SIZE (inevity-lightweight-java-profiler-g20170308-e8041b5_GH0.tar.gz) = 16120
@@ -0,0 +1,41 @@
--- Makefile.orig 2017-03-31 01:58:22 UTC
+++ Makefile
@@ -1,7 +1,7 @@
-SHELL:=/bin/bash
+SHELL:=/usr/bin/env bash
UNAME:=$(shell uname | tr '[A-Z]' '[a-z]')
-BITS?=32
+#BITS?=32
ifeq ($(UNAME), darwin)
READLINK_ARGS:=""
PLATFORM_WARNINGS:=-Weverything -Wno-c++98-compat-pedantic -Wno-padded \
@@ -23,6 +23,13 @@ else ifeq ($(UNAME), linux)
HEADERS:=include
CC=g++
LDFLAGS=-Wl,--fatal-warnings
+else ifeq ($(UNAME), freebsd)
+ READLINK_ARGS:=""
+ PLATFORM_WARNINGS:=-Weverything -Wno-c++98-compat-pedantic -Wno-padded \
+ -Wno-missing-prototypes
+ PLATFORM_COPTS:=-std=c++11
+ HEADERS:=include
+ LDFLAGS=-Wl,-fatal_warnings
endif
JAVA_HOME := $(shell \
@@ -32,11 +39,11 @@ JAVA_HOME := $(shell \
[[ -n "$${JAVA_HOME}" ]] || (echo "Cannot find JAVA_HOME" && exit) ; \
echo $${JAVA_HOME})
AGENT=liblagent.so
-LIBS=-ldl
-BUILD_DIR ?= $(shell mkdir build-$(BITS) 2> /dev/null ; echo build-$(BITS))
+LIBS=-lc
+BUILD_DIR ?= $(shell mkdir build 2> /dev/null ; echo build)
SRC_DIR:=${PWD}/src
OPT?=-O2
-GLOBAL_WARNINGS=-Wall -Werror -Wformat-security -Wno-char-subscripts \
+GLOBAL_WARNINGS=-Wall -Wformat-security -Wno-char-subscripts \
-Wno-sign-compare -Wno-strict-overflow -Wwrite-strings -Wnon-virtual-dtor \
-Woverloaded-virtual
GLOBAL_COPTS=-fdiagnostics-show-option -fno-exceptions \
@@ -0,0 +1,11 @@
--- src/display.cc.orig 2015-04-15 08:00:23 UTC
+++ src/display.cc
@@ -20,7 +20,7 @@ void StackTracesPrinter::PrintStackTrace
if (traces[i].count != 0) {
total += traces[i].count;
count++;
- fprintf(file_, "%"PRIdPTR" ", traces[i].count);
+ fprintf(file_, "%" PRIdPTR" ", traces[i].count);
PrintStackTrace(&traces[i]);
fprintf(file_, "\n");
}
@@ -0,0 +1,20 @@
--- src/entry.cc.orig 2015-04-15 08:00:23 UTC
+++ src/entry.cc
@@ -182,7 +182,7 @@ static void SetFileFromOption(char *equa
if (Globals::OutFile == NULL) {
fprintf(stderr, "Could not open file %s: ", file_name);
perror(NULL);
- exit(1);
+ _exit(1);
}
}
@@ -207,7 +207,7 @@ static void ParseArguments(char *options
char path[PATH_MAX];
if (getcwd(path, PATH_MAX) == NULL) {
fprintf(stderr, "cwd too long?\n");
- exit(0);
+ _exit(0);
}
size_t pathlen = strlen(path);
strncat(path, "/", PATH_MAX - (pathlen++));
@@ -0,0 +1,23 @@
--- src/globals.h.orig 2015-04-15 08:00:23 UTC
+++ src/globals.h
@@ -179,18 +179,13 @@ class Accessors {
#endif
};
-#if defined(__GNUC__) && (defined(i386) || defined(__x86_64))
#if defined(__x86_64__)
#define __CAS_INSTR "lock; cmpxchgq %1,%2"
#define __ADD_INSTR "lock; xaddq %0,%1"
-#else // defined(__x86_64__)
+#else
#define __CAS_INSTR "lock; cmpxchgl %1,%2"
#define __ADD_INSTR "lock; xaddl %0,%1"
-#endif // defined(__x86_64__)
-#else // defined(__GNUC__) && (defined(i386) || defined(__x86_64))
-#error \
- "Cannot compile with non-x86. Add support for atomic ops, if you want it"
-#endif // defined(__GNUC__) && (defined(i386) || defined(__x86_64))
+#endif
inline intptr_t NoBarrier_CompareAndSwap(volatile intptr_t *ptr,
intptr_t old_value,
+9
View File
@@ -0,0 +1,9 @@
lightweight-java-profiler
a lightweight Java profiler which can be used for flamegraphs
The lightweight Java profiler acts as an agent library and generates
execution stacks. These can be fed into flamegraph utils to profile
Java applications at minimal cost.
WWW: https://github.com/inevity/lightweight-java-profiler
@@ -0,0 +1,3 @@
To use the lightweight-java-profiler, you can invoke Java as follows:
java -agentpath:path/to/liblagent.so[:file=fname] It will spit out stack traces into traces.txt (or into the optional fname passed to the agent). The current implementation samples every 1/100th of a second. It stores the first 3000 stack traces it encounters; additional stack traces will be ignored, but duplicate stack traces will continue to be counted indefinitely (or until the counter overflows, which will take a while).