5acff312f9cbcfad8bdf26adad83bf2bd362eb1c
[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 #define _LGPL_SOURCE
21 #include "org_lttng_ust_agent_jul_LttngJulApi.h"
22
23 #define TRACEPOINT_DEFINE
24 #define TRACEPOINT_CREATE_PROBES
25 #include "lttng_ust_jul.h"
26 #include "../common/lttng_ust_context.h"
27
28 /*
29 * Deprecated function from before the context information was passed.
30 */
31 JNIEXPORT void JNICALL Java_org_lttng_ust_agent_jul_LttngJulApi_tracepoint(JNIEnv *env,
32 jobject jobj,
33 jstring msg,
34 jstring logger_name,
35 jstring class_name,
36 jstring method_name,
37 jlong millis,
38 jint log_level,
39 jint thread_id)
40 {
41 jboolean iscopy;
42 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
43 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
44 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
45 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
46
47 tracepoint(lttng_jul, event, msg_cstr, logger_name_cstr,
48 class_name_cstr, method_name_cstr, millis, log_level, thread_id);
49
50 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
51 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
52 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
53 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
54 }
55
56 /*
57 * Tracepoint used by Java applications using the JUL handler.
58 */
59 JNIEXPORT void JNICALL Java_org_lttng_ust_agent_jul_LttngJulApi_tracepointWithContext(JNIEnv *env,
60 jobject jobj,
61 jstring msg,
62 jstring logger_name,
63 jstring class_name,
64 jstring method_name,
65 jlong millis,
66 jint log_level,
67 jint thread_id,
68 jbyteArray context_info_entries,
69 jbyteArray context_info_strings)
70 {
71 jboolean iscopy;
72 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
73 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
74 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
75 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
76 signed char *context_info_entries_array;
77 signed char *context_info_strings_array;
78
79 /*
80 * Write these to the TLS variables, so that the UST callbacks in
81 * lttng_ust_context.c can access them.
82 */
83 context_info_entries_array = (*env)->GetByteArrayElements(env, context_info_entries, &iscopy);
84 lttng_ust_context_info_tls.ctx_entries = (struct lttng_ust_jni_ctx_entry *) context_info_entries_array;
85 lttng_ust_context_info_tls.ctx_entries_len = (*env)->GetArrayLength(env, context_info_entries);
86 context_info_strings_array = (*env)->GetByteArrayElements(env, context_info_strings, &iscopy);
87 lttng_ust_context_info_tls.ctx_strings = context_info_strings_array;
88 lttng_ust_context_info_tls.ctx_strings_len = (*env)->GetArrayLength(env, context_info_strings);
89
90 tracepoint(lttng_jul, event, msg_cstr, logger_name_cstr,
91 class_name_cstr, method_name_cstr, millis, log_level, thread_id);
92
93 lttng_ust_context_info_tls.ctx_entries = NULL;
94 lttng_ust_context_info_tls.ctx_entries_len = 0;
95 lttng_ust_context_info_tls.ctx_strings = NULL;
96 lttng_ust_context_info_tls.ctx_strings_len = 0;
97 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
98 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
99 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
100 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
101 (*env)->ReleaseByteArrayElements(env, context_info_entries, context_info_entries_array, 0);
102 (*env)->ReleaseByteArrayElements(env, context_info_strings, context_info_strings_array, 0);
103 }
This page took 0.030869 seconds and 3 git commands to generate.