ltt_trace_read with external LttEvent
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 30 Jul 2004 15:11:25 +0000 (15:11 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 30 Jul 2004 15:11:25 +0000 (15:11 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@649 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/ltt/event.c
ltt/branches/poly/ltt/event.h
ltt/branches/poly/ltt/ltt-private.h
ltt/branches/poly/ltt/ltt.h
ltt/branches/poly/ltt/trace.h
ltt/branches/poly/ltt/tracefile.c

index d83c62c043a4d87bf8abfcfd3accd1db07d43bca..1c2140ef983c9f45b21f0b44ea44271cf8e3e5b5 100644 (file)
 #include <ltt/event.h>
 #include <ltt/trace.h>
 
+
+LttEvent *ltt_event_new()
+{
+  return g_new(LttEvent, 1);
+}
+
+void ltt_event_destroy(LttEvent *event)
+{
+  g_free(event);
+}
+
+
 /*****************************************************************************
  *Function name
  *    ltt_event_refresh_fields   : refresh fields of an event 
index 2b2eab2222bd673a76c2e6307b2193f6c9be5334..c3500120b8b49ba8bc01fd15dc9c05e554d093f2 100644 (file)
 
 #include <ltt/ltt.h>
 
+LttEvent *ltt_event_new();
+
+void ltt_event_destroy(LttEvent *event);
+
 /* Events and their content, including the raw data, are only valid 
    until reading another event from the same tracefile. 
    Indeed, since event reading is critical to the performance, 
    the memory associated with an event may be reused at each read. */
 
-
 /* Obtain the trace unique integer id associated with the type of 
    this event */
 
index f0c0d9572e72748a70bb70401f875c38ea8569d8..6e9e3e48af80d22659573a730675a6fbfed15bfd 100644 (file)
@@ -83,6 +83,26 @@ struct _LttEventType{
   int latest_event;       //the latest event using the event type
 };
 
+struct _LttEvent{
+  guint16  event_id;
+  guint32  time_delta;
+  LttTime event_time;
+  LttCycleCount event_cycle_count;
+  LttTracefile * tracefile;
+  void * data;               //event data
+  int which_block;           //the current block of the event
+  int which_event;           //the position of the event
+  /* This is a workaround for fast position seek */
+  void * last_event_pos;
+
+  LttTime prev_block_end_time;       //the end time of previous block
+  LttTime prev_event_time;           //the time of the previous event
+  LttCycleCount pre_cycle_count;     //previous cycle count of the event
+  int      count;                    //the number of overflow of cycle count
+  /* end of workaround */
+};
+
+
 struct _LttField{
   unsigned field_pos;        //field position within its parent
   LttType * field_type;      //field type, if it is root field
@@ -114,24 +134,6 @@ struct _LttField{
   unsigned current_element;  //which element is currently processed
 };
 
-struct _LttEvent{
-  guint16  event_id;
-  guint32  time_delta;
-  LttTime event_time;
-  LttCycleCount event_cycle_count;
-  LttTracefile * tracefile;
-  void * data;               //event data
-  int which_block;           //the current block of the event
-  int which_event;           //the position of the event
-  /* This is a workaround for fast position seek */
-  void * last_event_pos;
-
-  LttTime prev_block_end_time;       //the end time of previous block
-  LttTime prev_event_time;           //the time of the previous event
-  LttCycleCount pre_cycle_count;     //previous cycle count of the event
-  int      count;                    //the number of overflow of cycle count
-  /* end of workaround */
-};
 
 struct _LttFacility{
   char * name;               //facility name 
@@ -165,7 +167,6 @@ struct _LttTracefile{
 
   LttTime prev_block_end_time;       //the end time of previous block
   LttTime prev_event_time;           //the time of the previous event
-  LttEvent an_event;
   LttCycleCount pre_cycle_count;     //previous cycle count of the event
   int      count;                    //the number of overflow of cycle count
 };
@@ -199,7 +200,6 @@ struct _LttEventPosition{
 
   LttTime prev_block_end_time;       //the end time of previous block
   LttTime prev_event_time;           //the time of the previous event
-  LttEvent an_event;
   LttCycleCount pre_cycle_count;     //previous cycle count of the event
   int      count;                    //the number of overflow of cycle count
   /* end of workaround */
index c83ed6528d7ba6a789dd93395acef8c92edefef4..021173f966b2eae28d0976e9a31c6bf20e7c6227 100644 (file)
@@ -82,6 +82,7 @@ typedef struct _LttEvent LttEvent;
 
 typedef struct _LttSystemDescription LttSystemDescription;
 
+
 /* Checksums are used to differentiate facilities which have the same name
    but differ. */
 
index 05ed31eb508bad3863b8cac1cddad9f348d906c4..03f47694183a7f3f23b6054b21cddc677ca7058f 100644 (file)
@@ -127,7 +127,7 @@ void ltt_tracefile_seek_position(LttTracefile *t,
 
 /* Read the next event */
 
-LttEvent *ltt_tracefile_read(LttTracefile *t);
+LttEvent *ltt_tracefile_read(LttTracefile *t, LttEvent *event);
 
 /* open tracefile */
 
index cd44542031274802a76749b213fa1c2e399e2ce3..980512b65390c3b2abd6ee804bcae2f01e54de56 100644 (file)
@@ -21,7 +21,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <dirent.h>
-#include <linux/errno.h>  
+#include <linux/errno.h>
 
 // For realpath
 #include <limits.h>
@@ -33,6 +33,7 @@
 #include "ltt-private.h"
 #include <ltt/trace.h>
 #include <ltt/facility.h>
+#include <ltt/event.h>
 
 #define DIR_NAME_SIZE 256
 
@@ -221,7 +222,7 @@ void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name)
 gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
 {
   LttTracefile * tf;
-  LttEvent ev;
+  LttEvent ev;
   LttFacility * f;
   guint16 evId;
   void * pos;
@@ -239,11 +240,10 @@ gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
   //parse facilities tracefile to get base_id
   if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){
     while(1){
-      ev = ltt_tracefile_read(tf);
-      if(!ev)return 0; // end of file
+      if(!ltt_tracefile_read(tf,&ev)) return 0; // end of file
 
-      if(ev->event_id == TRACE_FACILITY_LOAD){
-       pos = ev->data;
+      if(ev.event_id == TRACE_FACILITY_LOAD){
+       pos = ev.data;
        fLoad.name = (char*)pos;
        fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
        fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
@@ -260,9 +260,9 @@ gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
                  fLoad.name,fLoad.checksum);
     return -1;
   }
-      }else if(ev->event_id == TRACE_BLOCK_START){
+      }else if(ev.event_id == TRACE_BLOCK_START){
        continue;
-      }else if(ev->event_id == TRACE_BLOCK_END){
+      }else if(ev.event_id == TRACE_BLOCK_END){
        break;
       }else {
         g_warning("Not valid facilities trace file\n");
@@ -807,8 +807,8 @@ void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end)
     if(ltt_time_compare(endBig,endTmp) < 0) endBig = endTmp;
   }
 
-  *start = startSmall;
-  *end = endBig;
+  if(start != NULL) *start = startSmall;
+  if(end != NULL) *end = endBig;
 }
 
 
@@ -916,7 +916,7 @@ void ltt_tracefile_seek_time(LttTracefile *t, LttTime time)
   LttTime lttTime;
   int headTime = ltt_time_compare(t->a_block_start->time, time);
   int tailTime = ltt_time_compare(t->a_block_end->time, time);
-  LttEvent ev;
+  LttEvent ev;
 
   if(headTime < 0 && tailTime > 0){
     if(ltt_time_compare(t->a_block_end->time, t->current_event_time) !=0) {
@@ -931,8 +931,7 @@ void ltt_tracefile_seek_time(LttTracefile *t, LttTime time)
        }
       }else if(err < 0){
        while(1){
-         ev = ltt_tracefile_read(t);
-         if(ev == NULL){
+         if(ltt_tracefile_read(t,&ev) == NULL) {
            g_print("End of file\n");      
            return;
          }
@@ -1021,7 +1020,8 @@ void ltt_tracefile_seek_position(LttTracefile *t, const LttEventPosition *ep)
   //MD: warning : this is slow!
   g_warning("using slow O(n) tracefile seek position");
 
-  while(t->which_event < ep->event_num) ltt_tracefile_read(t);
+  LttEvent event;
+  while(t->which_event < ep->event_num) ltt_tracefile_read(t, &event);
 
   return;
 }
@@ -1035,9 +1035,8 @@ void ltt_tracefile_seek_position(LttTracefile *t, const LttEventPosition *ep)
  *    LttEvent *        : an event to be processed
  ****************************************************************************/
 
-LttEvent *ltt_tracefile_read(LttTracefile *t)
+LttEvent *ltt_tracefile_read(LttTracefile *t, LttEvent *event)
 {
-  LttEvent * lttEvent = &t->an_event;
   int err;
 
   if(t->cur_event_pos == t->buffer + t->block_size){
@@ -1048,28 +1047,28 @@ LttEvent *ltt_tracefile_read(LttTracefile *t)
     if(err)g_error("Can not read tracefile");    
   }
 
-  lttEvent->event_id = (int)(*(guint16 *)(t->cur_event_pos));
-  if(lttEvent->event_id == TRACE_TIME_HEARTBEAT)
+  event->event_id = (int)(*(guint16 *)(t->cur_event_pos));
+  if(event->event_id == TRACE_TIME_HEARTBEAT)
     t->cur_heart_beat_number++;
 
   t->prev_event_time  = t->current_event_time;
   //  t->current_event_time = getEventTime(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;
+  event->time_delta = *(guint32 *)(t->cur_event_pos + EVENT_ID_SIZE);
+  event->event_time = t->current_event_time;
+  event->event_cycle_count = t->cur_cycle_count;
 
-  lttEvent->tracefile = t;
-  lttEvent->data = t->cur_event_pos + EVENT_HEADER_SIZE;  
-  lttEvent->which_block = t->which_block;
-  lttEvent->which_event = t->which_event;
+  event->tracefile = t;
+  event->data = t->cur_event_pos + EVENT_HEADER_SIZE;  
+  event->which_block = t->which_block;
+  event->which_event = t->which_event;
 
   /* This is a workaround for fast position seek */
-  lttEvent->last_event_pos = t->last_event_pos;
-  lttEvent->prev_block_end_time = t->prev_block_end_time;
-  lttEvent->prev_event_time = t->prev_event_time;
-  lttEvent->pre_cycle_count = t->pre_cycle_count;
-  lttEvent->count = t->count;
+  event->last_event_pos = t->last_event_pos;
+  event->prev_block_end_time = t->prev_block_end_time;
+  event->prev_event_time = t->prev_event_time;
+  event->pre_cycle_count = t->pre_cycle_count;
+  event->count = t->count;
   /* end of workaround */
 
 
@@ -1078,7 +1077,7 @@ LttEvent *ltt_tracefile_read(LttTracefile *t)
   err = skipEvent(t);
   if(err == ERANGE) g_error("event id is out of range\n");
 
-  return lttEvent;
+  return event;
 }
 
 /****************************************************************************
This page took 0.029282 seconds and 4 git commands to generate.