Implement Java agent application context retrieval
[lttng-ust.git] / liblttng-ust-java-agent / jni / jul / lttng_ust_jul.c
1 /*
2 * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; only
8 * version 2.1 of the License.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "org_lttng_ust_agent_jul_LttngJulApi.h"
21
22 #define TRACEPOINT_DEFINE
23 #define TRACEPOINT_CREATE_PROBES
24 #include "lttng_ust_jul.h"
25 #include "../common/lttng_ust_context.h"
26
27 /*
28 * Deprecated function from before the context information was passed.
29 */
30 JNIEXPORT void JNICALL Java_org_lttng_ust_agent_jul_LttngJulApi_tracepoint(JNIEnv *env,
31 jobject jobj,
32 jstring msg,
33 jstring logger_name,
34 jstring class_name,
35 jstring method_name,
36 jlong millis,
37 jint log_level,
38 jint thread_id)
39 {
40 jboolean iscopy;
41 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
42 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
43 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
44 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
45
46 tracepoint(lttng_jul, event, msg_cstr, logger_name_cstr,
47 class_name_cstr, method_name_cstr, millis, log_level, thread_id);
48
49 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
50 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
51 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
52 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
53 }
54
55 /*
56 * Tracepoint used by Java applications using the JUL handler.
57 */
58 JNIEXPORT void JNICALL Java_org_lttng_ust_agent_jul_LttngJulApi_tracepointWithContext(JNIEnv *env,
59 jobject jobj,
60 jstring msg,
61 jstring logger_name,
62 jstring class_name,
63 jstring method_name,
64 jlong millis,
65 jint log_level,
66 jint thread_id,
67 jbyteArray context_info)
68 {
69 jboolean iscopy;
70 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
71 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
72 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
73 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
74 signed char *context_info_array;
75
76 /*
77 * Write these to the TLS variables, so that the UST callbacks in
78 * lttng_ust_context.c can access them.
79 */
80 context_info_array = (*env)->GetByteArrayElements(env, context_info, &iscopy);
81 lttng_ust_context_info_tls.ctx = (struct lttng_ust_jni_ctx *) context_info_array;
82 lttng_ust_context_info_tls.len = (*env)->GetArrayLength(env, context_info);
83
84 tracepoint(lttng_jul, event, msg_cstr, logger_name_cstr,
85 class_name_cstr, method_name_cstr, millis, log_level, thread_id);
86
87 lttng_ust_context_info_tls.ctx = NULL;
88 lttng_ust_context_info_tls.len = 0;
89 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
90 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
91 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
92 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
93 (*env)->ReleaseByteArrayElements(env, context_info, context_info_array, 0);
94 }
This page took 0.032358 seconds and 5 git commands to generate.