From: compudj Date: Fri, 26 May 2006 03:51:26 +0000 (+0000) Subject: java tracing X-Git-Tag: v0.12.20~1631 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6f52084a2a9a72cb917024abb072e1a3e3915163;p=lttv.git java tracing git-svn-id: http://ltt.polymtl.ca/svn@1858 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt-usertrace/java/Sample.java b/ltt-usertrace/java/Sample.java new file mode 100644 index 00000000..08f7cc89 --- /dev/null +++ b/ltt-usertrace/java/Sample.java @@ -0,0 +1,15 @@ +// The Sample-java.java file +public class Sample +{ + // Declaration of the Native (C) function + private static native void trace_java_generic_string(String arg); + static { + System.loadLibrary("ltt-java-string"); + } + + public static void main(String[] args) + { + System.out.println("Hello world"); + Sample.trace_java_generic_string("Tracing from java"); + } +} diff --git a/ltt-usertrace/java/generate.sh b/ltt-usertrace/java/generate.sh new file mode 100755 index 00000000..92ca1992 --- /dev/null +++ b/ltt-usertrace/java/generate.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +javac Sample.java +CLASSPATH=.:/usr/lib/jvm/java-1.5.0-sun-1.5.0.06/bin javah -jni Sample +gcc -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include \ + -I /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/include/linux \ + -shared -Wl,-soname,libltt-java-string \ + -o libltt-java-string.so ltt-java-string.c \ + ../ltt-facility-loader-user_generic.c +LD_LIBRARY_PATH=. java Sample diff --git a/ltt-usertrace/java/ltt-java-string.c b/ltt-usertrace/java/ltt-java-string.c new file mode 100644 index 00000000..be011fb5 --- /dev/null +++ b/ltt-usertrace/java/ltt-java-string.c @@ -0,0 +1,20 @@ + +#include +#include "Sample.h" +#include +#include + +#define LTT_TRACE +#define LTT_BLOCKING 1 +#include + +JNIEXPORT void JNICALL Java_Sample_trace_1java_1generic_1string + (JNIEnv *env, jobject obj, jstring jstr) +{ + const char *str; + str = (*env)->GetStringUTFChars(env, jstr, NULL); + if (str == NULL) return; // out of memory error thrown + trace_user_generic_string(str); + (*env)->ReleaseStringUTFChars(env, jstr, str); +} +