Merged changes needed by JNI in latest LTTv version
authorWilliam Bourque <william.bourque@polymtl.ca>
Fri, 16 Apr 2010 18:04:45 +0000 (14:04 -0400)
committerWilliam Bourque <william.bourque@polymtl.ca>
Fri, 16 Apr 2010 18:04:45 +0000 (14:04 -0400)
ltt/Makefile.am
ltt/jni_interface.c
ltt/trace.h
ltt/tracefile.c
specs/lttv.spec

index f503e633975c5a048181cda2eff64b009b66d542..641bb4c7f2333210680d9756cbaa9d4d6225ca77 100644 (file)
@@ -8,14 +8,18 @@
 
 AM_CFLAGS = $(PACKAGE_CFLAGS)
 
-lib_LTLIBRARIES = liblttvtraceread.la
-
 if BUILD_JNI_INTERFACE
+lib_LTLIBRARIES = liblttvtraceread.la liblttvtraceread_loader.la
 liblttvtraceread_la_SOURCES = jni_interface.c tracefile.c marker.c event.c
+liblttvtraceread_loader_la_SOURCES= lttvtraceread_loader.c
 else
+lib_LTLIBRARIES = liblttvtraceread.la
 liblttvtraceread_la_SOURCES = tracefile.c marker.c event.c
 endif
 
+liblttvtraceread_la_LDFLAGS = -release 2.6
+liblttvtraceread_loader_la_LDFLAGS = -release 2.6
+
 noinst_HEADERS = ltt-private.h
 
 lttinclude_HEADERS = \
index aac5a21045be5a4d98b087082ee988f675a9d706..8238599e6e09e7f2d81fb46db5d76be3697c3607 100644 (file)
@@ -109,6 +109,27 @@ JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_Jni_1C_1Common_ltt_
 #### */
 
 
+
+JNIEXPORT void JNICALL Java_org_eclipse_linuxtools_lttng_jni_factory_JniTraceVersion_ltt_1getTraceVersion(JNIEnv *env, jobject jobj, jstring tracepath) {
+        
+        const gchar *c_pathname = (*env)->GetStringUTFChars(env, tracepath, 0);
+        jint tmpMajorNumber = 0;
+        jint tmpMinorNumber = 0;
+        
+        jclass accessClass = (*env)->GetObjectClass(env, jobj);
+        jmethodID accessFunction = (*env)->GetMethodID(env, accessClass, "setTraceVersionFromC", "(II)V");
+        
+        struct LttTraceVersion version_number;
+        
+        if ( ltt_get_trace_version(c_pathname, &version_number) >= 0) {
+                tmpMajorNumber = version_number.ltt_major_version;
+                tmpMinorNumber = version_number.ltt_minor_version;
+        }
+        
+        (*env)->CallVoidMethod(env, jobj, accessFunction, tmpMajorNumber, tmpMinorNumber );
+}
+
+
 /* 
 ### TRACE methods ###
 #
index 7d7d712299e862f1951bc06b850237092d95451e..e16c66f29f43ca44f5d317322f003788cdcb4488 100644 (file)
@@ -216,4 +216,13 @@ LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc);
 /* Set to enable event debugging output */
 void ltt_event_debug(int state);
 
+/* A structure representing the version number of the trace */
+struct LttTraceVersion {
+  guint8    ltt_major_version;
+  guint8    ltt_minor_version;
+};
+
+/* To get the version number of a trace */
+int ltt_get_trace_version(const gchar *pathname, struct LttTraceVersion * version_number);
+
 #endif // TRACE_H
index c206b0466e06147e53597f48fb608af5280095c9..6c36deed45839e2dafc382487c1b566f7b595c85 100644 (file)
@@ -1790,3 +1790,138 @@ static __attribute__((constructor)) void init(void)
 {
   LTT_TRACEFILE_NAME_METADATA = g_quark_from_string("metadata");
 }
