2 // !! Important to get consistent size_t type
3 #define _FILE_OFFSET_BITS 64
9 #include <ltt/marker.h>
19 // We've got hell of a problem passing "unsigned int64" to java, as there is no equivalent type
20 // The closer we can use is "long" which is signed, so only 32 (or 63?) bits are valid
21 // Plus, even if we are within the "32 bits" capacity, java sometime screw itself trying to convert "unsigned 64 -> signed 64"
22 // This happen especially often when RETURNING a jlong
23 // So when returning a jlong, we should convert it like this : "unsigned 64"->"signed 64"->jlong
24 #define CONVERT_UINT64_TO_JLONG(n) (jlong)(gint64)(n)
25 #define CONVERT_INT64_TO_JLONG(n) (jlong)(gint64)(n)
27 // To ease calcul involving nano
28 #define BILLION 1000000000
32 #define CONVERT_JLONG_TO_PTR(p) (p)
33 #define CONVERT_PTR_TO_JLONG(p) (jlong)(p)
34 // Define the "gint" type we should use for pointer.
35 #define GINT_TYPE_FOR_PTR gint64
37 // Conversion to int first to save warning
38 #define CONVERT_JLONG_TO_PTR(p) (int)(p)
39 #define CONVERT_PTR_TO_JLONG(p) (jlong)(int)(p)
40 // Define the "gint" type we should use for pointer.
41 #define GINT_TYPE_FOR_PTR gint32
44 // Structure to encapsulate java_data to pass as arguments
45 struct java_calling_data
52 // Find a better way! This is ugly!
55 struct java_calling_data
* java_args
;
56 struct marker_data
* mdata
;
60 // ### COMMON Methods ###
62 // JNI method to call printf from the java side
63 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_Jni_1C_1Common_ltt_1printC(JNIEnv
* env
, jobject jobj
, jstring new_string
)
65 printf("%s", (*env
)->GetStringUTFChars(env
, new_string
, 0) );
73 // ### TRACE methods ###
75 // JNI mapping of < LttTrace *ltt_trace_open(const gchar *pathname) > (trace.h)
76 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1openTrace(JNIEnv
* env
, jobject jobj
, jstring pathname
) {
77 const char* c_pathname
= (*env
)->GetStringUTFChars(env
, pathname
, 0);
78 LttTrace
* newPtr
= ltt_trace_open( c_pathname
);
80 (*env
)->ReleaseStringUTFChars(env
, pathname
, c_pathname
);
82 return CONVERT_PTR_TO_JLONG(newPtr
);
85 // JNI mapping of < void ltt_trace_close(LttTrace *t) > (trace.h)
86 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1closeTrace(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
){
88 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
90 ltt_trace_close(newPtr
);
94 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getTracepath(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
95 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
97 return (*env
)->NewStringUTF(env
, g_quark_to_string( newPtr
->pathname
) );
102 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getCpuNumber(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
103 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
105 return (jint
)newPtr
->num_cpu
;
109 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getArchType(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
110 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
112 return (jlong
)newPtr
->arch_type
;
115 // Get of arch_variant
116 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getArchVariant(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
117 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
119 return (jlong
)newPtr
->arch_variant
;
123 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getArchSize(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
124 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
126 return (jshort
)newPtr
->arch_size
;
129 // Get of ltt_major_version
130 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getLttMajorVersion(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
131 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
133 return (jshort
)newPtr
->ltt_major_version
;
136 // Get of ltt_minor_version
137 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getLttMinorVersion(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
138 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
140 return (jshort
)newPtr
->ltt_minor_version
;
143 // Get of flight_recorder
144 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getFlightRecorder(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
145 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
147 return (jshort
)newPtr
->flight_recorder
;
151 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getFreqScale(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
152 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
154 return (jlong
)newPtr
->freq_scale
;
158 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getStartFreq(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
159 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
161 return CONVERT_UINT64_TO_JLONG(newPtr
->start_freq
);
165 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getStartTimestampCurrentCounter(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
166 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
168 return CONVERT_UINT64_TO_JLONG(newPtr
->start_tsc
);
171 // Get of start_monotonic
172 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getStartMonotonic(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
173 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
175 return CONVERT_UINT64_TO_JLONG(newPtr
->start_monotonic
);
178 // Access to start_time
179 // Note that we are calling the setTimeFromC function in Jaf_Time from here
180 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedStartTime(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
, jobject time_jobj
) {
181 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
183 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
184 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTimeFromC", "(J)V");
186 jlong fullTime
= (CONVERT_UINT64_TO_JLONG(newPtr
->start_time
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(newPtr
->start_time
.tv_nsec
);
188 (*env
)->CallVoidMethod(env
, time_jobj
, accessFunction
, fullTime
);
191 // Access to start_time_from_tsc
192 // Note that we are calling the setTimeFromC function in Jaf_Time from here
193 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1feedStartTimeFromTimestampCurrentCounter(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
, jobject time_jobj
) {
194 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
196 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
197 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTimeFromC", "(J)V");
199 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
);
201 (*env
)->CallVoidMethod(env
, time_jobj
, accessFunction
, fullTime
);
205 // g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getAllTracefiles
206 void g_datalist_foreach_addTracefilesOfTrace(GQuark name
, gpointer data
, gpointer user_data
) {
207 struct java_calling_data
* args
= (struct java_calling_data
*)user_data
;
209 jclass accessClass
= (*args
->env
)->GetObjectClass(args
->env
, args
->jobj
);
210 jmethodID accessFunction
= (*args
->env
)->GetMethodID(args
->env
, accessClass
, "addTracefileFromC", "(Ljava/lang/String;J)V");
212 GArray
* group
= (GArray
*)data
;
213 LttTracefile
* tracefile
;
217 for (i
=0; i
<group
->len
; i
++) {
218 tracefile
= &g_array_index(group
, LttTracefile
, i
);
220 newPtr
= CONVERT_PTR_TO_JLONG(tracefile
);
222 (*args
->env
)->CallVoidMethod(args
->env
, args
->jobj
, accessFunction
, (*args
->env
)->NewStringUTF(args
->env
, g_quark_to_string(tracefile
->name
) ), newPtr
);
226 // Function to fill up the java map with the event type found in tracefile (the name)
227 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getAllTracefiles(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
228 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
230 struct java_calling_data args
= { env
, jobj
};
232 g_datalist_foreach(&newPtr
->tracefiles
, &g_datalist_foreach_addTracefilesOfTrace
, &args
);
236 // Function to print the content of a tracefile
237 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1printTrace(JNIEnv
* env
, jobject jobj
, jlong trace_ptr
) {
239 LttTrace
* newPtr
= (LttTrace
*)CONVERT_JLONG_TO_PTR(trace_ptr
);
241 printf("pathname : %s\n" ,g_quark_to_string(newPtr
->pathname
) );
242 printf("num_cpu : %u\n" ,(unsigned int)(newPtr
->num_cpu
) );
243 printf("arch_type : %u\n" ,(unsigned int)(newPtr
->arch_type
) );
244 printf("arch_variant : %u\n" ,(unsigned int)(newPtr
->arch_variant
) );
245 printf("arch_size : %u\n" ,(unsigned short)(newPtr
->arch_size
) );
246 printf("ltt_major_version : %u\n" ,(unsigned short)(newPtr
->ltt_major_version
) );
247 printf("ltt_minor_version : %u\n" ,(unsigned short)(newPtr
->ltt_minor_version
) );
248 printf("flight_recorder : %u\n" ,(unsigned short)(newPtr
->flight_recorder
) );
249 printf("freq_scale : %u\n" ,(unsigned int)(newPtr
->freq_scale
) );
250 printf("start_freq : %lu\n" ,(long unsigned int)(newPtr
->start_freq
) );
251 printf("start_tsc : %lu\n" ,(long unsigned int)(newPtr
->start_tsc
) );
252 printf("start_monotonic : %lu\n" ,(long unsigned int)(newPtr
->start_monotonic
) );
253 printf("start_time ptr : %p\n" ,&newPtr
->start_time
);
254 printf(" tv_sec : %lu\n" ,(long unsigned int)(newPtr
->start_time
.tv_sec
) );
255 printf(" tv_nsec : %lu\n" ,(long unsigned int)(newPtr
->start_time
.tv_nsec
) );
256 printf("start_time_from_tsc ptr : %p\n" ,&newPtr
->start_time_from_tsc
);
257 printf(" tv_sec : %lu\n" ,(long unsigned int)(newPtr
->start_time_from_tsc
.tv_sec
) );
258 printf(" tv_nsec : %lu\n" ,(long unsigned int)(newPtr
->start_time_from_tsc
.tv_nsec
) );
259 printf("tracefiles ptr : %p\n" ,newPtr
->tracefiles
);
268 // ### TRACEFILE methods ###
271 JNIEXPORT jboolean JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getIsCpuOnline(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
272 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
274 return (jboolean
)newPtr
->cpu_online
;
278 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTracefilepath(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
279 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
281 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->long_name
) );
285 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTracefilename(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
286 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
288 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->name
) );
292 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCpuNumber(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
293 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
295 return (jlong
)newPtr
->cpu_num
;
299 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTid(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
300 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
302 return (jlong
)newPtr
->tid
;
306 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getPgid(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
307 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
309 return (jlong
)newPtr
->pgid
;
313 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCreation(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
314 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
316 return CONVERT_UINT64_TO_JLONG(newPtr
->creation
);
320 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getTracePtr(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
321 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
323 return CONVERT_PTR_TO_JLONG(newPtr
->trace
);
327 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getMarkerDataPtr(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
328 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
330 return CONVERT_PTR_TO_JLONG(newPtr
->mdata
);
334 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCFileDescriptor(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
335 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
337 return (jint
)newPtr
->fd
;
341 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getFileSize(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
342 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
344 return CONVERT_UINT64_TO_JLONG(newPtr
->file_size
);
348 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBlockNumber(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
349 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
351 return (jlong
)newPtr
->num_blocks
;
355 JNIEXPORT jboolean JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getIsBytesOrderReversed(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
356 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
358 return (jboolean
)newPtr
->reverse_bo
;
361 // Get of float_word_order
362 JNIEXPORT jboolean JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getIsFloatWordOrdered(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
363 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
365 return (jboolean
)newPtr
->float_word_order
;
369 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getAlignement(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
370 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
372 return CONVERT_UINT64_TO_JLONG(newPtr
->alignment
);
375 // Get of buffer_header_size
376 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBufferHeaderSize(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
377 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
379 return CONVERT_UINT64_TO_JLONG(newPtr
->buffer_header_size
);
383 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBitsOfCurrentTimestampCounter(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
384 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
386 return (jint
)newPtr
->tscbits
;
390 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBitsOfEvent(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
391 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
393 return (jint
)newPtr
->eventbits
;
397 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCurrentTimestampCounterMask(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
398 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
400 return CONVERT_UINT64_TO_JLONG(newPtr
->tsc_mask
);
403 // Get of tsc_mask_next_bit
404 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getCurrentTimestampCounterMaskNextBit(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
405 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
407 return CONVERT_UINT64_TO_JLONG(newPtr
->tsc_mask_next_bit
);
410 // Get of events_lost
411 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getEventsLost(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
412 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
414 return (jlong
)newPtr
->events_lost
;
417 // Get of subbuf_corrupt
418 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getSubBufferCorrupt(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
419 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
421 return (jlong
)newPtr
->subbuf_corrupt
;
425 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getEventPtr(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
426 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
428 return CONVERT_PTR_TO_JLONG(&newPtr
->event
);
432 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBufferPtr(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
433 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
435 return CONVERT_PTR_TO_JLONG(&newPtr
->buffer
);
439 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getBufferSize(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
440 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
442 return (jlong
)newPtr
->buf_size
;
446 // g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getAllMarkers
447 void g_hash_table_foreach_addMarkersOfTracefile(gpointer key
, gpointer data
, gpointer user_data
) {
448 struct addMarkersArgs
* args
= (struct addMarkersArgs
*)user_data
;
449 struct java_calling_data
* jargs
= (struct java_calling_data
*)args
->java_args
;
451 jclass accessClass
= (*jargs
->env
)->GetObjectClass(jargs
->env
, jargs
->jobj
);
452 jmethodID accessFunction
= (*jargs
->env
)->GetMethodID(jargs
->env
, accessClass
, "addMarkersFromC", "(IJ)V");
454 unsigned long marker_id
= (unsigned long)data
;
456 // The hash table store an ID... we will use the ID to access the array.
457 GArray
* marker
= args
->mdata
->markers
;
458 struct marker_info
* newPtr
= &g_array_index(marker
, struct marker_info
, marker_id
);
460 (*jargs
->env
)->CallVoidMethod(jargs
->env
, jargs
->jobj
, accessFunction
, marker_id
, CONVERT_PTR_TO_JLONG(newPtr
) );
463 // Function to fill up the java map with the event type found in tracefile (the name)
464 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getAllMarkers(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
465 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
468 // Find a better way! This is ugly!
469 struct java_calling_data java_args
= { env
, jobj
};
470 struct addMarkersArgs args
= { &java_args
, newPtr
->mdata
};
472 g_hash_table_foreach( newPtr
->mdata
->markers_hash
, &g_hash_table_foreach_addMarkersOfTracefile
, &args
);
476 // Function to print the content of a tracefile
477 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1printTracefile(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
479 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
480 printf("cpu_online : %i\n" ,(int)newPtr
->cpu_online
);
481 printf("long_name : %s\n" ,g_quark_to_string(newPtr
->long_name
));
482 printf("name : %s\n" ,g_quark_to_string(newPtr
->name
));
483 printf("cpu_num : %u\n" ,(unsigned int)(newPtr
->cpu_num
));
484 printf("tid : %u\n" ,(unsigned int)(newPtr
->tid
));
485 printf("pgid : %u\n" ,(unsigned int)(newPtr
->pgid
));
486 printf("creation : %lu\n" ,(long unsigned int)(newPtr
->creation
));
487 printf("trace ptr : %p\n" ,newPtr
->trace
);
488 printf("marker ptr : %p\n" ,newPtr
->mdata
);
489 printf("fd : %i\n" ,(int)(newPtr
->fd
));
490 printf("file_size : %u\n" ,(unsigned int)(newPtr
->file_size
));
491 printf("num_blocks : %u\n" ,(unsigned int)(newPtr
->num_blocks
));
492 printf("reverse_bo : %i\n" ,(int)newPtr
->reverse_bo
);
493 printf("float_word_order : %i\n" ,(int)newPtr
->float_word_order
);
494 printf("alignment : %i\n" ,(int)newPtr
->alignment
);
495 printf("buffer_header_size : %i\n" ,(int)newPtr
->buffer_header_size
);
496 printf("tscbits : %u\n" ,(unsigned short)newPtr
->tscbits
);
497 printf("eventbits : %u\n" ,(unsigned short)newPtr
->eventbits
);
498 printf("tsc_mask : %lu\n" ,(long unsigned int)newPtr
->tsc_mask
);
499 printf("tsc_mask_next_bit : %lu\n" ,(long unsigned int)newPtr
->tsc_mask_next_bit
);
500 printf("events_lost : %u\n" ,(unsigned int)newPtr
->events_lost
);
501 printf("subbuf_corrupt : %u\n" ,(unsigned int)newPtr
->subbuf_corrupt
);
502 printf("event ptr : %p\n" ,&newPtr
->event
);
503 printf("buffer ptr : %p\n" ,&newPtr
->buffer
);
504 printf("buf_size : %i\n" ,(unsigned int)newPtr
->buf_size
);
512 // ### EVENT methods ###
515 // Method to get the read status
516 // This method will read the next event and then seek back its initial position
517 // Lttv assume that every tracefile have at least 1 event, but we have not guarantee after this one.
518 // We will read the next event and return the status of that read
519 // We will then seek back to our initial position
520 // Note : this method is expensive and should not be used too often
521 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1positionToFirstEvent(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
522 LttTracefile
* tracefilePtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
524 // Ask ltt to read the next events on the given tracefiles
525 // Returned value can be :
526 // 0 if everything went fine (EOK)
527 // ERANGE = 34 out of range, back to last event (might be system dependent?)
528 // EPERM = 1 error while reading (might be system dependent?)
531 // Seek to the start time... this will also read the first event, as we want.
532 int returnedValue
= ltt_tracefile_seek_time(tracefilePtr
, ((struct LttTrace
)*(tracefilePtr
->trace
)).start_time_from_tsc
);
534 return (jint
)returnedValue
;
537 // Method to read next event
538 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1readNextEvent(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
) {
539 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
541 // Ask ltt to read the next events on the given tracefiles
542 // Returned value can be :
543 // 0 if everything went fine (EOK)
544 // ERANGE = 34 out of range, back to last event (might be system dependent?)
545 // EPERM = 1 error while reading (might be system dependent?)
549 // This might fail on the FIRST event, as the timestamp before the first read is uninitialized
550 // However, LTT make the assumption that all tracefile have AT LEAST one event, so we got to run with it
552 // Save "last time" before moving, to be able to get back if needed
553 LttTime lastTime
= newPtr
->event
.event_time
;
555 int returnedValue
= ltt_tracefile_read(newPtr
);
557 // According to Ltt documentation, we need to get back to beginning after an error
558 if ( returnedValue
!= 0 ) {
559 ltt_tracefile_seek_time(newPtr
, lastTime
);
562 return (jint
)returnedValue
;
565 // Method to seek to a certain event
566 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1seekEvent(JNIEnv
* env
, jobject jobj
, jlong tracefile_ptr
, jobject time_jobj
) {
567 LttTracefile
* newPtr
= (LttTracefile
*)CONVERT_JLONG_TO_PTR(tracefile_ptr
);
569 guint64 fullTime
= 0;
571 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
572 jmethodID getTimeFunction
= (*env
)->GetMethodID(env
, accessClass
, "getTime", "()J");
573 fullTime
= (*env
)->CallLongMethod(env
, time_jobj
, getTimeFunction
);
576 // Conversion from jlong -> C long seems to be particularly sloppy
577 // Depending how and where (inlined a function or as a single operation) we do this, we might end up with wrong number
578 // The following asignation of guint64 seems to work well.
579 // MAKE SURE TO PERFORM SEVERAL TESTS IF YOU CHANGE THIS.
580 guint64 seconds
= fullTime
/BILLION
;
581 guint64 nanoSeconds
= fullTime
%BILLION
;
583 LttTime seekTime
= { (unsigned long)seconds
, (unsigned long)nanoSeconds
};
585 // Ask ltt to read the next events on the given tracefiles
586 // Returned value can be :
587 // 0 if everything went fine (EOK)
588 // ERANGE = 34 out of range, back to last event (might be system dependent?)
589 // EPERM = 1 error while reading (might be system dependent?)
591 int returnedValue
= ltt_tracefile_seek_time(newPtr
, seekTime
);
592 return (jint
)returnedValue
;
596 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getTracefilePtr(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
597 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
599 return CONVERT_PTR_TO_JLONG(newPtr
->tracefile
);
603 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getBlock(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
604 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
606 return (jlong
)newPtr
->block
;
610 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getOffset(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
611 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
613 return (jlong
)newPtr
->offset
;
617 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getCurrentTimestampCounter(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
618 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
620 return CONVERT_UINT64_TO_JLONG(newPtr
->tsc
);
624 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getTimestamp(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
625 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
627 return (jlong
)newPtr
->timestamp
;
631 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getEventMarkerId(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
632 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
634 return (jint
)newPtr
->event_id
;
638 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1feedEventTime(JNIEnv
* env
, jobject jobj
, jlong event_ptr
, jobject time_jobj
) {
639 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
641 jclass accessClass
= (*env
)->GetObjectClass(env
, time_jobj
);
642 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "setTimeFromC", "(J)V");
644 jlong fullTime
= (CONVERT_UINT64_TO_JLONG(newPtr
->event_time
.tv_sec
)*BILLION
) + CONVERT_UINT64_TO_JLONG(newPtr
->event_time
.tv_nsec
);
646 (*env
)->CallVoidMethod(env
, time_jobj
, accessFunction
, fullTime
);
649 // Access method to the data
650 // The data are in "byte" form
651 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getDataContent(JNIEnv
* env
, jobject jobj
, jlong event_ptr
, jlong data_size
, jbyteArray dataArray
) {
652 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
654 (*env
)->SetByteArrayRegion(env
, dataArray
, 0, (jsize
)data_size
, newPtr
->data
);
658 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getEventDataSize(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
659 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
661 return (jlong
)newPtr
->data_size
;
665 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getEventSize(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
666 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
668 return (jlong
)newPtr
->event_size
;
672 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getCount(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
673 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
675 return (jint
)newPtr
->count
;
678 // Get of overflow_nsec
679 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1getOverflowNanoSeconds(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
680 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
682 return CONVERT_UINT64_TO_JLONG(newPtr
->overflow_nsec
);
686 // Function to print the content of a event
687 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniEvent_ltt_1printEvent(JNIEnv
* env
, jobject jobj
, jlong event_ptr
) {
688 LttEvent
* newPtr
= (LttEvent
*)CONVERT_JLONG_TO_PTR(event_ptr
);
690 printf("tracefile : %p\n" ,(void*)newPtr
->tracefile
);
691 printf("block : %u\n" ,(unsigned int)newPtr
->block
);
692 printf("offset : %u\n" ,(unsigned int)newPtr
->offset
);
693 printf("tsc : %lu\n" ,(long unsigned int)newPtr
->tsc
);
694 printf("timestamp : %u\n" ,(unsigned int)newPtr
->timestamp
);
695 printf("event_id : %u\n" ,(unsigned short)newPtr
->event_id
);
696 printf("event_time : %p\n" ,(void*) &newPtr
->event_time
);
697 printf(" sec : %lu\n" ,(long unsigned int)(newPtr
->event_time
.tv_sec
) );
698 printf(" nsec : %lu\n" ,(long unsigned int)(newPtr
->event_time
.tv_nsec
) );
699 printf("data : %p\n" ,(void*) newPtr
->data
);
700 printf("data_size : %u\n" ,(unsigned int)newPtr
->data_size
);
701 printf("event_size : %u\n" ,(unsigned int)newPtr
->event_size
);
702 printf("count : %d\n" ,(int)newPtr
->count
);
703 printf("overflow_nsec : %ld\n" ,(long)newPtr
->overflow_nsec
);
710 // ### MARKER method ###
714 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getName(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
715 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
717 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->name
));
721 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getFormatOverview(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
722 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
724 return (*env
)->NewStringUTF(env
, newPtr
->format
);
728 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getSize(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
729 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
731 return (jlong
)newPtr
->size
;
734 // Method to get all markerField pointers
735 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getAllMarkerFields(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
736 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
738 jclass accessClass
= (*env
)->GetObjectClass(env
, jobj
);
739 jmethodID accessFunction
= (*env
)->GetMethodID(env
, accessClass
, "addMarkerFieldFromC", "(Ljava/lang/String;J)V");
741 GArray
* field_array
= (GArray
*)newPtr
->fields
;
742 struct marker_field
* field
;
743 jlong marker_field_ptr
;
746 for (i
=0; i
<field_array
->len
; i
++) {
747 field
= &g_array_index(field_array
, struct marker_field
, i
);
749 marker_field_ptr
= CONVERT_PTR_TO_JLONG(field
);
751 (*env
)->CallVoidMethod(env
, jobj
, accessFunction
, (*env
)->NewStringUTF(env
, g_quark_to_string(field
->name
) ), marker_field_ptr
);
757 // Get of largest_align
758 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getLargestAlign(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
759 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
761 return (jshort
)newPtr
->largest_align
;
765 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getIntSize(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
766 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
768 return (jshort
)newPtr
->int_size
;
772 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getLongSize(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
773 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
775 return (jshort
)newPtr
->long_size
;
778 // Get of pointer_size
779 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getPointerSize(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
780 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
782 return (jshort
)newPtr
->pointer_size
;
785 // Get of size_t_size
786 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getSize_1tSize(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
787 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
789 return (jshort
)newPtr
->size_t_size
;
793 JNIEXPORT jshort JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getAlignement(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
794 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
796 return (jshort
)newPtr
->alignment
;
800 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1getNextMarkerPtr(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
801 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
803 return CONVERT_PTR_TO_JLONG(newPtr
->next
);
807 // Function to print the content of a marker
808 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarker_ltt_1printMarker(JNIEnv
* env
, jobject jobj
, jlong marker_info_ptr
) {
809 struct marker_info
* newPtr
= (struct marker_info
*)CONVERT_JLONG_TO_PTR(marker_info_ptr
);
811 printf("name : %s\n" ,g_quark_to_string(newPtr
->name
) );
812 printf("format : %s\n" ,newPtr
->format
);
813 printf("size : %li\n" ,(long int)newPtr
->size
);
814 printf("largest_align : %u\n" ,(unsigned short)newPtr
->largest_align
);
815 printf("fields : %p\n" ,newPtr
->fields
);
816 printf("int_size : %u\n" ,(unsigned short)newPtr
->int_size
);
817 printf("long_size : %u\n" ,(unsigned short)newPtr
->long_size
);
818 printf("pointer_size : %u\n" ,(unsigned short)newPtr
->pointer_size
);
819 printf("size_t_size : %u\n" ,(unsigned short)newPtr
->size_t_size
);
820 printf("alignment : %u\n" ,(unsigned short)newPtr
->alignment
);
821 printf("next : %p\n" ,newPtr
->next
);
830 // ### MARKERFIELD Method
834 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getField(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
835 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
837 return (*env
)->NewStringUTF(env
, g_quark_to_string(newPtr
->name
));
841 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getType(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
842 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
844 return (jint
)newPtr
->type
;
848 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getOffset(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
849 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
851 return CONVERT_UINT64_TO_JLONG(newPtr
->offset
);
855 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getSize(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
856 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
858 return CONVERT_UINT64_TO_JLONG(newPtr
->size
);
862 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getAlignment(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
863 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
865 return CONVERT_UINT64_TO_JLONG(newPtr
->alignment
);
869 JNIEXPORT jlong JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getAttributes(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
870 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
872 return CONVERT_UINT64_TO_JLONG(newPtr
->attributes
);
875 // Get of static_offset
876 JNIEXPORT jint JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getStatic_1offset(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
877 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
879 return (jint
)newPtr
->static_offset
;
883 JNIEXPORT jstring JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1getFormat(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
884 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
886 return (*env
)->NewStringUTF(env
, newPtr
->fmt
->str
);
889 // Function to print the content of a marker_field
890 JNIEXPORT
void JNICALL
Java_org_eclipse_linuxtools_lttng_jni_JniMarkerField_ltt_1printMarkerField(JNIEnv
* env
, jobject jobj
, jlong marker_field_ptr
) {
891 struct marker_field
* newPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
893 printf("name : %s\n" ,g_quark_to_string(newPtr
->name
) );
894 printf("type : %i\n" ,(int)newPtr
->type
);
895 printf("offset : %lu\n" ,(long unsigned int)newPtr
->offset
);
896 printf("size : %lu\n" ,(long unsigned int)newPtr
->size
);
897 printf("alignment : %lu\n" ,(long unsigned int)newPtr
->alignment
);
898 printf("attributes : %lu\n" ,(long unsigned int)newPtr
->attributes
);
899 printf("static_offset : %i\n" ,(int)newPtr
->static_offset
);
900 printf("fmt : %s\n" ,newPtr
->fmt
->str
);
911 // This function will do the actual parsing
912 // It will then call java to assign the parsed data to the object "javaObj"
913 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
) {
914 LttEvent newEventPtr
= *(LttEvent
*)(CONVERT_JLONG_TO_PTR(event_ptr
));
915 struct marker_field
* newMarkerFieldPtr
= (struct marker_field
*)CONVERT_JLONG_TO_PTR(marker_field_ptr
);
917 jmethodID accessFunction
= NULL
;
920 // There is a very limited number of type in LTT
921 // We will switch on the type for this field and act accordingly
922 // NOTE : We will save all integer into "long" type, as there is no signed/unsigned in java
925 // It seems the marker_field->type is absolutely not consistent, especially about pointer!
926 // Sometime pointer are saved in String, sometime as Int, sometime as pointer...
927 // We will do an extra check on type "LTT_TYPE_UNSIGNED_INT" to check if the marker_field->format is hint of a pointer
928 switch ( newMarkerFieldPtr
->type
) {
929 case LTT_TYPE_SIGNED_INT
:
930 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
931 (*env
)->CallStaticVoidMethod( env
,
935 (*env
)->NewStringUTF(env
, g_quark_to_string(newMarkerFieldPtr
->name
) ),
936 ltt_event_get_long_int(&newEventPtr
, newMarkerFieldPtr
),
937 (*env
)->NewStringUTF(env
, newMarkerFieldPtr
->fmt
->str
)
942 case LTT_TYPE_UNSIGNED_INT
:
944 // If the format seems to be a pointer, add it as a pointer
945 if ( (strncmp(newMarkerFieldPtr
->fmt
->str
, "0x%llX", newMarkerFieldPtr
->fmt
->len
) == 0 ) || (strncmp(newMarkerFieldPtr
->fmt
->str
, "%llX", newMarkerFieldPtr
->fmt
->len
) == 0 ) ) {
946 #if ARCHITECTURE_IS_64BITS == 0
947 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addIntPointerToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
949 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongPointerToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
951 (*env
)->CallStaticVoidMethod( env
,
955 (*env
)->NewStringUTF(env
, g_quark_to_string(newMarkerFieldPtr
->name
) ),
956 CONVERT_PTR_TO_JLONG(ltt_event_get_long_unsigned(&newEventPtr
, newMarkerFieldPtr
) ),
957 (*env
)->NewStringUTF(env
, newMarkerFieldPtr
->fmt
->str
)
960 // Otherwise, add it as a number
962 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
963 (*env
)->CallStaticVoidMethod( env
,
967 (*env
)->NewStringUTF(env
, g_quark_to_string(newMarkerFieldPtr
->name
) ),
968 ltt_event_get_long_unsigned(&newEventPtr
, newMarkerFieldPtr
),
969 (*env
)->NewStringUTF(env
, newMarkerFieldPtr
->fmt
->str
)
975 case LTT_TYPE_POINTER
:
976 #if ARCHITECTURE_IS_64BITS == 0
977 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addIntPointerToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
979 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addLongPointerToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
981 (*env
)->CallStaticVoidMethod( env
,
985 (*env
)->NewStringUTF(env
, g_quark_to_string(newMarkerFieldPtr
->name
) ),
986 CONVERT_PTR_TO_JLONG(*(GINT_TYPE_FOR_PTR
*)(newEventPtr
.data
+ newMarkerFieldPtr
->offset
)),
987 (*env
)->NewStringUTF(env
, newMarkerFieldPtr
->fmt
->str
)
991 case LTT_TYPE_STRING
:
992 accessFunction
= (*env
)->GetStaticMethodID(env
, accessClass
, "addStringToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V");
993 (*env
)->CallStaticVoidMethod( env
,
997 (*env
)->NewStringUTF(env
, g_quark_to_string(newMarkerFieldPtr
->name
) ),
998 (*env
)->NewStringUTF(env
, ltt_event_get_string(&newEventPtr
, newMarkerFieldPtr
) ),
999 (*env
)->NewStringUTF(env
, newMarkerFieldPtr
->fmt
->str
)
1003 case LTT_TYPE_COMPACT
:
1004 case LTT_TYPE_NONE
:
1006 printf("Warning : Unrecognized format type! Skipping! (Java_org_eclipse_linuxtools_lttng_jni_JniParser_ltt_1fillParseArray)");