[lttng-dev] [lttng-ust PATCH 1/2] Add Integer and Long tracepoint types to the Java interface

Alexandre Montplaisir alexandre.montplaisir at polymtl.ca
Fri May 4 00:03:29 EDT 2012


Also added Javadoc comments to the .java file.

Signed-off-by: Alexandre Montplaisir <alexandre.montplaisir at polymtl.ca>
---
 liblttng-ust-java/LTTngUst.c       |   38 ++++++++++++++++----
 liblttng-ust-java/LTTngUst.java    |   67 ++++++++++++++++++++++++++++++++----
 liblttng-ust-java/lttng_ust_java.h |   22 ++++++++++--
 3 files changed, 112 insertions(+), 15 deletions(-)

diff --git a/liblttng-ust-java/LTTngUst.c b/liblttng-ust-java/LTTngUst.c
index 3d23d6a..0bef89d 100644
--- a/liblttng-ust-java/LTTngUst.c
+++ b/liblttng-ust-java/LTTngUst.c
@@ -22,18 +22,44 @@
 #define TRACEPOINT_CREATE_PROBES
 #include "lttng_ust_java.h"
 
+JNIEXPORT void JNICALL Java_org_lttng_ust_LTTngUst_tracepointInt(JNIEnv *env,
+						jobject jobj,
+						jstring ev_name,
+						jint payload)
+{
+	jboolean iscopy;
+	const char *ev_name_cstr = (*env)->GetStringUTFChars(env, ev_name, &iscopy);
+
+	tracepoint(lttng_ust_java, int_event, ev_name_cstr, payload);
+
+	(*env)->ReleaseStringUTFChars(env, ev_name, ev_name_cstr);
+}
+
+JNIEXPORT void JNICALL Java_org_lttng_ust_LTTngUst_tracepointLong(JNIEnv *env,
+						jobject jobj,
+						jstring ev_name,
+						jlong payload)
+{
+	jboolean iscopy;
+	const char *ev_name_cstr = (*env)->GetStringUTFChars(env, ev_name, &iscopy);
+
+	tracepoint(lttng_ust_java, long_event, ev_name_cstr, payload);
+
+	(*env)->ReleaseStringUTFChars(env, ev_name, ev_name_cstr);
+}
+
 JNIEXPORT void JNICALL Java_org_lttng_ust_LTTngUst_tracepointString(JNIEnv *env,
 						jobject jobj,
 						jstring ev_name,
-						jstring args)
+						jstring payload)
 {
 	jboolean iscopy;
-	const char *ev_name_cstr = (*env)->GetStringUTFChars(env, ev_name,
-							&iscopy);
-	const char *args_cstr = (*env)->GetStringUTFChars(env, args, &iscopy);
+	const char *ev_name_cstr = (*env)->GetStringUTFChars(env, ev_name, &iscopy);
+	const char *payload_cstr = (*env)->GetStringUTFChars(env, payload, &iscopy);
 
-	tracepoint(lttng_ust_java, string, ev_name_cstr, args_cstr);
+	tracepoint(lttng_ust_java, string_event, ev_name_cstr, payload_cstr);
 
 	(*env)->ReleaseStringUTFChars(env, ev_name, ev_name_cstr);
-	(*env)->ReleaseStringUTFChars(env, args, args_cstr);
+	(*env)->ReleaseStringUTFChars(env, payload, payload_cstr);
 }
+
diff --git a/liblttng-ust-java/LTTngUst.java b/liblttng-ust-java/LTTngUst.java
index 68ed120..f4bea32 100644
--- a/liblttng-ust-java/LTTngUst.java
+++ b/liblttng-ust-java/LTTngUst.java
@@ -1,5 +1,6 @@
-/*
+/**
  * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ * Copyright (C) 2012 Alexandre Montplaisir <alexandre.montplaisir at polymtl.ca>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,10 +19,64 @@
 
 package org.lttng.ust;
 
-public class LTTngUst {
-	public static native void tracepointString(String name, String arg);
-	static {
-		System.loadLibrary("lttng-ust-java");
-	}
+/**
+ * This class implements the the Java side of the LTTng-UST Java interface.
+ *
+ * First, make sure you have installed "liblttng-ust-java.so" where the linker
+ * can find it. You can then call LTTngUst.init() from your Java program to
+ * connect the methods exposed here to the native library.
+ *
+ * Because of limitations in the probe declaration, all trace events generated
+ * by this library will have "lttng_ust_java" for domain, and "<type>_event" for
+ * event name in the CTF trace files. The "name" parameter will instead appear
+ * as the first element of the event's payload.
+ *
+ * @author Mathieu Desnoyers
+ * @author Alexandre Montplaisir
+ *
+ */
+public abstract class LTTngUst {
+
+    /**
+     * Initialize the UST tracer. This should always be called first, before any
+     * tracepoint* method.
+     */
+    public static void init() {
+        System.loadLibrary("lttng-ust-java"); //$NON-NLS-1$
+    }
+
+    /**
+     * Insert a tracepoint with a payload of type Integer.
+     *
+     * @param name
+     *            The name assigned to this event. For best performance, this
+     *            should be a statically-defined String, or a literal.
+     * @param payload
+     *            The int payload
+     */
+    public static native void tracepointInt(String name, int payload);
+
+    /**
+     * Insert a tracepoint with a payload of type Long
+     *
+     * @param name
+     *            The name assigned to this event. For best performance, this
+     *            should be a statically-defined String, or a literal.
+     * @param payload
+     *            The long payload
+     */
+    public static native void tracepointLong(String name, long payload);
+
+    /**
+     * Insert a tracepoint with a String payload.
+     *
+     * @param name
+     *            The name assigned to this event. For best performance, this
+     *            should be a statically-defined String, or a literal.
+     * @param payload
+     *            The String payload
+     */
+    public static native void tracepointString(String name, String payload);
+
 }
 
diff --git a/liblttng-ust-java/lttng_ust_java.h b/liblttng-ust-java/lttng_ust_java.h
index 771d392..7cdbea5 100644
--- a/liblttng-ust-java/lttng_ust_java.h
+++ b/liblttng-ust-java/lttng_ust_java.h
@@ -24,11 +24,27 @@
 
 #include <lttng/tracepoint.h>
 
-TRACEPOINT_EVENT(lttng_ust_java, string,
-	TP_ARGS(const char *, name, const char *, args),
+TRACEPOINT_EVENT(lttng_ust_java, int_event,
+	TP_ARGS(const char *, name, int, payload),
 	TP_FIELDS(
 		ctf_string(name, name)
-		ctf_string(args, args)
+		ctf_integer(int, int_payload, payload)
+	)
+)
+
+TRACEPOINT_EVENT(lttng_ust_java, long_event,
+	TP_ARGS(const char *, name, long, payload),
+	TP_FIELDS(
+		ctf_string(name, name)
+		ctf_integer(long, long_payload, payload)
+	)
+)
+
+TRACEPOINT_EVENT(lttng_ust_java, string_event,
+	TP_ARGS(const char *, name, const char *, payload),
+	TP_FIELDS(
+		ctf_string(name, name)
+		ctf_string(string_payload, payload)
 	)
 )
 
-- 
1.7.10




More information about the lttng-dev mailing list