fix event count in state.c
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / lttvwindowtraces.c
index 1ce869990fe2e10ee69ad30f18e4b7773daf913d..56bf076d8740857d377d042b0f7457c32147903d 100644 (file)
 
 /* Here is the implementation of the API */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <string.h>
 
 #include <ltt/time.h>
 #include <ltt/trace.h>
@@ -65,7 +70,6 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace);
 
 LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path)
 {
-  LttvAttribute *attribute = lttv_global_attributes();
   guint i;
 
   for(i=0;i<lttvwindowtraces_get_number();i++) {
@@ -76,7 +80,7 @@ LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path)
 
     trace = lttv_trace(trace_v);
     g_assert(trace != NULL);
-    name = ltt_trace_name(trace);
+    name = g_quark_to_string(ltt_trace_name(trace));
 
     if(strcmp(name, path) == 0) {
       /* Found */
@@ -136,13 +140,13 @@ void lttvwindowtraces_add_trace(LttvTrace *trace)
   struct stat buf;
   gchar attribute_path[PATH_MAX];
 
-  if(stat(ltt_trace_name(lttv_trace(trace)), &buf)) {
+  if(stat(g_quark_to_string(ltt_trace_name(lttv_trace(trace))), &buf)) {
     g_warning("lttvwindowtraces_add_trace: Trace %s not found",
-        ltt_trace_name(lttv_trace(trace)));
+        g_quark_to_string(ltt_trace_name(lttv_trace(trace))));
     return;
   }
   g_assert(
-      snprintf(attribute_path, PATH_MAX, "%lu:%lu", buf.st_dev, buf.st_ino) >= 0);
+      snprintf(attribute_path, PATH_MAX, "%llu:%llu", buf.st_dev, buf.st_ino) >= 0);
   
   g_assert(attribute = 
       LTTV_ATTRIBUTE(lttv_iattribute_find_subdir(LTTV_IATTRIBUTE(g_attribute),
@@ -157,6 +161,7 @@ void lttvwindowtraces_add_trace(LttvTrace *trace)
   /* create new traceset and tracesetcontext */
   LttvTraceset *ts;
   LttvTracesetStats *tss;
+  LttvTracesetContextPosition *sync_position;
   
   attribute = lttv_trace_attribute(trace);
   g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
@@ -177,6 +182,14 @@ void lttvwindowtraces_add_trace(LttvTrace *trace)
   
   lttv_context_init(LTTV_TRACESET_CONTEXT(tss), ts);
 
+  g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(attribute),
+                                LTTV_COMPUTATION_SYNC_POSITION,
+                                LTTV_POINTER,
+                                &value));
+
+  sync_position = lttv_traceset_context_position_new();
+  *(value.v_pointer) = sync_position;
+
   value = lttv_attribute_add(attribute,
                      LTTV_REQUESTS_QUEUE,
                      LTTV_POINTER);
@@ -220,9 +233,10 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace)
       /* Found */
       LttvAttribute *l_attribute;
 
-      /* create new traceset and tracesetcontext */
+      /* destroy traceset and tracesetcontext */
       LttvTraceset *ts;
       LttvTracesetStats *tss;
+      LttvTracesetContextPosition *sync_position;
       
       l_attribute = lttv_trace_attribute(trace);
 
@@ -245,6 +259,17 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace)
                                     &value));
       ts = (LttvTraceset*)*(value.v_pointer);
      
+      g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute),
+                                    LTTV_COMPUTATION_SYNC_POSITION,
+                                    LTTV_POINTER,
+                                    &value));
+      sync_position = (LttvTracesetContextPosition*)*(value.v_pointer);
+
+      lttv_traceset_context_position_destroy(sync_position);
+      
+      lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
+                                     LTTV_COMPUTATION_SYNC_POSITION);
+
       g_assert(lttv_iattribute_find(LTTV_IATTRIBUTE(l_attribute),
                                     LTTV_COMPUTATION_TRACESET_CONTEXT,
                                     LTTV_POINTER,
@@ -255,9 +280,10 @@ void lttvwindowtraces_remove_trace(LttvTrace *trace)
       g_object_unref(tss);
       lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
                                      LTTV_COMPUTATION_TRACESET_CONTEXT);
-      lttv_traceset_destroy(ts);
       lttv_iattribute_remove_by_name(LTTV_IATTRIBUTE(l_attribute),
                                      LTTV_COMPUTATION_TRACESET);
+      /* Destroy the traceset and the trace also */
+      lttv_traceset_destroy(ts);
 
       /* finally, remove the global attribute */
       lttv_attribute_remove(attribute, i);
@@ -548,7 +574,8 @@ void lttvwindowtraces_background_notify_remove(gpointer owner)
 /* Background processing helper functions */
 
 void lttvwindowtraces_add_computation_hooks(LttvAttributeName module_name,
-                                            LttvTracesetContext *tsc)
+                                            LttvTracesetContext *tsc,
+                                            LttvHooks *hook_adder)
 {
   LttvAttribute *g_attribute = lttv_global_attributes();
   LttvAttribute *module_attribute;
@@ -611,7 +638,9 @@ void lttvwindowtraces_add_computation_hooks(LttvAttributeName module_name,
                                      LTTV_HOOK_ADDER,
                                      &value);
   if(type == LTTV_POINTER) {
-    lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss);
+    //lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss);
+    if(hook_adder != NULL)
+      lttv_hooks_add_list(hook_adder, (LttvHooks*)*(value.v_pointer));
   }
 
 
