1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2010 William Bourque
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License Version 2.1 as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
19 /* Important to get consistent size_t type */
20 #define _FILE_OFFSET_BITS 64
24 #include <ltt/trace.h>
26 #include <ltt/marker.h>
37 We've got hell of a problem passing "unsigned int64" to java, as there is no equivalent type
38 The closer we can use is "long" which is signed, so only 32 (or 63?) bits are valid
39 Plus, even if we are within the "32 bits" capacity, java sometime screw itself trying to convert "unsigned 64 -> signed 64"
40 This happen especially often when RETURNING a jlong
41 So when returning a jlong, we should convert it like this : "unsigned 64"->"signed 64"->jlong
43 #define CONVERT_UINT64_TO_JLONG(n) (jlong)(gint64)(n)
44 #define CONVERT_INT64_TO_JLONG(n) (jlong)(gint64)(n)
46 /* To ease calcul involving nano */
47 #define BILLION 1000000000
51 #define CONVERT_JLONG_TO_PTR(p) (p)
52 #define CONVERT_PTR_TO_JLONG(p) (jlong)(p)
53 /* Define the "gint" type we should use for pointer. */
54 #define GINT_TYPE_FOR_PTR gint64
56 /* Conversion to int first to save warning */
57 #define CONVERT_JLONG_TO_PTR(p) (int)(p)
58 #define CONVERT_PTR_TO_JLONG(p) (jlong)(int)(p)
59 /* Define the "gint" type we should use for pointer. */
60 #define GINT_TYPE_FOR_PTR gint32
63 /* Structure to encapsulate java_data to pass as arguments */
64 struct java_calling_data
71 All these struct are used to call g_datalist_foreach()
72 Find a better way! This is ugly!
76 struct java_calling_data
*java_args
;
77 struct marker_data
*mdata
;
82 GArray
*saveTimeArray
;
85 struct saveTimeAndTracefile
88 LttTracefile
*tracefile
;
92 ### COMMON Methods ###
94 Empty method to turn off the debug (debug waste time while printing) */
95 void ignore_and_drop_message(const gchar
*log_domain
, GLogLevelFlags log_level
, const gchar
*message
, gpointer user_data
) {
99 /* JNI method to call printf from the java side */
100 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_Jni_1C_1Common_ltt_1printC(JNIEnv
*env
, jobject jobj
, jstring new_string
) {
101 const char *c_msg
= (*env
)->GetStringUTFChars(env
, new_string
, 0);
103 printf("%s", c_msg
);
105 (*env
)->ReleaseStringUTFChars(env
, new_string
, c_msg
);
108 /* Method to obtain a trace version number from its path */
109 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVersion_ltt_1getTraceVersion(JNIEnv
*env
, jobject jobj
, jstring tracepath
) {
111 const gchar
*c_pathname
= (*env
)->GetStringUTFChars(env
, tracepath
, 0);
112 jint tmpMajorNumber
= 0;
113 jint tmpMinorNumber
= 0;
115 jclass accessClass
= (*env
)->GetObjectClass(env
, jobj
);
116 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTraceVersionFromC", "(II)V");
118 struct LttTraceVersion version_number
;
120 if ( ltt_get_trace_version(c_pathname
, &version_number
) >= 0) {
121 tmpMajorNumber
= version_number
.ltt_major_version
;
122 tmpMinorNumber
= version_number
.ltt_minor_version
;
125 (*env
)->CallVoidMethod(env
, jobj
, accessFunction
, tmpMajorNumber
, tmpMinorNumber
);
133 ### TRACE methods ###
135 JNI mapping of < LttTrace *ltt_trace_open(const gchar *pathname) > (trace.h) */
136 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1openTrace(JNIEnv
*env
, jobject jobj
, jstring pathname
, jboolean show_debug
) {
139 /* Make sure we don't use any debug (speed up the read) */
140 g_log_set_handler(NULL
, G_LOG_LEVEL_INFO
, ignore_and_drop_message
, NULL
);
141 g_log_set_handler(NULL
, G_LOG_LEVEL_DEBUG
, ignore_and_drop_message
, NULL
);
144 const char *c_pathname
= (*env
)->GetStringUTFChars(env
, pathname
, 0);
145 LttTrace
*newPtr
= ltt_trace_open( c_pathname
);
147 (*env
)->ReleaseStringUTFChars(env
, pathname
, c_pathname
);
149 return CONVERT_PTR_TO_JLONG(newPtr
);
152 /* JNI mapping of < void ltt_trace_close(LttTrace *t) > (trace.h) */
153 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1closeTrace(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
){
155 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
157 ltt_trace_close(newPtr
);
160 /* Get the tracepath */
161 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getTracepath(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
162 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
164 return (*env
)->NewStringUTF(env
, g_quark_to_string( newPtr
->pathname
) );
169 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getCpuNumber(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
170 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
172 return (jint
)newPtr
->num_cpu
;
175 /* Get of arch_type */
176 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getArchType(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
177 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
179 return (jlong
)newPtr
->arch_type
;
182 /* Get of arch_variant */
183 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getArchVariant(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
184 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
186 return (jlong
)newPtr
->arch_variant
;
189 /* Get of arch_size */
190 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getArchSize(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
191 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
193 return (jshort
)newPtr
->arch_size
;
196 /* Get of ltt_major_version */
197 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getLttMajorVersion(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
198 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
200 return (jshort
)newPtr
->ltt_major_version
;
203 /* Get of ltt_minor_version */
204 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getLttMinorVersion(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
205 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
207 return (jshort
)newPtr
->ltt_minor_version
;
210 /* Get of flight_recorder */
211 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getFlightRecorder(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
212 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
214 return (jshort
)newPtr
->flight_recorder
;
217 /* Get of freq_scale */
218 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getFreqScale(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
219 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
221 return (jlong
)newPtr
->freq_scale
;
224 /* Get of start_freq */
225 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getStartFreq(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
226 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
228 return CONVERT_UINT64_TO_JLONG(newPtr
->start_freq
);
231 /* Get of start_tsc */
232 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getStartTimestampCurrentCounter(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
233 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
235 return CONVERT_UINT64_TO_JLONG(newPtr
->start_tsc
);
238 /* Get of start_monotonic */
239 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getStartMonotonic(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
240 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
242 return CONVERT_UINT64_TO_JLONG(newPtr
->start_monotonic
);
245 /* Access to start_time */
246 /* Note that we are calling the setTimeFromC function in Jaf_Time from here */
247 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedStartTime(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
, jobject time_jobj
) {
248 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
250 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
251 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTimeFromC", "(J)V");
253 jlong fullTime
= (CONVERT_UINT64_TO_JLONG(newPtr
->start_time
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(newPtr
->start_time
.tv_nsec
);
255 (*env
)->CallVoidMethod(env
, time_jobj
, accessFunction
, fullTime
);
258 /* Access to start_time_from_tsc */
259 /* Note that we are calling the setTimeFromC function in Jaf_Time from here */
260 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedStartTimeFromTimestampCurrentCounter(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
, jobject time_jobj
) {
261 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
263 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
264 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTimeFromC", "(J)V");
266 jlong fullTime
= (CONVERT_UINT64_TO_JLONG(newPtr
->start_time_from_tsc
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(newPtr
->start_time_from_tsc
.tv_nsec
);
268 (*env
)->CallVoidMethod(env
, time_jobj
, accessFunction
, fullTime
);
272 /* g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getAllTracefiles */
273 void g_datalist_foreach_addTracefilesOfTrace(GQuark name
, gpointer data
, gpointer user_data
) {
274 struct java_calling_data
*args
= (struct java_calling_data
*)user_data
;
276 jclass accessClass
= (*args
->env
)->GetObjectClass(args
->env
, args
->jobj
);
277 jmethodID accessFunction
= (*args
->env
)->GetMethodID(args
->env
, accessClass
, "addTracefileFromC", "(Ljava/lang/String;J)V");
279 GArray
*tracefile_array
= (GArray
*)data
;
280 LttTracefile
*tracefile
;
284 for (i
=0; i
<tracefile_array
->len
; i
++) {
285 tracefile
= &g_array_index(tracefile_array
, LttTracefile
, i
);
287 newPtr
= CONVERT_PTR_TO_JLONG(tracefile
);
289 (*args
->env
)->CallVoidMethod(args
->env
, args
->jobj
, accessFunction
, (*args
->env
)->NewStringUTF(args
->env
, g_quark_to_string(tracefile
->name
) ), newPtr
);
293 /* Function to fill up the java map with the event type found in tracefile (the name) */
294 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedAllTracefiles(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
295 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
297 struct java_calling_data args
= { env
, jobj
};
299 g_datalist_foreach(&newPtr
->tracefiles
, &g_datalist_foreach_addTracefilesOfTrace
, &args
);
303 /* g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedTracefileTimeRange */
304 /* used to save the current timestamp for each tracefile */
305 void g_datalist_foreach_saveTracefilesTime(GQuark name
, gpointer data
, gpointer user_data
) {
306 struct saveTimeArgs
*args
= (struct saveTimeArgs
*)user_data
;
308 GArray
*tracefile_array
= (GArray
*)data
;
309 GArray
*save_array
= args
->saveTimeArray
;
311 LttTracefile
*tracefile
;
312 struct saveTimeAndTracefile
*savedData
;
315 for (i
=0; i
<tracefile_array
->len
; i
++) {
316 tracefile
= &g_array_index(tracefile_array
, LttTracefile
, i
);
318 /* Allocate a new LttTime for each tracefile (so it won't change if the tracefile seek somewhere else) */
319 savedData
= (struct saveTimeAndTracefile
*)malloc( sizeof(struct saveTimeAndTracefile
) );
320 savedData
->time
.tv_sec
= tracefile
->event
.event_time
.tv_sec
;
321 savedData
->time
.tv_nsec
= tracefile
->event
.event_time
.tv_nsec
;
322 savedData
->tracefile
= tracefile
;
323 /* Append the saved data to the array */
324 g_array_append_val(save_array
, savedData
);
329 /* Obtain the range of the trace (i.e. "start time" and "end time") */
330 /* Note : This function, unlike ltt_trace_time_span_get, is assured to return all tracefiles to their correct position after operation */
331 /* NOTE : this method is quite heavy to use!!! */
332 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedTracefileTimeRange(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
, jobject jstart_time
, jobject jend_time
) {
333 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
335 /* Allocate ourself a new array to save the data in */
336 GArray
*savedDataArray
= g_array_new(FALSE
, FALSE
, sizeof(struct saveTimeAndTracefile
*) );
337 struct saveTimeArgs args
= { savedDataArray
};
338 /* Call g_datalist_foreach_saveTracefilesTime for each element in the GData to save the time */
339 g_datalist_foreach(&newPtr
->tracefiles
, &g_datalist_foreach_saveTracefilesTime
, &args
);
341 /* Call to ltt_trace_time_span_get to find the current start and end time */
342 /* NOTE : This WILL change the current block of the tracefile (i.e. its timestamp) */
343 LttTime tmpStartTime
= { 0, 0 };
344 LttTime tmpEndTime
= { 0, 0 };
345 ltt_trace_time_span_get(newPtr
, &tmpStartTime
, &tmpEndTime
);
347 /* Seek back to the correct time for each tracefile and free the allocated memory */
348 struct saveTimeAndTracefile
*savedData
;
350 for (i
=0; i
<savedDataArray
->len
; i
++) {
351 savedData
= g_array_index(savedDataArray
, struct saveTimeAndTracefile
*, i
);
352 /* Seek back to the correct time */
353 /* Some time will not be consistent here (i.e. unitialized data) */
354 /* but the seek should work just fine with that */
355 ltt_tracefile_seek_time(savedData
->tracefile
, savedData
->time
);
357 /* Free the memory allocated for this saveTimeAndTracefile entry */
360 /* Free the memory allocated for the GArray */
361 g_array_free(savedDataArray
, TRUE
);
363 /* Send the start and end time back to the java */
364 /* We do it last to make sure a problem won't leave us with unfred memory */
365 jclass startAccessClass
= (*env
)->GetObjectClass(env
, jstart_time
);
366 jmethodID startAccessFunction
= (*env
)->GetMethodID(env
, startAccessClass
, "setTimeFromC", "(J)V");
367 jlong startTime
= (CONVERT_UINT64_TO_JLONG(tmpStartTime
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(tmpStartTime
.tv_nsec
);
368 (*env
)->CallVoidMethod(env
, jstart_time
, startAccessFunction
, startTime
);
370 jclass endAccessClass
= (*env
)->GetObjectClass(env
, jend_time
);
371 jmethodID endAccessFunction
= (*env
)->GetMethodID(env
, endAccessClass
, "setTimeFromC", "(J)V");
372 jlong endTime
= (CONVERT_UINT64_TO_JLONG(tmpEndTime
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(tmpEndTime
.tv_nsec
);
373 (*env
)->CallVoidMethod(env
, jend_time
, endAccessFunction
, endTime
);
376 /* Function to print the content of a trace */
377 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1printTrace(JNIEnv
*env
, jobject jobj
, jlong trace_ptr
) {
379 LttTrace
*newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
381 printf("pathname : %s\n" ,g_quark_to_string(newPtr
->pathname
) );
382 printf("num_cpu : %u\n" ,(unsigned int)(newPtr
->num_cpu
) );
383 printf("arch_type : %u\n" ,(unsigned int)(newPtr
->arch_type
) );
384 printf("arch_variant : %u\n" ,(unsigned int)(newPtr
->arch_variant
) );
385 printf("arch_size : %u\n" ,(unsigned short)(newPtr
->arch_size
) );
386 printf("ltt_major_version : %u\n" ,(unsigned short)(newPtr
->ltt_major_version
) );
387 printf("ltt_minor_version : %u\n" ,(unsigned short)(newPtr
->ltt_minor_version
) );
388 printf("flight_recorder : %u\n" ,(unsigned short)(newPtr
->flight_recorder
) );
389 printf("freq_scale : %u\n" ,(unsigned int)(newPtr
->freq_scale
) );
390 printf("start_freq : %lu\n" ,(long unsigned int)(newPtr
->start_freq
) );
391 printf("start_tsc : %lu\n" ,(long unsigned int)(newPtr
->start_tsc
) );
392 printf("start_monotonic : %lu\n" ,(long unsigned int)(newPtr
->start_monotonic
) );
393 printf("start_time ptr : %p\n" ,&newPtr
->start_time
);
394 printf(" tv_sec : %lu\n" ,(long unsigned int)(newPtr
->start_time
.tv_sec
) );
395 printf(" tv_nsec : %lu\n" ,(long unsigned int)(newPtr
->start_time
.tv_nsec
) );
396 printf("start_time_from_tsc ptr : %p\n" ,&newPtr
->start_time_from_tsc
);
397 printf(" tv_sec : %lu\n" ,(long unsigned int)(newPtr
->start_time_from_tsc
.tv_sec
) );
398 printf(" tv_nsec : %lu\n" ,(long unsigned int)(newPtr
->start_time_from_tsc
.tv_nsec
) );
399 printf("tracefiles ptr : %p\n" ,newPtr
->tracefiles
);
410 ### TRACEFILE methods ###
413 /* Get of cpu_online */
414 JNIEXPORT jboolean JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getIsCpuOnline(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
415 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
417 return (jboolean
)newPtr
->cpu_online
;
420 /* Get of long_name */
421 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTracefilepath(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
422 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
424 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->long_name
) );
428 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTracefilename(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
429 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
431 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->name
) );
435 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCpuNumber(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
436 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
438 return (jlong
)newPtr
->cpu_num
;
442 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTid(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
443 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
445 return (jlong
)newPtr
->tid
;
449 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getPgid(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
450 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
452 return (jlong
)newPtr
->pgid
;
455 /* Get of creation */
456 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCreation(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
457 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
459 return CONVERT_UINT64_TO_JLONG(newPtr
->creation
);
463 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTracePtr(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
464 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
466 return CONVERT_PTR_TO_JLONG(newPtr
->trace
);
470 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getMarkerDataPtr(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
471 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
473 return CONVERT_PTR_TO_JLONG(newPtr
->mdata
);
477 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCFileDescriptor(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
478 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
480 return (jint
)newPtr
->fd
;
483 /* Get of file_size */
484 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getFileSize(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
485 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
487 return CONVERT_UINT64_TO_JLONG(newPtr
->file_size
);
490 /* Get of num_blocks */
491 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBlockNumber(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
492 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
494 return (jlong
)newPtr
->num_blocks
;
497 /* Get of reverse_bo */
498 JNIEXPORT jboolean JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getIsBytesOrderReversed(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
499 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
501 return (jboolean
)newPtr
->reverse_bo
;
504 /* Get of float_word_order */
505 JNIEXPORT jboolean JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getIsFloatWordOrdered(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
506 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
508 return (jboolean
)newPtr
->float_word_order
;
511 /* Get of alignment */
512 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getAlignement(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
513 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
515 return CONVERT_UINT64_TO_JLONG(newPtr
->alignment
);
518 /* Get of buffer_header_size */
519 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBufferHeaderSize(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
520 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
522 return CONVERT_UINT64_TO_JLONG(newPtr
->buffer_header_size
);
526 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBitsOfCurrentTimestampCounter(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
527 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
529 return (jint
)newPtr
->tscbits
;
532 /* Get of eventbits */
533 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBitsOfEvent(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
534 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
536 return (jint
)newPtr
->eventbits
;
539 /* Get of tsc_mask */
540 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCurrentTimestampCounterMask(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
541 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
543 return CONVERT_UINT64_TO_JLONG(newPtr
->tsc_mask
);
546 /* Get of tsc_mask_next_bit */
547 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCurrentTimestampCounterMaskNextBit(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
548 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
550 return CONVERT_UINT64_TO_JLONG(newPtr
->tsc_mask_next_bit
);
553 /* Get of events_lost */
554 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getEventsLost(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
555 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
557 return (jlong
)newPtr
->events_lost
;
560 /* Get of subbuf_corrupt */
561 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getSubBufferCorrupt(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
562 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
564 return (jlong
)newPtr
->subbuf_corrupt
;
568 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getEventPtr(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
569 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
571 return CONVERT_PTR_TO_JLONG(&newPtr
->event
);
575 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBufferPtr(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
576 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
578 return CONVERT_PTR_TO_JLONG(&newPtr
->buffer
);
581 /* Get of buffer size */
582 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBufferSize(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
583 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
585 return (jlong
)newPtr
->buf_size
;
589 /* g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getAllMarkers */
590 void g_hash_table_foreach_addMarkersOfTracefile(gpointer key
, gpointer data
, gpointer user_data
) {
591 struct addMarkersArgs
*args
= (struct addMarkersArgs
*)user_data
;
592 struct java_calling_data
*jargs
= (struct java_calling_data
*)args
->java_args
;
594 jclass accessClass
= (*jargs
->env
)->GetObjectClass(jargs
->env
, jargs
->jobj
);
595 jmethodID accessFunction
= (*jargs
->env
)->GetMethodID(jargs
->env
, accessClass
, "addMarkersFromC", "(IJ)V");
597 unsigned long marker_id
= (unsigned long)data
;
599 /* The hash table store an ID... we will use the ID to access the array. */
600 GArray
*marker
= args
->mdata
->markers
;
601 struct marker_info
*newPtr
= &g_array_index(marker
, struct marker_info
, marker_id
);
603 (*jargs
->env
)->CallVoidMethod(jargs
->env
, jargs
->jobj
, accessFunction
, marker_id
, CONVERT_PTR_TO_JLONG(newPtr
) );
606 /* Function to fill up the java map with the event type found in tracefile (the name) */
607 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1feedAllMarkers(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
608 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
611 Find a better way! This is ugly! */
612 struct java_calling_data java_args
= { env
, jobj
};
613 struct addMarkersArgs args
= { &java_args
, newPtr
->mdata
};
615 g_hash_table_foreach( newPtr
->mdata
->markers_hash
, &g_hash_table_foreach_addMarkersOfTracefile
, &args
);
619 /* Function to print the content of a tracefile */
620 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1printTracefile(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
622 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
623 printf("cpu_online : %i\n" ,(int)newPtr
->cpu_online
);
624 printf("long_name : %s\n" ,g_quark_to_string(newPtr
->long_name
));
625 printf("name : %s\n" ,g_quark_to_string(newPtr
->name
));
626 printf("cpu_num : %u\n" ,(unsigned int)(newPtr
->cpu_num
));
627 printf("tid : %u\n" ,(unsigned int)(newPtr
->tid
));
628 printf("pgid : %u\n" ,(unsigned int)(newPtr
->pgid
));
629 printf("creation : %lu\n" ,(long unsigned int)(newPtr
->creation
));
630 printf("trace ptr : %p\n" ,newPtr
->trace
);
631 printf("marker ptr : %p\n" ,newPtr
->mdata
);
632 printf("fd : %i\n" ,(int)(newPtr
->fd
));
633 printf("file_size : %u\n" ,(unsigned int)(newPtr
->file_size
));
634 printf("num_blocks : %u\n" ,(unsigned int)(newPtr
->num_blocks
));
635 printf("reverse_bo : %i\n" ,(int)newPtr
->reverse_bo
);
636 printf("float_word_order : %i\n" ,(int)newPtr
->float_word_order
);
637 printf("alignment : %i\n" ,(int)newPtr
->alignment
);
638 printf("buffer_header_size : %i\n" ,(int)newPtr
->buffer_header_size
);
639 printf("tscbits : %u\n" ,(unsigned short)newPtr
->tscbits
);
640 printf("eventbits : %u\n" ,(unsigned short)newPtr
->eventbits
);
641 printf("tsc_mask : %lu\n" ,(long unsigned int)newPtr
->tsc_mask
);
642 printf("tsc_mask_next_bit : %lu\n" ,(long unsigned int)newPtr
->tsc_mask_next_bit
);
643 printf("events_lost : %u\n" ,(unsigned int)newPtr
->events_lost
);
644 printf("subbuf_corrupt : %u\n" ,(unsigned int)newPtr
->subbuf_corrupt
);
645 printf("event ptr : %p\n" ,&newPtr
->event
);
646 printf("buffer ptr : %p\n" ,&newPtr
->buffer
);
656 ### EVENT methods ###
659 /* Method to get the read status */
660 /* This method will read the next event and then seek back its initial position */
661 /* Lttv assume that every tracefile have at least 1 event, but we have not guarantee after this one. */
662 /* We will read the next event and return the status of that read */
663 /* We will then seek back to our initial position */
664 /* Note : this method is expensive and should not be used too often */
665 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1positionToFirstEvent(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
666 LttTracefile
*tracefilePtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
668 /* Ask ltt to read the next events on the given tracefiles
669 Returned value can be :
670 0 if everything went fine (EOK)
671 ERANGE = 34 out of range, back to last event (might be system dependent?)
672 EPERM = 1 error while reading (might be system dependent?) */
675 /* Seek to the start time... this will also read the first event, as we want. */
676 int returnedValue
= ltt_tracefile_seek_time(tracefilePtr
, ((struct LttTrace
)*(tracefilePtr
->trace
)).start_time_from_tsc
);
678 return (jint
)returnedValue
;
681 /* Method to read next event */
682 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1readNextEvent(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
) {
683 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
685 /* Ask ltt to read the next events on the given tracefiles
686 Returned value can be :
687 0 if everything went fine (EOK)
688 ERANGE = 34 out of range, back to last event (might be system dependent?)
689 EPERM = 1 error while reading (might be system dependent?) */
693 This might fail on the FIRST event, as the timestamp before the first read is uninitialized
694 However, LTT make the assumption that all tracefile have AT LEAST one event, so we got to run with it */
696 /* Save "last time" before moving, to be able to get back if needed */
697 LttTime lastTime
= newPtr
->event
.event_time
;
699 int returnedValue
= ltt_tracefile_read(newPtr
);
701 /* We need to get back to previous after an error to keep a sane state */
702 if ( returnedValue
!= 0 ) {
703 ltt_tracefile_seek_time(newPtr
, lastTime
);
706 return (jint
)returnedValue
;
709 /* Method to seek to a certain event */
710 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1seekEvent(JNIEnv
*env
, jobject jobj
, jlong tracefile_ptr
, jobject time_jobj
) {
711 LttTracefile
*newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
713 guint64 fullTime
= 0;
715 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
716 jmethodID getTimeFunction
= (*env
)->GetMethodID(env
, accessClass
, "getTime", "()J");
717 fullTime
= (*env
)->CallLongMethod(env
, time_jobj
, getTimeFunction
);
720 Conversion from jlong -> C long seems to be particularly sloppy
721 Depending how and where (inlined a function or as a single operation) we do this, we might end up with wrong number
722 The following asignation of guint64 seems to work well.
723 MAKE SURE TO PERFORM SEVERAL TESTS IF YOU CHANGE THIS. */
724 guint64 seconds
= fullTime
/BILLION
;
725 guint64 nanoSeconds
= fullTime
%BILLION
;
727 LttTime seekTime
= { (unsigned long)seconds
, (unsigned long)nanoSeconds
};
729 /* Ask ltt to read the next events on the given tracefiles
730 Returned value can be :
731 0 if everything went fine (EOK)
732 ERANGE = 34 out of range, back to last event (might be system dependent?)
733 EPERM = 1 error while reading (might be system dependent?) */
735 int returnedValue
= ltt_tracefile_seek_time(newPtr
, seekTime
);
736 return (jint
)returnedValue
;
739 /* Get of tracefile */
740 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getTracefilePtr(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
741 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
743 return CONVERT_PTR_TO_JLONG(newPtr
->tracefile
);
747 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getBlock(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
748 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
750 return (jlong
)newPtr
->block
;
754 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getOffset(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
755 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
757 return (jlong
)newPtr
->offset
;
761 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getCurrentTimestampCounter(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
762 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
764 return CONVERT_UINT64_TO_JLONG(newPtr
->tsc
);
767 /* Get of timestamp */
768 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getTimestamp(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
769 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
771 return (jlong
)newPtr
->timestamp
;
774 /* Get of event_id */
775 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getEventMarkerId(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
776 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
778 return (jint
)newPtr
->event_id
;
781 /* Get time in nanoseconds */
782 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getNanosencondsTime(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
783 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
785 return (CONVERT_UINT64_TO_JLONG(newPtr
->event_time
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(newPtr
->event_time
.tv_nsec
);
788 /* Fill event_time into an object */
789 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1feedEventTime(JNIEnv
*env
, jobject jobj
, jlong event_ptr
, jobject time_jobj
) {
790 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
792 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
793 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTimeFromC", "(J)V");
795 jlong fullTime
= (CONVERT_UINT64_TO_JLONG(newPtr
->event_time
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(newPtr
->event_time
.tv_nsec
);
797 (*env
)->CallVoidMethod(env
, time_jobj
, accessFunction
, fullTime
);
800 /* Access method to the data */
801 /* The data are in "byte" form */
802 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getDataContent(JNIEnv
*env
, jobject jobj
, jlong event_ptr
, jlong data_size
, jbyteArray dataArray
) {
803 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
805 (*env
)->SetByteArrayRegion(env
, dataArray
, 0, (jsize
)data_size
, newPtr
->data
);
808 /* Get of data_size */
809 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getEventDataSize(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
810 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
812 return (jlong
)newPtr
->data_size
;
815 /* Get of event_size */
816 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getEventSize(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
817 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
819 return (jlong
)newPtr
->event_size
;
823 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getCount(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
824 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
826 return (jint
)newPtr
->count
;
829 /* Get of overflow_nsec */
830 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getOverflowNanoSeconds(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
831 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
833 return CONVERT_UINT64_TO_JLONG(newPtr
->overflow_nsec
);
837 /* Function to print the content of a event */
838 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1printEvent(JNIEnv
*env
, jobject jobj
, jlong event_ptr
) {
839 LttEvent
*newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
841 printf("tracefile : %p\n" ,(void*)newPtr
->tracefile
);
842 printf("block : %u\n" ,(unsigned int)newPtr
->block
);
843 printf("offset : %u\n" ,(unsigned int)newPtr
->offset
);
844 printf("tsc : %lu\n" ,(long unsigned int)newPtr
->tsc
);
845 printf("timestamp : %u\n" ,(unsigned int)newPtr
->timestamp
);
846 printf("event_id : %u\n" ,(unsigned short)newPtr
->event_id
);
847 printf("event_time : %p\n" ,(void*) &newPtr
->event_time
);
848 printf(" sec : %lu\n" ,(long unsigned int)(newPtr
->event_time
.tv_sec
) );
849 printf(" nsec : %lu\n" ,(long unsigned int)(newPtr
->event_time
.tv_nsec
) );
850 printf("data : %p\n" ,(void*) newPtr
->data
);
851 printf("data_size : %u\n" ,(unsigned int)newPtr
->data_size
);
852 printf("event_size : %u\n" ,(unsigned int)newPtr
->event_size
);
853 printf("count : %d\n" ,(int)newPtr
->count
);
854 printf("overflow_nsec : %ld\n" ,(long)newPtr
->overflow_nsec
);
863 ### MARKER method ###
867 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getName(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
868 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
870 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->name
));
874 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getFormatOverview(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
875 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
877 return (*env
)->NewStringUTF(env
, newPtr
->format
);
881 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getSize(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
882 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
884 return (jlong
)newPtr
->size
;
887 /* Method to get all markerField pointers */
888 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getAllMarkerFields(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
889 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
891 jclass accessClass
= (*env
)->GetObjectClass(env
, jobj
);
892 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "addMarkerFieldFromC", "(Ljava/lang/String;J)V");
894 GArray
*field_array
= (GArray
*)newPtr
->fields
;
895 struct marker_field
*field
;
896 jlong marker_field_ptr
;
899 for (i
=0; i
<field_array
->len
; i
++) {
900 field
= &g_array_index(field_array
, struct marker_field
, i
);
902 marker_field_ptr
= CONVERT_PTR_TO_JLONG(field
);
904 (*env
)->CallVoidMethod(env
, jobj
, accessFunction
, (*env
)->NewStringUTF(env
, g_quark_to_string(field
->name
) ), marker_field_ptr
);
910 /* Get of largest_align */
911 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getLargestAlign(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
912 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
914 return (jshort
)newPtr
->largest_align
;
917 /* Get of int_size */
918 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getIntSize(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
919 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
921 return (jshort
)newPtr
->int_size
;
924 /* Get of long_size */
925 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getLongSize(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
926 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
928 return (jshort
)newPtr
->long_size
;
931 /* Get of pointer_size */
932 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getPointerSize(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
933 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
935 return (jshort
)newPtr
->pointer_size
;
938 /* Get of size_t_size */
939 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getSize_1tSize(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
940 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
942 return (jshort
)newPtr
->size_t_size
;
945 /* Get of alignment */
946 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getAlignement(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
947 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
949 return (jshort
)newPtr
->alignment
;
953 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getNextMarkerPtr(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
954 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
956 return CONVERT_PTR_TO_JLONG(newPtr
->next
);
960 /* Function to print the content of a marker */
961 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1printMarker(JNIEnv
*env
, jobject jobj
, jlong marker_info_ptr
) {
962 struct marker_info
*newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
964 printf("name : %s\n" ,g_quark_to_string(newPtr
->name
) );
965 printf("format : %s\n" ,newPtr
->format
);
966 printf("size : %li\n" ,(long int)newPtr
->size
);
967 printf("largest_align : %u\n" ,(unsigned short)newPtr
->largest_align
);
968 printf("fields : %p\n" ,newPtr
->fields
);
969 printf("int_size : %u\n" ,(unsigned short)newPtr
->int_size
);
970 printf("long_size : %u\n" ,(unsigned short)newPtr
->long_size
);
971 printf("pointer_size : %u\n" ,(unsigned short)newPtr
->pointer_size
);
972 printf("size_t_size : %u\n" ,(unsigned short)newPtr
->size_t_size
);
973 printf("alignment : %u\n" ,(unsigned short)newPtr
->alignment
);
974 printf("next : %p\n" ,newPtr
->next
);
984 ### MARKERFIELD Method
988 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getField(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
989 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
991 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->name
));
995 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getType(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
996 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
998 return (jint
)newPtr
->type
;
1002 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getOffset(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1003 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1005 return CONVERT_UINT64_TO_JLONG(newPtr
->offset
);
1009 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getSize(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1010 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1012 return CONVERT_UINT64_TO_JLONG(newPtr
->size
);
1015 /* Get of alignment */
1016 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getAlignment(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1017 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1019 return CONVERT_UINT64_TO_JLONG(newPtr
->alignment
);
1022 /* Get of attributes */
1023 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getAttributes(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1024 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1026 return CONVERT_UINT64_TO_JLONG(newPtr
->attributes
);
1029 /* Get of static_offset */
1030 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getStatic_1offset(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1031 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1033 return (jint
)newPtr
->static_offset
;
1037 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getFormat(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1038 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1040 return (*env
)->NewStringUTF(env
, newPtr
->fmt
->str
);
1043 /* Function to print the content of a marker_field */
1044 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1printMarkerField(JNIEnv
*env
, jobject jobj
, jlong marker_field_ptr
) {
1045 struct marker_field
*newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1047 printf("name : %s\n" ,g_quark_to_string(newPtr
->name
) );
1048 printf("type : %i\n" ,(int)newPtr
->type
);
1049 printf("offset : %lu\n" ,(long unsigned int)newPtr
->offset
);
1050 printf("size : %lu\n" ,(long unsigned int)newPtr
->size
);
1051 printf("alignment : %lu\n" ,(long unsigned int)newPtr
->alignment
);
1052 printf("attributes : %lu\n" ,(long unsigned int)newPtr
->attributes
);
1053 printf("static_offset : %i\n" ,(int)newPtr
->static_offset
);
1054 printf("fmt : %s\n" ,newPtr
->fmt
->str
);
1066 /* This function will do the actual parsing */
1067 /* It will then call java to assign the parsed data to the object "javaObj" */
1068 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniParser_ltt_1getParsedData(JNIEnv
*env
, jclass accessClass
, jobject javaObj
, jlong event_ptr
, jlong marker_field_ptr
) {
1069 LttEvent newEventPtr
= *(LttEvent
*)(CONVERT_JLONG_TO_PTR(event_ptr
));
1070 struct marker_field
*newMarkerFieldPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
1072 jmethodID accessFunction
= NULL
;
1076 There is a very limited number of type in LTT
1077 We will switch on the type for this field and act accordingly
1078 NOTE : We will save all integer into "long" type, as there is no signed/unsigned in java */
1081 It seems the marker_field->type is absolutely not consistent, especially about pointer!
1082 Sometime pointer are saved in String, sometime as Int, sometime as pointer...
1083 We will do an extra check on type "LTT_TYPE_UNSIGNED_INT" to check if the marker_field->format is hint of a pointer */
1084 switch ( newMarkerFieldPtr
->type
) {
1085 case LTT_TYPE_SIGNED_INT
:
1086 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongToParsingFromC", "(Ljava/lang/Object;J)V");
1087 (*env
)->CallStaticVoidMethod( env
,
1091 ltt_event_get_long_int(&newEventPtr
, newMarkerFieldPtr
)
1096 case LTT_TYPE_UNSIGNED_INT
:
1097 /* If the format seems to be a pointer, add it as a pointer */
1098 if ( (strncmp(newMarkerFieldPtr
->fmt
->str
, "0x%llX", newMarkerFieldPtr
->fmt
->len
) == 0 ) || (strncmp(newMarkerFieldPtr
->fmt
->str
, "%llX", newMarkerFieldPtr
->fmt
->len
) == 0 ) ) {
1099 #if __WORDSIZE == 64
1100 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1102 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addIntPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1104 (*env
)->CallStaticVoidMethod( env
,
1108 CONVERT_PTR_TO_JLONG(ltt_event_get_long_unsigned(&newEventPtr
, newMarkerFieldPtr
) )
1111 /* Otherwise, add it as a number */
1113 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongToParsingFromC", "(Ljava/lang/Object;J)V");
1114 (*env
)->CallStaticVoidMethod( env
,
1118 ltt_event_get_long_unsigned(&newEventPtr
, newMarkerFieldPtr
)
1124 case LTT_TYPE_POINTER
:
1125 #if __WORDSIZE == 64
1126 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1128 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addIntPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1130 (*env
)->CallStaticVoidMethod( env
,
1134 CONVERT_PTR_TO_JLONG(*(GINT_TYPE_FOR_PTR
*)(newEventPtr
.data
+ newMarkerFieldPtr
->offset
))
1138 case LTT_TYPE_STRING
:
1139 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addStringToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;)V");
1140 (*env
)->CallStaticVoidMethod( env
,
1144 (*env
)->NewStringUTF(env
, ltt_event_get_string(&newEventPtr
, newMarkerFieldPtr
) )
1148 case LTT_TYPE_COMPACT
:
1149 case LTT_TYPE_NONE
:
1151 printf("Warning : Unrecognized format type! Skipping! (Java_org_eclipse_linuxtools_lttng_jni_JniParser_ltt_1getParsedData)");