removed X on tabs, because would need style hack : too long
[lttv.git] / ltt / branches / poly / ltt / tracefile.c
index ee77b7af2188c82c0b08c288f76626cd6006c1dc..225f7eacfe67d95026361b75a311ce6af0380994 100644 (file)
@@ -1,3 +1,21 @@
+/* This file is part of the Linux Trace Toolkit viewer
+ * Copyright (C) 2003-2004 Xiangxiu Yang
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
+ * MA 02111-1307, USA.
+ */
+
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -5,6 +23,11 @@
 #include <dirent.h>
 #include <linux/errno.h>  
 
+// For realpath
+#include <limits.h>
+#include <stdlib.h>
+
+
 #include "parser.h"
 #include <ltt/ltt.h>
 #include "ltt-private.h"
@@ -349,7 +372,8 @@ void getCpuFileInfo(LttTrace *t, char* cpu)
 
   while((entry = readdir(dir)) != NULL){
     if(strcmp(entry->d_name,".") != 0 &&
-       strcmp(entry->d_name,"..") != 0 ){
+       strcmp(entry->d_name,"..") != 0 &&
+       strcmp(entry->d_name,".svn") != 0){      
       strcpy(name,cpu);
       strcat(name,entry->d_name);
       ltt_tracefile_open_cpu(t,name);
@@ -366,8 +390,8 @@ void getCpuFileInfo(LttTrace *t, char* cpu)
  *When a trace is closed, all the associated facilities, types and fields
  *are released as well.
  *
- * MD : If pathname is already absolute, we do not add current working
- * directory to it.
+ * MD : Fixed this function so it uses realpath, dealing well with
+ * forgotten cases (.. were not used correctly before).
  *
  ****************************************************************************/
 
@@ -377,27 +401,17 @@ void get_absolute_pathname(const char *pathname, char * abs_pathname)
   size_t size = DIR_NAME_SIZE;
   abs_pathname[0] = '\0';
 
-       if(pathname[0] == '/')
-       {
-    strcat(abs_pathname, pathname);
-               return;
-       }
-
-  if(!getcwd(abs_pathname, size)){
-    g_warning("Can not get current working directory\n");
-    strcat(abs_pathname, pathname);
+  if ( realpath (pathname, abs_pathname) != NULL)
+    return;
+  else
+  {
+    // FIXME : Path is wrong, is it ok to return the pathname unmodified ?
+    strcpy(abs_pathname, pathname);
     return;
   }
 
-  strcat(abs_pathname,"/");
+  return;
   
-  ptr = (char*)pathname;
-  ptr1 = ptr + 1;
-  while(*ptr == '.' && *ptr1 == '.'){
-    ptr += 3;
-    ptr1 = ptr + 1;
-  }
-  strcat(abs_pathname,ptr);
 }
 
 LttTrace *ltt_trace_open(const char *pathname)
@@ -413,7 +427,6 @@ LttTrace *ltt_trace_open(const char *pathname)
   gboolean has_slash = FALSE;
 
   get_absolute_pathname(pathname, abs_path);
-  
   //establish the pathname to different directories
   if(abs_path[strlen(abs_path)-1] == '/')has_slash = TRUE;
   strcpy(eventdefs,abs_path);
@@ -890,7 +903,7 @@ void ltt_tracefile_seek_time(LttTracefile *t, LttTime time)
  * Seek to the first event with position equal or larger to ep 
  ****************************************************************************/
 
-void ltt_tracefile_seek_position(LttTracefile *t, LttEventPosition *ep)
+void ltt_tracefile_seek_position(LttTracefile *t, const LttEventPosition *ep)
 {
   //if we are at the right place, just return
   if(t->which_block == ep->block_num && t->which_event == ep->event_num)
@@ -943,6 +956,7 @@ LttEvent *ltt_tracefile_read(LttTracefile *t)
 
   lttEvent->time_delta = *(guint32 *)(t->cur_event_pos + EVENT_ID_SIZE);
   lttEvent->event_time = t->current_event_time;
+  lttEvent->event_cycle_count = t->cur_cycle_count;
 
   lttEvent->tracefile = t;
   lttEvent->data = t->cur_event_pos + EVENT_HEADER_SIZE;  
@@ -953,8 +967,6 @@ LttEvent *ltt_tracefile_read(LttTracefile *t)
   err = skipEvent(t);
   if(err == ERANGE) g_error("event id is out of range\n");
 
-  lttEvent->event_cycle_count = t->cur_cycle_count;
-
   return lttEvent;
 }
 
@@ -1142,10 +1154,10 @@ LttTime getEventTime(LttTracefile * tf)
   LttTime       time;
   LttCycleCount cycle_count;      // cycle count for the current event
   LttCycleCount lEventTotalCycle; // Total cycles from start for event
-  double        lEventNSec;       // Total usecs from start for event
+  LttCycleCount lEventNSec;       // Total usecs from start for event
   LttTime       lTimeOffset;      // Time offset in struct LttTime
   guint16       evId;
-  gint64        nanoSec, tmpCycleCount = (((guint64)1)<<32);
+  LttCycleCount tmpCycleCount = (((LttCycleCount)1)<<32);
 
   evId = *(guint16 *)tf->cur_event_pos;
   if(evId == TRACE_BLOCK_START){
@@ -1167,8 +1179,8 @@ LttTime getEventTime(LttTracefile * tf)
   tf->pre_cycle_count = cycle_count;
   cycle_count += tmpCycleCount * tf->count;  
   
-  if(tf->cur_heart_beat_number > tf->count)
-    cycle_count += tmpCycleCount * (tf->cur_heart_beat_number - tf->count);  
+  //  if(tf->cur_heart_beat_number > tf->count)
+  //    cycle_count += tmpCycleCount * (tf->cur_heart_beat_number - tf->count);  
 
   tf->cur_cycle_count = cycle_count;
 
@@ -1176,12 +1188,11 @@ LttTime getEventTime(LttTracefile * tf)
   lEventTotalCycle -= tf->a_block_start->cycle_count;
 
   // Convert it to nsecs
-  lEventNSec = lEventTotalCycle / tf->cycle_per_nsec;
-  nanoSec    = lEventNSec;
+  lEventNSec = (double)lEventTotalCycle / (double)tf->cycle_per_nsec;
 
   // Determine offset in struct LttTime 
-  lTimeOffset.tv_nsec = nanoSec % NANOSECONDS_PER_SECOND;
-  lTimeOffset.tv_sec  = nanoSec / NANOSECONDS_PER_SECOND;
+  lTimeOffset.tv_nsec = lEventNSec % NANOSECONDS_PER_SECOND;
+  lTimeOffset.tv_sec  = lEventNSec / NANOSECONDS_PER_SECOND;
 
   time = ltt_time_add(tf->a_block_start->time, lTimeOffset);  
   
This page took 0.02526 seconds and 4 git commands to generate.