@@ -626,7 +655,8 @@ void lttvwindowtraces_add_computation_hooks(LttvAttributeName module_name,
 }
                                             
 void lttvwindowtraces_remove_computation_hooks(LttvAttributeName module_name,
-                                               LttvTracesetContext *tsc)
+                                               LttvTracesetContext *tsc,
+                                               LttvHooks *hook_remover)
 {
   LttvAttribute *g_attribute = lttv_global_attributes();
   LttvAttribute *module_attribute;
@@ -695,7 +725,9 @@ void lttvwindowtraces_remove_computation_hooks(LttvAttributeName module_name,
                                      LTTV_HOOK_REMOVER,
                                      &value);
   if(type == LTTV_POINTER) {
-    lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss);
+    //lttv_hooks_call((LttvHooks*)*(value.v_pointer), (gpointer)tss);
+    if(hook_remover != NULL)
+      lttv_hooks_add_list(hook_remover, (LttvHooks*)*(value.v_pointer));
   }
 }
 
@@ -816,13 +848,13 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
   LttvTracesetContext *tsc;
   LttvTracesetStats *tss;
   LttvTraceset *ts;
+  LttvTracesetContextPosition *sync_position;
   LttvAttribute *attribute;
   LttvAttribute *g_attribute = lttv_global_attributes();
   GSList **list_out, **list_in, **notify_in, **notify_out;
   LttvAttributeValue value;
   LttvAttributeType type;
   gboolean ret_val;
-  LttvHooks *before_request, *after_request;
 
   if(trace == NULL)
     return FALSE;
@@ -867,10 +899,15 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
   tss = (LttvTracesetStats*)*(value.v_pointer);
   g_assert(LTTV_IS_TRACESET_CONTEXT(tsc));
   g_assert(LTTV_IS_TRACESET_STATS(tss));
+  
+  type = lttv_iattribute_get_by_name(LTTV_IATTRIBUTE(attribute),
+                                     LTTV_COMPUTATION_SYNC_POSITION,
+                                     &value);
+  g_assert(type == LTTV_POINTER);
+  sync_position = (LttvTracesetContextPosition*)*(value.v_pointer);
  
   /* There is no events requests pending : we should never have been called! */
   g_assert(g_slist_length(*list_out) != 0 || g_slist_length(*list_in) != 0);
-
   /* 0.1 Lock traces */
   {
     guint iter_trace=0;
@@ -886,8 +923,8 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
     }
   }
   /* 0.2 Sync tracefiles */
-  lttv_process_traceset_synchronize_tracefiles(tsc);
-
+  g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0);
+ // lttv_process_traceset_synchronize_tracefiles(tsc);
   /* 1. Before processing */
   {
     /* if list_in is empty */
@@ -950,7 +987,6 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
                                              &value);
           g_assert(type == LTTV_POINTER);
           LttvHooks *before_request = (LttvHooks*)*(value.v_pointer);
-
  
           if(before_request != NULL) lttv_hooks_call(before_request, tsc);
           
@@ -997,6 +1033,7 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
 
     {
       GSList *iter = *list_in;
+      LttvHooks *hook_adder = lttv_hooks_new();
       /* - for each request in list_in */
       while(iter != NULL) {
         
@@ -1004,16 +1041,19 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
         /*- Call before chunk hooks for list_in*/
         /*- add hooks to context*/
         lttvwindowtraces_add_computation_hooks(bg_req->module_name,
-                                               tsc);
+                                               tsc,
+                                               hook_adder);
         iter = g_slist_next(iter);
       }
+      lttv_hooks_call(hook_adder,tsc);
+      lttv_hooks_destroy(hook_adder);
     }
   }
 
   /* 2. call process traceset middle for a chunk */
   {
     /*(assert list_in is not empty! : should not even be called in that case)*/
-    LttTime end = { G_MAXUINT, G_MAXUINT };
+    LttTime end = ltt_time_infinite;
     g_assert(g_slist_length(*list_in) != 0);
     
     lttv_process_traceset_middle(tsc, end, CHUNK_NUM_EVENTS, NULL);
@@ -1024,6 +1064,7 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
     /*  3.1 call after_chunk hooks for list_in */
     {
       GSList *iter = *list_in;
+      LttvHooks *hook_remover = lttv_hooks_new();
       /* - for each request in list_in */
       while(iter != NULL) {
         
@@ -1031,9 +1072,12 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
         /* - Call after chunk hooks for list_in */
         /* - remove hooks from context */
         lttvwindowtraces_remove_computation_hooks(bg_req->module_name,
-                                                  tsc);
+                                                  tsc,
+                                                  hook_remover);
         iter = g_slist_next(iter);
       }
+      lttv_hooks_call(hook_remover,tsc);
+      lttv_hooks_destroy(hook_remover);
     }
 
     /* 3.2 for each notify_in */
@@ -1174,6 +1218,11 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
             }
           }
         }
+        {
+          /* - reset the context */
+          LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->fini(tsc);
+          LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->init(tsc,ts);
+        }
         /* - if list_out is empty */
         if(g_slist_length(*list_out) == 0) {
           /* - return FALSE (scheduler stopped) */
@@ -1194,7 +1243,8 @@ gboolean lttvwindowtraces_process_pending_requests(LttvTrace *trace)
   }
   /* 4. Unlock traces */
   {
-    //lttv_process_traceset_get_sync_data(tsc);
+ //   lttv_process_traceset_get_sync_data(tsc);
+    lttv_traceset_context_position_save(tsc, sync_position);
     guint iter_trace;
     
     for(iter_trace=0; 
This page took 0.026985 seconds and 4 git commands to generate.