Removing whitespace/align errors
[lttv.git] / ltt / jni_interface.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2010 William Bourque
3 *
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.
7 *
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.
12 *
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.
17 */
18
19 /* Important to get consistent size_t type */
20 #define _FILE_OFFSET_BITS 64
21
22 #include <jni.h>
23
24 #include <ltt/trace.h>
25 #include <ltt/time.h>
26 #include <ltt/marker.h>
27 #include <glib.h>
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdint.h>
33
34 /*
35 ***FIXME***
36 ***HACK***
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
42 */
43 #define CONVERT_UINT64_TO_JLONG(n) (jlong)(gint64)(n)
44 #define CONVERT_INT64_TO_JLONG(n) (jlong)(gint64)(n)
45
46 /* To ease calcul involving nano */
47 #define BILLION 1000000000
48
49
50 #if __WORDSIZE == 64
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
55 #else
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
61 #endif
62
63 /* Structure to encapsulate java_data to pass as arguments */
64 struct java_calling_data
65 {
66 JNIEnv *env;
67 jobject jobj;
68 };
69
70 /* ***TODO***
71 All these struct are used to call g_datalist_foreach()
72 Find a better way! This is ugly!
73 */
74 struct addMarkersArgs
75 {
76 struct java_calling_data *java_args;
77 struct marker_data *mdata;
78 };
79
80 struct saveTimeArgs
81 {
82 GArray *saveTimeArray;
83 };
84
85 struct saveTimeAndTracefile
86 {
87 LttTime time;
88 LttTracefile *tracefile;
89 };
90
91 /*
92 ### COMMON Methods ###
93 #
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) {
96 }
97
98
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);
102
103 printf("%s", c_msg );
104
105 (*env)->ReleaseStringUTFChars(env, new_string, c_msg);
106 }
107
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) {
110
111 const gchar *c_pathname = (*env)->GetStringUTFChars(env, tracepath, 0);
112 jint tmpMajorNumber = 0;
113 jint tmpMinorNumber = 0;
114
115 jclass accessClass = (*env)->GetObjectClass(env, jobj);
116 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTraceVersionFromC", "(II)V");
117
118 struct LttTraceVersion version_number;
119
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;
123 }
124
125 (*env)->CallVoidMethod(env, jobj, accessFunction, tmpMajorNumber, tmpMinorNumber );
126 }
127 /*
128 #
129 #### */
130
131
132 /*
133 ### TRACE methods ###
134 #
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) {
137
138 if ( !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);
142 }
143
144 const char *c_pathname = (*env)->GetStringUTFChars(env, pathname, 0);
145 LttTrace *newPtr = ltt_trace_open( c_pathname );
146
147 (*env)->ReleaseStringUTFChars(env, pathname, c_pathname);
148
149 return CONVERT_PTR_TO_JLONG(newPtr);
150 }
151
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){
154
155 LttTrace *newPtr = (LttTrace*)CONVERT_JLONG_TO_PTR(trace_ptr);
156
157 ltt_trace_close(newPtr);
158 }
159
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);
163
164 return (*env)->NewStringUTF(env, g_quark_to_string( newPtr->pathname) );
165 }
166
167
168 /* Get of num_cpu */
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);
171
172 return (jint)newPtr->num_cpu;
173 }
174
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);
178
179 return (jlong)newPtr->arch_type;
180 }
181
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);
185
186 return (jlong)newPtr->arch_variant;
187 }
188
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);
192
193 return (jshort)newPtr->arch_size;
194 }
195
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);
199
200 return (jshort)newPtr->ltt_major_version;
201 }
202
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);
206
207 return (jshort)newPtr->ltt_minor_version;
208 }
209
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);
213
214 return (jshort)newPtr->flight_recorder;
215 }
216
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);
220
221 return (jlong)newPtr->freq_scale;
222 }
223
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);
227
228 return CONVERT_UINT64_TO_JLONG(newPtr->start_freq);
229 }
230
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);
234
235 return CONVERT_UINT64_TO_JLONG(newPtr->start_tsc);
236 }
237
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);
241
242 return CONVERT_UINT64_TO_JLONG(newPtr->start_monotonic);
243 }
244
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);
249
250 jclass accessClass = (*env)->GetObjectClass(env, time_jobj);
251 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTimeFromC", "(J)V");
252
253 jlong fullTime = (CONVERT_UINT64_TO_JLONG(newPtr->start_time.tv_sec)*BILLION) + CONVERT_UINT64_TO_JLONG(newPtr->start_time.tv_nsec);
254
255 (*env)->CallVoidMethod(env, time_jobj, accessFunction, fullTime );
256 }
257
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);
262
263 jclass accessClass = (*env)->GetObjectClass(env, time_jobj);
264 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTimeFromC", "(J)V");
265
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);
267
268 (*env)->CallVoidMethod(env, time_jobj, accessFunction, fullTime);
269 }
270
271
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;
275
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");
278
279 GArray *tracefile_array = (GArray*)data;
280 LttTracefile *tracefile;
281 jlong newPtr;
282
283 unsigned int i;
284 for (i=0; i<tracefile_array->len; i++) {
285 tracefile = &g_array_index(tracefile_array, LttTracefile, i);
286
287 newPtr = CONVERT_PTR_TO_JLONG(tracefile);
288
289 (*args->env)->CallVoidMethod(args->env, args->jobj, accessFunction, (*args->env)->NewStringUTF(args->env, g_quark_to_string(tracefile->name) ), newPtr );
290 }
291 }
292
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);
296
297 struct java_calling_data args = { env, jobj };
298
299 g_datalist_foreach(&newPtr->tracefiles, &g_datalist_foreach_addTracefilesOfTrace, &args);
300 }
301
302
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;
307
308 GArray *tracefile_array = (GArray*)data;
309 GArray *save_array = args->saveTimeArray;
310
311 LttTracefile *tracefile;
312 struct saveTimeAndTracefile *savedData;
313
314 unsigned int i;
315 for (i=0; i<tracefile_array->len; i++) {
316 tracefile = &g_array_index(tracefile_array, LttTracefile, i);
317
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);
325 }
326 }
327
328
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);
334
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);
340
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);
346
347 /* Seek back to the correct time for each tracefile and free the allocated memory */
348 struct saveTimeAndTracefile *savedData;
349 unsigned int i;
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);
356
357 /* Free the memory allocated for this saveTimeAndTracefile entry */
358 free( savedData );
359 }
360 /* Free the memory allocated for the GArray */
361 g_array_free(savedDataArray, TRUE);
362
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);
369
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);
374 }
375
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) {
378
379 LttTrace *newPtr = (LttTrace*)CONVERT_JLONG_TO_PTR(trace_ptr);
380
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);
400 printf("\n");
401 }
402 /*
403 #
404 ### */
405
406
407
408
409 /*
410 ### TRACEFILE methods ###
411 # */
412
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);
416
417 return (jboolean)newPtr->cpu_online;
418 }
419
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);
423
424 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->long_name) );
425 }
426
427 /* Get of 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);
430
431 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->name) );
432 }
433
434 /* Get of cpu_num */
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);
437
438 return (jlong)newPtr->cpu_num;
439 }
440
441 /* Get of tid */
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);
444
445 return (jlong)newPtr->tid;
446 }
447
448 /* Get of pgid */
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);
451
452 return (jlong)newPtr->pgid;
453 }
454
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);
458
459 return CONVERT_UINT64_TO_JLONG(newPtr->creation);
460 }
461
462 /* Get of trace */
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);
465
466 return CONVERT_PTR_TO_JLONG(newPtr->trace);
467 }
468
469 /* Get of mdata */
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);
472
473 return CONVERT_PTR_TO_JLONG(newPtr->mdata);
474 }
475
476 /* Get of fd */
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);
479
480 return (jint)newPtr->fd;
481 }
482
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);
486
487 return CONVERT_UINT64_TO_JLONG(newPtr->file_size);
488 }
489
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);
493
494 return (jlong)newPtr->num_blocks;
495 }
496
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);
500
501 return (jboolean)newPtr->reverse_bo;
502 }
503
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);
507
508 return (jboolean)newPtr->float_word_order;
509 }
510
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);
514
515 return CONVERT_UINT64_TO_JLONG(newPtr->alignment);
516 }
517
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);
521
522 return CONVERT_UINT64_TO_JLONG(newPtr->buffer_header_size);
523 }
524
525 /* Get of tscbits */
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);
528
529 return (jint)newPtr->tscbits;
530 }
531
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);
535
536 return (jint)newPtr->eventbits;
537 }
538
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);
542
543 return CONVERT_UINT64_TO_JLONG(newPtr->tsc_mask);
544 }
545
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);
549
550 return CONVERT_UINT64_TO_JLONG(newPtr->tsc_mask_next_bit);
551 }
552
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);
556
557 return (jlong)newPtr->events_lost;
558 }
559
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);
563
564 return (jlong)newPtr->subbuf_corrupt;
565 }
566
567 /* Get of event */
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);
570
571 return CONVERT_PTR_TO_JLONG(&newPtr->event);
572 }
573
574 /* Get of buffer */
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);
577
578 return CONVERT_PTR_TO_JLONG(&newPtr->buffer);
579 }
580
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);
584
585 return (jlong)newPtr->buf_size;
586 }
587
588
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;
593
594 jclass accessClass = (*jargs->env)->GetObjectClass(jargs->env, jargs->jobj);
595 jmethodID accessFunction = (*jargs->env)->GetMethodID(jargs->env, accessClass, "addMarkersFromC", "(IJ)V");
596
597 unsigned long marker_id = (unsigned long)data;
598
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);
602
603 (*jargs->env)->CallVoidMethod(jargs->env, jargs->jobj, accessFunction, marker_id, CONVERT_PTR_TO_JLONG(newPtr) );
604 }
605
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);
609
610 /* ***TODO***
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 };
614
615 g_hash_table_foreach( newPtr->mdata->markers_hash, &g_hash_table_foreach_addMarkersOfTracefile, &args);
616 }
617
618
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) {
621
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);
647 printf("\n");
648 }
649 /*
650 #
651 ### */
652
653
654
655 /*
656 ### EVENT methods ###
657 # */
658
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);
667
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?) */
673
674
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);
677
678 return (jint)returnedValue;
679 }
680
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);
684
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?) */
690
691
692 /* ***FIXME***
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 */
695
696 /* Save "last time" before moving, to be able to get back if needed */
697 LttTime lastTime = newPtr->event.event_time;
698
699 int returnedValue = ltt_tracefile_read(newPtr);
700
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);
704 }
705
706 return (jint)returnedValue;
707 }
708
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);
712
713 guint64 fullTime = 0;
714
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);
718
719 /* ***HACK***
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;
726
727 LttTime seekTime = { (unsigned long)seconds, (unsigned long)nanoSeconds };
728
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?) */
734
735 int returnedValue = ltt_tracefile_seek_time(newPtr, seekTime);
736 return (jint)returnedValue;
737 }
738
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);
742
743 return CONVERT_PTR_TO_JLONG(newPtr->tracefile);
744 }
745
746 /* Get of block */
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);
749
750 return (jlong)newPtr->block;
751 }
752
753 /* Get of offset */
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);
756
757 return (jlong)newPtr->offset;
758 }
759
760 /* Get of tsc */
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);
763
764 return CONVERT_UINT64_TO_JLONG(newPtr->tsc);
765 }
766
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);
770
771 return (jlong)newPtr->timestamp;
772 }
773
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);
777
778 return (jint)newPtr->event_id;
779 }
780
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);
784
785 return (CONVERT_UINT64_TO_JLONG(newPtr->event_time.tv_sec)*BILLION) + CONVERT_UINT64_TO_JLONG(newPtr->event_time.tv_nsec);
786 }
787
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);
791
792 jclass accessClass = (*env)->GetObjectClass(env, time_jobj);
793 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTimeFromC", "(J)V");
794
795 jlong fullTime = (CONVERT_UINT64_TO_JLONG(newPtr->event_time.tv_sec)*BILLION) + CONVERT_UINT64_TO_JLONG(newPtr->event_time.tv_nsec);
796
797 (*env)->CallVoidMethod(env, time_jobj, accessFunction, fullTime);
798 }
799
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);
804
805 (*env)->SetByteArrayRegion(env, dataArray, 0, (jsize)data_size, newPtr->data);
806 }
807
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);
811
812 return (jlong)newPtr->data_size;
813 }
814
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);
818
819 return (jlong)newPtr->event_size;
820 }
821
822 /* Get of count */
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);
825
826 return (jint)newPtr->count;
827 }
828
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);
832
833 return CONVERT_UINT64_TO_JLONG(newPtr->overflow_nsec);
834 }
835
836
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);
840
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 );
855 printf("\n");
856 }
857 /*
858 #
859 ### */
860
861
862 /*
863 ### MARKER method ###
864 # */
865
866 /* Get of name */
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);
869
870 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->name));
871 }
872
873 /* Get of format */
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);
876
877 return (*env)->NewStringUTF(env, newPtr->format);
878 }
879
880 /* Get of size */
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);
883
884 return (jlong)newPtr->size;
885 }
886
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);
890
891 jclass accessClass = (*env)->GetObjectClass(env, jobj);
892 jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "addMarkerFieldFromC", "(Ljava/lang/String;J)V");
893
894 GArray *field_array = (GArray*)newPtr->fields;
895 struct marker_field *field;
896 jlong marker_field_ptr;
897
898 unsigned int i;
899 for (i=0; i<field_array->len; i++) {
900 field = &g_array_index(field_array, struct marker_field, i);
901
902 marker_field_ptr = CONVERT_PTR_TO_JLONG(field);
903
904 (*env)->CallVoidMethod(env, jobj, accessFunction, (*env)->NewStringUTF(env, g_quark_to_string(field->name) ), marker_field_ptr );
905 }
906 }
907
908
909
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);
913
914 return (jshort)newPtr->largest_align;
915 }
916
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);
920
921 return (jshort)newPtr->int_size;
922 }
923
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);
927
928 return (jshort)newPtr->long_size;
929 }
930
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);
934
935 return (jshort)newPtr->pointer_size;
936 }
937
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);
941
942 return (jshort)newPtr->size_t_size;
943 }
944
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);
948
949 return (jshort)newPtr->alignment;
950 }
951
952 /* Get of next */
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);
955
956 return CONVERT_PTR_TO_JLONG(newPtr->next);
957 }
958
959
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);
963
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 );
975 printf("\n");
976 }
977 /*
978 #
979 ### */
980
981
982
983 /*
984 ### MARKERFIELD Method
985 # */
986
987 /* Get of name */
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);
990
991 return (*env)->NewStringUTF(env, g_quark_to_string(newPtr->name));
992 }
993
994 /* Get of type */
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);
997
998 return (jint)newPtr->type;
999 }
1000
1001 /* Get of offset */
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);
1004
1005 return CONVERT_UINT64_TO_JLONG(newPtr->offset);
1006 }
1007
1008 /* Get of size */
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);
1011
1012 return CONVERT_UINT64_TO_JLONG(newPtr->size);
1013 }
1014
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);
1018
1019 return CONVERT_UINT64_TO_JLONG(newPtr->alignment);
1020 }
1021
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);
1025
1026 return CONVERT_UINT64_TO_JLONG(newPtr->attributes);
1027 }
1028
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);
1032
1033 return (jint)newPtr->static_offset;
1034 }
1035
1036 /* Get of fmt */
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);
1039
1040 return (*env)->NewStringUTF(env, newPtr->fmt->str);
1041 }
1042
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);
1046
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 );
1055 printf("\n");
1056 }
1057 /*
1058 #
1059 ### */
1060
1061
1062 /*
1063 ### PARSER Method
1064 # */
1065
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);
1071
1072 jmethodID accessFunction = NULL;
1073
1074
1075 /*
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 */
1079
1080 /* ***HACK***
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,
1088 accessClass,
1089 accessFunction,
1090 javaObj,
1091 ltt_event_get_long_int(&newEventPtr, newMarkerFieldPtr)
1092 );
1093
1094 break;
1095
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");
1101 #else
1102 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addIntPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1103 #endif
1104 (*env)->CallStaticVoidMethod( env,
1105 accessClass,
1106 accessFunction,
1107 javaObj,
1108 CONVERT_PTR_TO_JLONG(ltt_event_get_long_unsigned(&newEventPtr, newMarkerFieldPtr) )
1109 );
1110 }
1111 /* Otherwise, add it as a number */
1112 else {
1113 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addLongToParsingFromC", "(Ljava/lang/Object;J)V");
1114 (*env)->CallStaticVoidMethod( env,
1115 accessClass,
1116 accessFunction,
1117 javaObj,
1118 ltt_event_get_long_unsigned(&newEventPtr, newMarkerFieldPtr)
1119 );
1120 }
1121
1122 break;
1123
1124 case LTT_TYPE_POINTER :
1125 #if __WORDSIZE == 64
1126 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addLongPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1127 #else
1128 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addIntPointerToParsingFromC", "(Ljava/lang/Object;J)V");
1129 #endif
1130 (*env)->CallStaticVoidMethod( env,
1131 accessClass,
1132 accessFunction,
1133 javaObj,
1134 CONVERT_PTR_TO_JLONG(*(GINT_TYPE_FOR_PTR*)(newEventPtr.data + newMarkerFieldPtr->offset))
1135 );
1136 break;
1137
1138 case LTT_TYPE_STRING :
1139 accessFunction = (*env)->GetStaticMethodID(env, accessClass, "addStringToParsingFromC", "(Ljava/lang/Object;Ljava/lang/String;)V");
1140 (*env)->CallStaticVoidMethod( env,
1141 accessClass,
1142 accessFunction,
1143 javaObj,
1144 (*env)->NewStringUTF(env, ltt_event_get_string(&newEventPtr, newMarkerFieldPtr) )
1145 );
1146 break;
1147
1148 case LTT_TYPE_COMPACT :
1149 case LTT_TYPE_NONE :
1150 default :
1151 printf("Warning : Unrecognized format type! Skipping! (Java_org_eclipse_linuxtools_lttng_jni_JniParser_ltt_1getParsedData)");
1152 break;
1153 }
1154
1155 }
1156 /*
1157 #
1158 ### */
This page took 0.057052 seconds and 4 git commands to generate.