Removing whitespace/align errors
[lttv.git] / ltt / tracefile.c
index 9cd130558e67392cf96c9e024f2bee7928b4e6ab..21188917fe3773eb493610201cc94e545b5f8f4f 100644 (file)
@@ -764,11 +764,6 @@ LttTrace *ltt_trace_open(const gchar *pathname)
   get_absolute_pathname(pathname, abs_path);
   t->pathname = g_quark_from_string(abs_path);
 
-  t->start_tsc = 0;
-  t->freq_scale = 1;
-  t->start_freq = 1;
-  t->start_time_from_tsc = ltt_time_zero;
-
   g_datalist_init(&t->tracefiles);
 
   /* Test to see if it looks like a trace */
@@ -790,6 +785,7 @@ LttTrace *ltt_trace_open(const gchar *pathname)
   closedir(dir);
   
   /* Open all the tracefiles */
+  t->start_freq= 0;
   if(open_tracefiles(t, abs_path, "")) {
     g_warning("Error opening tracefile %s", abs_path);
     goto find_error;
@@ -889,6 +885,8 @@ void ltt_tracefile_time_span_get(LttTracefile *tf,
     *end = ltt_time_zero;
   } else
     *end = tf->buffer.end.timestamp;
+
+  g_assert(end->tv_sec <= G_MAXUINT);
 }
 
 struct tracefile_time_span_get_args {
@@ -1389,22 +1387,24 @@ static gint map_block(LttTracefile * tf, guint block_num)
 
   tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
                                               &header->cycle_count_begin);
-  tf->buffer.begin.freq = tf->trace->start_freq;
-
-  tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf, 
-                                          tf->buffer.begin.cycle_count);
   tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
                                               &header->cycle_count_end);
-  tf->buffer.end.freq = tf->trace->start_freq;
-  
   tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf),
                                         &header->lost_size);
-  tf->buffer.end.timestamp = ltt_interpolate_time_from_tsc(tf,
-                                        tf->buffer.end.cycle_count);
   tf->buffer.tsc =  tf->buffer.begin.cycle_count;
   tf->event.tsc = tf->buffer.tsc;
   tf->buffer.freq = tf->buffer.begin.freq;
 
+  if (tf->trace->start_freq)
+  {
+    tf->buffer.begin.freq = tf->trace->start_freq;
+    tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf,
+      tf->buffer.begin.cycle_count);
+    tf->buffer.end.freq = tf->trace->start_freq;
+    tf->buffer.end.timestamp = ltt_interpolate_time_from_tsc(tf,
+      tf->buffer.end.cycle_count);
+  }
+
   /* FIXME
    * eventually support variable buffer size : will need a partial pre-read of
    * the headers to create an index when we open the trace... eventually. */
@@ -1729,3 +1729,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;
+}
This page took 0.025092 seconds and 4 git commands to generate.