+
+/*****************************************************************************
+ *Function name
+ *    ltt_tracefile_open_header    : based on ltt_tracefile_open but it stops
+ *                                  when it gets the header                                    
+ *Input params 
+ *    fileName       : path to the tracefile
+ *    tf             : the tracefile (metadata_0) where the header will be read
+ *Return value
+ *    ltt_subbuffer_header_t         : the header containing the version number
+ ****************************************************************************/
+static ltt_subbuffer_header_t * ltt_tracefile_open_header(gchar *fileName, LttTracefile *tf)
+{
+        struct stat    lTDFStat;    /* Trace data file status */
+        ltt_subbuffer_header_t *header;
+        int page_size = getpagesize();
+        
+        /* open the file */
+        tf->long_name = g_quark_from_string(fileName);
+        tf->fd = open(fileName, O_RDONLY);
+        if(tf->fd < 0){
+                g_warning("Unable to open input data file %s\n", fileName);
+                goto end;
+        }
+        
+        /* Get the file's status */ 
+        if(fstat(tf->fd, &lTDFStat) < 0){
+                g_warning("Unable to get the status of the input data file %s\n", fileName);
+                goto close_file;
+        }
+        
+        /* Is the file large enough to contain a trace */
+        if(lTDFStat.st_size < (off_t)(ltt_subbuffer_header_size())) {
+                g_print("The input data file %s does not contain a trace\n", fileName);
+                goto close_file;
+        }
+        
+        /* Temporarily map the buffer start header to get trace information */
+        /* Multiple of pages aligned head */
+        tf->buffer.head = mmap(0,PAGE_ALIGN(ltt_subbuffer_header_size()), PROT_READ, MAP_PRIVATE, tf->fd, 0);
+        
+        if(tf->buffer.head == MAP_FAILED) {
+                perror("Error in allocating memory for buffer of tracefile");
+                goto close_file;
+        }
+        g_assert( ( (gulong)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
+        
+        header = (ltt_subbuffer_header_t *)tf->buffer.head;
+        
+        return header;
+        
+        close_file:
+                close(tf->fd);
+        end:
+                return 0;
+}
+
+
+/*****************************************************************************
+ *Function name
+ *    get_version    : get the trace version from a metadata_0 trace file
+ *Input params 
+ *    pathname       : path to the trace
+ *    version_number  : the struct that will get the version number
+ *Return value
+ *    int         : 1 if succeed, -1 if error
+ ****************************************************************************/
+int ltt_get_trace_version(const gchar *pathname, struct LttTraceVersion *version_number) 
+{
+       gchar abs_path[PATH_MAX];
+       int ret = 0;
+       DIR *dir;
+       struct dirent *entry;
+       struct stat stat_buf;
+       gchar path[PATH_MAX];
+       
+       LttTracefile tmp_tf;
+       LttTrace  * t;
+       ltt_subbuffer_header_t *header;
+       
+       t = g_new(LttTrace, 1);
+         
+       get_absolute_pathname(pathname, abs_path);
+        
+       /* Test to see if it looks like a trace */
+       dir = opendir(abs_path);
+       
+       if(dir == NULL) {
+               perror(abs_path);
+               goto open_error;
+       }
+       
+       while((entry = readdir(dir)) != NULL) {
+               strcpy(path, abs_path);
+               strcat(path, "/");
+               strcat(path, entry->d_name);
+               ret = stat(path, &stat_buf);
+               if(ret == -1) {
+                       perror(path);
+                       continue;
+               }
+       }
+       
+       closedir(dir);  
+       dir = opendir(abs_path);
+        
+       while((entry = readdir(dir)) != NULL) {
+               if(entry->d_name[0] == '.') continue;
+               if(g_strcmp0(entry->d_name, "metadata_0") != 0) continue;
+               
+               strcpy(path, abs_path);
+               strcat(path, "/");
+               strcat(path, entry->d_name);
+               if(ret == -1) {
+                       perror(path);
+                       continue;
+               }
+               
+               header = ltt_tracefile_open_header(path, &tmp_tf);
+               
+               if(header == NULL) {
+                       g_info("Error getting the header %s", path);
+                       continue; /* error opening the tracefile : bad magic number ? */
+               }
+                       
+               version_number->ltt_major_version = header->major_version;
+               version_number->ltt_minor_version = header->minor_version;
+       }
+       
+       return 0;
+       
+       open_error:
+                g_free(t);
+                return -1;
+}
index 31852770178981e3375e6badf90c40509c72a287..a6226b9a6ef4523a0c90a0d18cb16c5adc058cf3 100644 (file)
@@ -48,8 +48,11 @@ echo "Running ldconfig (might take a while)"
 ldconfig
 
 %files
-%{libdir}/liblttvtraceread.so.0.0.0
-%{libdir}/liblttvtraceread.so.0
+%{libdir}/liblttvtraceread_loader-2.6.so
+%{libdir}/liblttvtraceread_loader.so
+%{libdir}/liblttvtraceread_loader.la
+%{libdir}/liblttvtraceread_loader.a
+%{libdir}/liblttvtraceread-2.6.so
 %{libdir}/liblttvtraceread.so
 %{libdir}/liblttvtraceread.la
 %{libdir}/liblttvtraceread.a
This page took 0.028498 seconds and 4 git commands to generate.