Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Modify structures to support different sources of avaibility trace
[simgrid.git] / src / surf / trace_mgr.c
index 03827df..c42d11d 100644 (file)
@@ -46,16 +46,17 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
   if (trace_list) {
     trace = xbt_dict_get_or_null(trace_list, id);
     if (trace) {
-      WARN1("Ignoring redefinition of trace %s", id);
+      XBT_WARN("Ignoring redefinition of trace %s", id);
       return trace;
     }
   }
 
-  xbt_assert1(periodicity >= 0,
+  xbt_assert(periodicity >= 0,
               "Invalid periodicity %lg (must be positive)", periodicity);
 
   trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
+  trace->type = e_trace_list;
+  trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
 
   list = xbt_str_split(input, "\n\r");
 
@@ -69,38 +70,36 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
       continue;
 
     if (sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) != 2)
-      xbt_die(bprintf
-              ("%s:%d: Syntax error in trace\n%s", id, linecount, input));
+      xbt_die("%s:%d: Syntax error in trace\n%s", id, linecount, input);
 
     if (last_event) {
       if (last_event->delta > event.delta) {
-        xbt_die(bprintf
-                ("%s:%d: Invalid trace: Events must be sorted, but time %lg > time %lg.\n%s",
-                 id, linecount, last_event->delta, event.delta, input));
+        xbt_die("%s:%d: Invalid trace: Events must be sorted, "
+                "but time %lg > time %lg.\n%s",
+                id, linecount, last_event->delta, event.delta, input);
       }
       last_event->delta = event.delta - last_event->delta;
     }
-    xbt_dynar_push(trace->event_list, &event);
+    xbt_dynar_push(trace->s_list.event_list, &event);
     last_event =
-      xbt_dynar_get_ptr(trace->event_list,
-                        xbt_dynar_length(trace->event_list) - 1);
+        xbt_dynar_get_ptr(trace->s_list.event_list,
+                          xbt_dynar_length(trace->s_list.event_list) - 1);
   }
   if (last_event)
     last_event->delta = periodicity;
 
   if (!trace_list)
-    trace_list = xbt_dict_new();
+    trace_list = xbt_dict_new_homogeneous((void (*)(void *)) tmgr_trace_free);
 
-  xbt_dict_set(trace_list, id, (void *) trace,
-               (void (*)(void *)) tmgr_trace_free);
+  xbt_dict_set(trace_list, id, (void *) trace, NULL);
 
   xbt_dynar_free(&list);
   return trace;
 }
 
-tmgr_trace_t tmgr_trace_new(const char *filename)
+tmgr_trace_t tmgr_trace_new_from_file(const char *filename)
 {
-       char *tstr = NULL;
+  char *tstr = NULL;
   FILE *f = NULL;
   tmgr_trace_t trace = NULL;
 
@@ -110,14 +109,14 @@ tmgr_trace_t tmgr_trace_new(const char *filename)
   if (trace_list) {
     trace = xbt_dict_get_or_null(trace_list, filename);
     if (trace) {
-      WARN1("Ignoring redefinition of trace %s", filename);
+      XBT_WARN("Ignoring redefinition of trace %s", filename);
       return trace;
     }
   }
 
   f = surf_fopen(filename, "r");
-  xbt_assert2(f!=NULL, "Cannot open file '%s' (path=%s)", filename,
-       xbt_str_join(surf_path,":"));
+  xbt_assert(f != NULL, "Cannot open file '%s' (path=%s)", filename,
+              xbt_str_join(surf_path, ":"));
 
   tstr = xbt_str_from_file(f);
   fclose(f);
@@ -133,11 +132,11 @@ tmgr_trace_t tmgr_empty_trace_new(void)
   s_tmgr_event_t event;
 
   trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
+  trace->s_list.event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
 
   event.delta = 0.0;
   event.value = 0.0;
-  xbt_dynar_push(trace->event_list, &event);
+  xbt_dynar_push(trace->s_list.event_list, &event);
 
   return trace;
 }
@@ -146,7 +145,7 @@ XBT_INLINE void tmgr_trace_free(tmgr_trace_t trace)
 {
   if (!trace)
     return;
-  xbt_dynar_free(&(trace->event_list));
+  xbt_dynar_free(&(trace->s_list.event_list));
   free(trace);
 }
 
@@ -162,7 +161,7 @@ tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t h,
   trace_event->idx = offset;
   trace_event->model = model;
 
-  xbt_assert0((trace_event->idx < xbt_dynar_length(trace->event_list)),
+  xbt_assert((trace_event->idx < xbt_dynar_length(trace->s_list.event_list)),
               "You're referring to an event that does not exist!");
 
   xbt_heap_push(h->heap, trace_event, start_time);
@@ -195,12 +194,12 @@ tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t h,
     return NULL;
 
   trace = trace_event->trace;
-  event = xbt_dynar_get_ptr(trace->event_list, trace_event->idx);
+  event = xbt_dynar_get_ptr(trace->s_list.event_list, trace_event->idx);
 
   *value = event->value;
   *model = trace_event->model;
 
-  if (trace_event->idx < xbt_dynar_length(trace->event_list) - 1) {
+  if (trace_event->idx < xbt_dynar_length(trace->s_list.event_list) - 1) {
     xbt_heap_push(h->heap, trace_event, event_date + event->delta);
     trace_event->idx++;
   } else if (event->delta > 0) {        /* Last element, checking for periodicity */