Add TRACEPOINT_EVENT java instrumentation wrapper
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 26 Aug 2011 11:23:16 +0000 (07:23 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 26 Aug 2011 11:23:16 +0000 (07:23 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Makefile.am
README
configure.ac
java/Makefile.am
java/README
java/UST.c
java/ust_java.h [new file with mode: 0644]

index 4f5ae8c1876cbfa2ac9f05d7cb0dc7c755c8a2c6..f294cf35abd24a53bd73abc4ea0e32a318dcd4c9 100644 (file)
@@ -5,7 +5,8 @@ ACLOCAL_AMFLAGS = -I config
 # libust and '.' (that contains the linker script). However, '.'
 # must be installed after libust so it can overwrite libust.so with
 # the linker script.
-SUBDIRS = snprintf liblttng-ust-comm libringbuffer libust include doc tests
+SUBDIRS = snprintf liblttng-ust-comm libringbuffer libust include doc tests \
+               java
 
 #temporarily disabled
 # . libustinstr-malloc libustfork
diff --git a/README b/README
index 635f9c1b482a2854788866a20acefee375c68c28..901e17514c85d06fa81b4e4280fefa905a2e28b1 100644 (file)
--- a/README
+++ b/README
@@ -122,3 +122,4 @@ PACKAGE CONTENTS:
 
   - java
     A simple library that uses JNI to allow tracing in java programs.
+    See java/README for build instructions.
index ce24a1a24a67c03d2d6439887955e908883430bf..dbfdecdecaaf4f5ee3d4219ffc0200d175b975e8 100644 (file)
@@ -135,6 +135,36 @@ if test x$NO_UNALIGNED_ACCESS = x ; then
 AC_DEFINE([HAVE_EFFICIENT_UNALIGNED_ACCESS], [1])
 fi
 
+# Set compile flags to java include files if given
+AC_ARG_WITH(java_jdk, [  --with-java-jdk=DIR     use java jdk from DIR. Ex : $JAVA_HOME.], JAVA_SDK=$withval,)
+if test $JAVA_SDK; then
+        if test -d $JAVA_SDK; then
+                AC_MSG_RESULT([using java include in $JAVA_SDK])
+                SUBDIRS=`find $JAVA_SDK/include -type d`
+               CFLAGS+=" "
+                CFLAGS+=`for x in $SUBDIRS; do echo -n "-I$x "; done`
+               CFLAGS+=" "
+        else
+                AC_MSG_ERROR(Unable to find java include file in $JAVA_JDK)
+        fi
+fi
+
+# Check for JNI header files if requested
+AC_ARG_WITH(jni-interface, [  --with-jni-interface    build JNI interface between C and java. Need java include files.
+                         [[default=no]]])
+
+if test -z "$with_jni_interface"; then
+        with_jni_interface=${with_jni_interface_default-no}
+fi
+
+if test "$with_jni_interface" = "yes"; then
+        AC_CHECK_HEADERS([jni.h],,AC_MSG_ERROR([
+missing jni.h
+Make sure Sun Java, OpenJDK or GCJ is installed and that this header file exists in the system path.
+Use --with-java-jdk=DIR flag to point to your java include files or desactivate the JNI interface.]))
+fi
+AM_CONDITIONAL(BUILD_JNI_INTERFACE, test "$with_jni_interface" = "yes")
+
 AC_CONFIG_FILES([
        Makefile
        doc/Makefile
@@ -167,5 +197,6 @@ AC_CONFIG_FILES([
        snprintf/Makefile
        ust.pc
        include/ust/version.h
+       java/Makefile
 ])
 AC_OUTPUT
index 4dcb0c3aff20b315b4a0164578238fe2554b9af9..cb2c1b8931f2cef8a399857b32e13104bc489349 100644 (file)
@@ -1,7 +1,9 @@
+if BUILD_JNI_INTERFACE
+
 AM_CPPFLAGS = -I$(top_srcdir)/include
 
 lib_LTLIBRARIES = libustjava.la
-libustjava_la_SOURCES = UST.c UST.h
+libustjava_la_SOURCES = UST.c UST.h ust_java.h
 dist_noinst_DATA = UST.java
 libustjava_la_LIBADD = -lc -L$(top_builddir)/libust/.libs -lust
 
@@ -13,5 +15,7 @@ clean-local:
 UST.class: UST.java
        javac -d "$(builddir)" "$(srcdir)/UST.java"
 
-UST.h:
+UST.h: UST.class
        javah -jni UST
+
+endif
index 358866fed99cb20936103974232e88d48acc8f90..ecc27ef6d27b2ca440cadc5b7d8d52b12eb582da 100644 (file)
@@ -1,3 +1,15 @@
 This directory contains a simple API for instrumenting java applications.
 
-Look at the example in the tests/java directory for usage.
+Configuration examples to build this library:
+
+dependency: sun-java6-jdk
+./configure --with-java-jdk=/usr/lib/jvm/java-6-sun --with-jni-interface
+
+dependency: openjdk-6-jdk
+./configure --with-java-jdk=/usr/lib/jvm/java-6-openjdk --with-jni-interface
+
+dependency: gcj-4.4-jdk
+./configure --with-java-jdk=/usr/lib/jvm/java-gcj --with-jni-interface
+
+Our testing shows that sun java6 and openjdk 6 build fine, but not gcj
+4.4.
index 0904ad2e8bb1ec86e18faa9d82dd3f9c5f1b20fc..84b7393abb7c36727091049f4cc99b9b478118c2 100644 (file)
@@ -1,13 +1,17 @@
 #include <jni.h>
-#include <ust/marker.h>
 
-JNIEXPORT void JNICALL Java_UST_ust_1java_1event (JNIEnv *env, jobject jobj, jstring ev_name, jstring args)
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_java.h"
+
+JNIEXPORT void JNICALL Java_UST_ust_1java_1event (JNIEnv *env, jobject jobj,
+                                               jstring ev_name, jstring args)
 {
        jboolean iscopy;
-       const char *ev_name_cstr = (*env)->GetStringUTFChars(env, ev_name, &iscopy);
+       const char *ev_name_cstr = (*env)->GetStringUTFChars(env, ev_name,
+                                                       &iscopy);
        const char *args_cstr = (*env)->GetStringUTFChars(env, args, &iscopy);
 
-       ust_marker(ust, java_event, "name %s args %s", ev_name_cstr, args_cstr);
+       tracepoint(ust_java_event, ev_name_cstr, args_cstr);
 }
 
-UST_MARKER_LIB
+TRACEPOINT_LIB
diff --git a/java/ust_java.h b/java/ust_java.h
new file mode 100644 (file)
index 0000000..366b373
--- /dev/null
@@ -0,0 +1,44 @@
+#undef TRACEPOINT_SYSTEM
+#define TRACEPOINT_SYSTEM ust_java
+
+#if !defined(_TRACEPOINT_UST_JAVA_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_JAVA_H
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1 of
+ * the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <ust/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_java_event,
+       TP_PROTO(const char *name, const char *args),
+       TP_ARGS(name, args),
+       TP_FIELDS(
+               ctf_string(name, name)
+               ctf_string(args, args)
+       )
+)
+
+#endif /* _TRACEPOINT_UST_JAVA_H */
+
+#undef TRACEPOINT_INCLUDE_PATH
+#define TRACEPOINT_INCLUDE_PATH .
+#undef TRACEPOINT_INCLUDE_FILE
+#define TRACEPOINT_INCLUDE_FILE ust_java
+
+/* This part must be outside protection */
+#include <ust/tracepoint-event.h>
This page took 0.026421 seconds and 4 git commands to generate.