Update version
[lttv.git] / ltt / jni_interface.c
... / ...
CommitLineData
1
2// !! Important to get consistent size_t type
3#define _FILE_OFFSET_BITS 64
4
5#include <jni.h>
6
7#include <ltt/trace.h>
8#include <ltt/time.h>
9#include <ltt/marker.h>
10#include <glib.h>
11
12#include <stdlib.h>
13#include <stdio.h>
14#include <string.h>
15#include <stdint.h>
16
17// *** FIXME ***
18// *** HACK ***
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)
26
27// To ease calcul involving nano
28#define BILLION 1000000000
29
30
31#if __WORDSIZE == 64
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
36#else
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
42#endif
43
44// Structure to encapsulate java_data to pass as arguments
45struct java_calling_data
46{
47 JNIEnv* env;
48 jobject jobj;
49};
50
51// *** TODO **
52// Find a better way! This is ugly!
53struct addMarkersArgs
54{
55 struct java_calling_data* java_args;
56 struct marker_data* mdata;
57};
58
59
60// ### COMMON Methods ###
61// #
62// JNI method to call printf from the java side
63JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_Jni_1C_1Common_ltt_1printC(JNIEnv* env, jobject jobj, jstring new_string)
64{
65 printf("%s", (*env)->GetStringUTFChars(env, new_string, 0) );
66}
67
68// #
69// ####
70
71
72
73// ### TRACE methods ###
74// #
75// JNI mapping of < LttTrace *ltt_trace_open(const gchar *pathname) > (trace.h)
76JNIEXPORT 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 );
79
80 (*env)->ReleaseStringUTFChars(env, pathname, c_pathname);
81
82 return CONVERT_PTR_TO_JLONG(newPtr);
83}
84
85// JNI mapping of < void ltt_trace_close(LttTrace *t) > (trace.h)
86JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1closeTrace(JNIEnv* env, jobject jobj, jlong trace_ptr){
87
88 LttTrace* newPtr = (LttTrace*)CONVERT_JLONG_TO_PTR(trace_ptr);
89
90 ltt_trace_close(newPtr);
91}
92
93// Get the tracepath
94JNIEXPORT 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);
96
97 return (*env)->NewStringUTF(env, g_quark_to_string( newPtr->pathname) );
98}
99
100
101// Get of num_cpu
102JNIEXPORT 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);
104
105 return (jint)newPtr->num_cpu;
106}
107
108// Get of arch_type
109JNIEXPORT 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);
111
112 return (jlong)newPtr->arch_type;
113}
114
115// Get of arch_variant
116JNIEXPORT 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);
118
119 return (jlong)newPtr->arch_variant;
120}
121
122// Get of arch_size
123JNIEXPORT 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);
125
126 return (jshort)newPtr->arch_size;
127}
128
129// Get of ltt_major_version
130JNIEXPORT 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);
132
133 return (jshort)newPtr->ltt_major_version;
134}
135
136// Get of ltt_minor_version
137JNIEXPORT 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);
139
140 return (jshort)newPtr->ltt_minor_version;
141}
142
143// Get of flight_recorder
144JNIEXPORT 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);
146
147 return (jshort)newPtr->flight_recorder;
148}
149
150// Get of freq_scale
151JNIEXPORT 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);
153
154 return (jlong)newPtr->freq_scale;
155}
156
157// Get of start_freq
158JNIEXPORT 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);
160
161 return CONVERT_UINT64_TO_JLONG(newPtr->start_freq);
162}
163
164// Get of start_tsc
165JNIEXPORT 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);
167
168 return CONVERT_UINT64_TO_JLONG(newPtr->start_tsc);
169}
170
171// Get of start_monotonic
172JNIEXPORT 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);
174
175 return CONVERT_UINT64_TO_JLONG(newPtr->start_monotonic);
176}
177
178// Access to start_time
179// Note that we are calling the setTimeFromC function in Jaf_Time from here
180JNIEXPORT 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);
182
183 jclass accessClass = (*env)->GetObjectClass(env, time_jobj);
184 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTimeFromC", "(J)V");
185
186 jlong fullTime = (CONVERT_UINT64_TO_JLONG(newPtr->start_time.tv_sec)*BILLION) + CONVERT_UINT64_TO_JLONG(newPtr->start_time.tv_nsec);
187
188 (*env)->CallVoidMethod(env, time_jobj, accessFunction, fullTime );
189}
190
191// Access to start_time_from_tsc
192// Note that we are calling the setTimeFromC function in Jaf_Time from here
193JNIEXPORT 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);
195
196 jclass accessClass = (*env)->GetObjectClass(env, time_jobj);
197 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTimeFromC", "(J)V");
198
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);
200
201 (*env)->CallVoidMethod(env, time_jobj, accessFunction, fullTime);
202}
203
204
205// g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1getAllTracefiles
206void g_datalist_foreach_addTracefilesOfTrace(GQuark name, gpointer data, gpointer user_data) {
207 struct java_calling_data* args = (struct java_calling_data*)user_data;
208
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");
211
212 GArray* group = (GArray*)data;
213 LttTracefile* tracefile;
214 jlong newPtr;
215
216 unsigned int i;
217 for (i=0; i<group->len; i++) {
218 tracefile = &g_array_index(group, LttTracefile, i);
219
220 newPtr = CONVERT_PTR_TO_JLONG(tracefile);
221
222 (*args->env)->CallVoidMethod(args->env, args->jobj, accessFunction, (*args->env)->NewStringUTF(args->env, g_quark_to_string(tracefile->name) ), newPtr );
223 }
224}
225
226// Function to fill up the java map with the event type found in tracefile (the name)
227JNIEXPORT 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);
229
230 struct java_calling_data args = { env, jobj };
231
232 g_datalist_foreach(&newPtr->tracefiles, &g_datalist_foreach_addTracefilesOfTrace, &args);
233}
234
235
236// Function to print the content of a tracefile
237JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTrace_ltt_1printTrace(JNIEnv* env, jobject jobj, jlong trace_ptr) {
238
239 LttTrace* newPtr = (LttTrace*)CONVERT_JLONG_TO_PTR(trace_ptr);
240
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);
260 printf("\n");
261}
262// #
263// ###
264
265
266
267
268// ### TRACEFILE methods ###
269// #
270// Get of cpu_online
271JNIEXPORT 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);
273
274 return (jboolean)newPtr->cpu_online;
275}
276
277// Get of long_name
278JNIEXPORT 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);
280
281 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->long_name) );
282}
283
284// Get of name
285JNIEXPORT 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);
287
288 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->name) );
289}
290
291// Get of cpu_num
292JNIEXPORT 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);
294
295 return (jlong)newPtr->cpu_num;
296}
297
298// Get of tid
299JNIEXPORT 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);
301
302 return (jlong)newPtr->tid;
303}
304
305// Get of pgid
306JNIEXPORT 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);
308
309 return (jlong)newPtr->pgid;
310}
311
312// Get of creation
313JNIEXPORT 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);
315
316 return CONVERT_UINT64_TO_JLONG(newPtr->creation);
317}
318
319// Get of trace
320JNIEXPORT 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);
322
323 return CONVERT_PTR_TO_JLONG(newPtr->trace);
324}
325
326// Get of mdata
327JNIEXPORT 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);
329
330 return CONVERT_PTR_TO_JLONG(newPtr->mdata);
331}
332
333// Get of fd
334JNIEXPORT 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);
336
337 return (jint)newPtr->fd;
338}
339
340// Get of file_size
341JNIEXPORT 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);
343
344 return CONVERT_UINT64_TO_JLONG(newPtr->file_size);
345}
346
347// Get of num_blocks
348JNIEXPORT 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);
350
351 return (jlong)newPtr->num_blocks;
352}
353
354// Get of reverse_bo
355JNIEXPORT 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);
357
358 return (jboolean)newPtr->reverse_bo;
359}
360
361// Get of float_word_order
362JNIEXPORT 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);
364
365 return (jboolean)newPtr->float_word_order;
366}
367
368// Get of alignment
369JNIEXPORT 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);
371
372 return CONVERT_UINT64_TO_JLONG(newPtr->alignment);
373}
374
375// Get of buffer_header_size
376JNIEXPORT 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);
378
379 return CONVERT_UINT64_TO_JLONG(newPtr->buffer_header_size);
380}
381
382// Get of tscbits
383JNIEXPORT 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);
385
386 return (jint)newPtr->tscbits;
387}
388
389// Get of eventbits
390JNIEXPORT 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);
392
393 return (jint)newPtr->eventbits;
394}
395
396// Get of tsc_mask
397JNIEXPORT 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);
399
400 return CONVERT_UINT64_TO_JLONG(newPtr->tsc_mask);
401}
402
403// Get of tsc_mask_next_bit
404JNIEXPORT 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);
406
407 return CONVERT_UINT64_TO_JLONG(newPtr->tsc_mask_next_bit);
408}
409
410// Get of events_lost
411JNIEXPORT 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);
413
414 return (jlong)newPtr->events_lost;
415}
416
417// Get of subbuf_corrupt
418JNIEXPORT 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);
420
421 return (jlong)newPtr->subbuf_corrupt;
422}
423
424// Get of event
425JNIEXPORT 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);
427
428 return CONVERT_PTR_TO_JLONG(&newPtr->event);
429}
430
431// Get of buffer
432JNIEXPORT 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);
434
435 return CONVERT_PTR_TO_JLONG(&newPtr->buffer);
436}
437
438// Get of buf_size
439JNIEXPORT 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);
441
442 return (jlong)newPtr->buf_size;
443}
444
445
446// g_list_data function for the "for_each" call in Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1getAllMarkers
447void 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;
450
451 jclass accessClass = (*jargs->env)->GetObjectClass(jargs->env, jargs->jobj);
452 jmethodID accessFunction = (*jargs->env)->GetMethodID(jargs->env, accessClass, "addMarkersFromC", "(IJ)V");
453
454 unsigned long marker_id = (unsigned long)data;
455
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);
459
460 (*jargs->env)->CallVoidMethod(jargs->env, jargs->jobj, accessFunction, marker_id, CONVERT_PTR_TO_JLONG(newPtr) );
461}
462
463// Function to fill up the java map with the event type found in tracefile (the name)
464JNIEXPORT 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);
466
467 // *** TODO ***
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 };
471
472 g_hash_table_foreach( newPtr->mdata->markers_hash, &g_hash_table_foreach_addMarkersOfTracefile, &args);
473}
474
475
476// Function to print the content of a tracefile
477JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_JniTracefile_ltt_1printTracefile(JNIEnv* env, jobject jobj, jlong tracefile_ptr) {
478
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);
505 printf("\n");
506}
507// #
508// ###
509
510
511
512// ### EVENT methods ###
513// #
514
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
521JNIEXPORT 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);
523
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?)
529
530
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);
533
534 return (jint)returnedValue;
535}
536
537// Method to read next event
538JNIEXPORT 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);
540
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?)
546
547
548 // *** FIXME ***
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
551 //
552 // Save "last time" before moving, to be able to get back if needed
553 LttTime lastTime = newPtr->event.event_time;
554
555 int returnedValue = ltt_tracefile_read(newPtr);
556
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);
560 }
561
562 return (jint)returnedValue;
563}
564
565// Method to seek to a certain event
566JNIEXPORT 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);
568
569 guint64 fullTime = 0;
570
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);
574
575 // *** HACK ***
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;
582
583 LttTime seekTime = { (unsigned long)seconds, (unsigned long)nanoSeconds };
584
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?)
590
591 int returnedValue = ltt_tracefile_seek_time(newPtr, seekTime);
592 return (jint)returnedValue;
593}
594
595// Get of tracefile
596JNIEXPORT 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);
598
599 return CONVERT_PTR_TO_JLONG(newPtr->tracefile);
600}
601
602// Get of block
603JNIEXPORT 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);
605
606 return (jlong)newPtr->block;
607}
608
609// Get of offset
610JNIEXPORT 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);
612
613 return (jlong)newPtr->offset;
614}
615
616// Get of tsc
617JNIEXPORT 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);
619
620 return CONVERT_UINT64_TO_JLONG(newPtr->tsc);
621}
622
623// Get of timestamp
624JNIEXPORT 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);
626
627 return (jlong)newPtr->timestamp;
628}
629
630// Get of event_id
631JNIEXPORT 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);
633
634 return (jint)newPtr->event_id;
635}
636
637// Get of event_time
638JNIEXPORT 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);
640
641 jclass accessClass = (*env)->GetObjectClass(env, time_jobj);
642 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTimeFromC", "(J)V");
643
644 jlong fullTime = (CONVERT_UINT64_TO_JLONG(newPtr->event_time.tv_sec)*BILLION) + CONVERT_UINT64_TO_JLONG(newPtr->event_time.tv_nsec);
645
646 (*env)->CallVoidMethod(env, time_jobj, accessFunction, fullTime);
647}
648
649// Access method to the data
650// The data are in "byte" form
651JNIEXPORT 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);
653
654 (*env)->SetByteArrayRegion(env, dataArray, 0, (jsize)data_size, newPtr->data);
655}
656
657// Get of data_size
658JNIEXPORT 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);
660
661 return (jlong)newPtr->data_size;
662}
663
664// Get of event_size
665JNIEXPORT 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);
667
668 return (jlong)newPtr->event_size;
669}
670
671// Get of count
672JNIEXPORT 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);
674
675 return (jint)newPtr->count;
676}
677
678// Get of overflow_nsec
679JNIEXPORT 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);
681
682 return CONVERT_UINT64_TO_JLONG(newPtr->overflow_nsec);
683}
684
685
686// Function to print the content of a event
687JNIEXPORT 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);
689
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 );
704 printf("\n");
705}
706// #
707// ###
708
709
710// ### MARKER method ###
711// #
712
713// Get of name
714JNIEXPORT 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);
716
717 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->name));
718}
719
720// Get of format
721JNIEXPORT 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);
723
724 return (*env)->NewStringUTF(env, newPtr->format);
725}
726
727// Get of size
728JNIEXPORT 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);
730
731 return (jlong)newPtr->size;
732}
733
734// Method to get all markerField pointers
735JNIEXPORT 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);
737
738 jclass accessClass = (*env)->GetObjectClass(env, jobj);
739 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "addMarkerFieldFromC", "(Ljava/lang/String;J)V");
740
741 GArray* field_array = (GArray*)newPtr->fields;
742 struct marker_field* field;
743 jlong marker_field_ptr;
744
745 unsigned int i;
746 for (i=0; i<field_array->len; i++) {
747 field = &g_array_index(field_array, struct marker_field, i);
748
749 marker_field_ptr = CONVERT_PTR_TO_JLONG(field);
750
751 (*env)->CallVoidMethod(env, jobj, accessFunction, (*env)->NewStringUTF(env, g_quark_to_string(field->name) ), marker_field_ptr );
752 }
753}
754
755
756
757// Get of largest_align
758JNIEXPORT 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);
760
761 return (jshort)newPtr->largest_align;
762}
763
764// Get of int_size
765JNIEXPORT 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);
767
768 return (jshort)newPtr->int_size;
769}
770
771// Get of long_size
772JNIEXPORT 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);
774
775 return (jshort)newPtr->long_size;
776}
777
778// Get of pointer_size
779JNIEXPORT 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);
781
782 return (jshort)newPtr->pointer_size;
783}
784
785// Get of size_t_size
786JNIEXPORT 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);
788
789 return (jshort)newPtr->size_t_size;
790}
791
792// Get of alignment
793JNIEXPORT 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);
795
796 return (jshort)newPtr->alignment;
797}
798
799// Get of next
800JNIEXPORT 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);
802
803 return CONVERT_PTR_TO_JLONG(newPtr->next);
804}
805
806
807// Function to print the content of a marker
808JNIEXPORT 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);
810
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 );
822 printf("\n");
823}
824
825// #
826// ###
827
828
829
830// ### MARKERFIELD Method
831// #
832
833// Get of name
834JNIEXPORT 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);
836
837 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->name));
838}
839
840// Get of type
841JNIEXPORT 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);
843
844 return (jint)newPtr->type;
845}
846
847// Get of offset
848JNIEXPORT 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);
850
851 return CONVERT_UINT64_TO_JLONG(newPtr->offset);
852}
853
854// Get of size
855JNIEXPORT 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);
857
858 return CONVERT_UINT64_TO_JLONG(newPtr->size);
859}
860
861// Get of alignment
862JNIEXPORT 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);
864
865 return CONVERT_UINT64_TO_JLONG(newPtr->alignment);
866}
867
868// Get of attributes
869JNIEXPORT 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);
871
872 return CONVERT_UINT64_TO_JLONG(newPtr->attributes);
873}
874
875// Get of static_offset
876JNIEXPORT 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);
878
879 return (jint)newPtr->static_offset;
880}
881
882// Get of fmt
883JNIEXPORT 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);
885
886 return (*env)->NewStringUTF(env, newPtr->fmt->str);
887}
888
889// Function to print the content of a marker_field
890JNIEXPORT 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);
892
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 );
901 printf("\n");
902}
903
904// #
905// ###
906
907
908// ### PARSER Method
909// #
910
911// This function will do the actual parsing
912// It will then call java to assign the parsed data to the object "javaObj"
913JNIEXPORT 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);
916
917 jmethodID accessFunction = NULL;
918
919
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
923
924 // *** HACK ***
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,
932 accessClass,
933 accessFunction,
934 javaObj,
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 )
938 );
939
940 break;
941
942 case LTT_TYPE_UNSIGNED_INT :
943
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");
948 #else
949 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addLongPointerToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
950 #endif
951 (*env)->CallStaticVoidMethod( env,
952 accessClass,
953 accessFunction,
954 javaObj,
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 )
958 );
959 }
960 // Otherwise, add it as a number
961 else {
962 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addLongToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
963 (*env)->CallStaticVoidMethod( env,
964 accessClass,
965 accessFunction,
966 javaObj,
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 )
970 );
971 }
972
973 break;
974
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");
978 #else
979 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addLongPointerToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;J)V");
980 #endif
981 (*env)->CallStaticVoidMethod( env,
982 accessClass,
983 accessFunction,
984 javaObj,
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 )
988 );
989 break;
990
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,
994 accessClass,
995 accessFunction,
996 javaObj,
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 )
1000 );
1001 break;
1002
1003 case LTT_TYPE_COMPACT :
1004 case LTT_TYPE_NONE :
1005 default :
1006 printf("Warning : Unrecognized format type! Skipping! (Java_org_eclipse_linuxtools_lttng_jni_JniParser_ltt_1fillParseArray)");
1007 break;
1008 }
1009
1010}
1011
1012// #
1013// ###
This page took 0.027247 seconds and 4 git commands to generate.