Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
objectifies the Future Event Set of trace events
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 25 Jan 2016 16:07:30 +0000 (17:07 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 25 Jan 2016 20:03:25 +0000 (21:03 +0100)
That's a rather mechanical change so far, and more cleanups is needed.

16 files changed:
include/simgrid/forward.h
src/include/surf/datatypes.h
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/host_ptask_L07.cpp
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
src/surf/surf_private.h
src/surf/trace_mgr.cpp
src/surf/trace_mgr.hpp
teshsuite/surf/trace_usage/trace_usage.cpp

index 5f77905..b910d90 100644 (file)
@@ -21,10 +21,9 @@ namespace simgrid {
     class As;
     class Link;
   }
-}
-
-namespace simgrid {
-
+  namespace trace_mgr {
+    class future_evt_set;
+  }
 }
 
 typedef simgrid::s4u::Host simgrid_Host;
@@ -32,6 +31,7 @@ typedef simgrid::surf::Cpu surf_Cpu;
 typedef simgrid::surf::NetCard surf_NetCard;
 typedef simgrid::surf::As surf_As;
 typedef simgrid::surf::Link Link;
+typedef simgrid::trace_mgr::future_evt_set sg_future_evt_set;
 
 #else
 
@@ -40,13 +40,14 @@ typedef struct surf_Cpu surf_Cpu;
 typedef struct surf_NetCard surf_NetCard;
 typedef struct surf_As surf_As;
 typedef struct Link Link;
-
+typedef struct future_evt_set sg_future_evt_set;
 #endif
 
 typedef simgrid_Host* sg_host_t;
 typedef surf_Cpu *surf_cpu_t;
 typedef surf_NetCard *sg_netcard_t;
 typedef surf_As *AS_t;
+typedef sg_future_evt_set *sg_future_evt_set_t;
 
 // Types which are in fact dictelmt:
 typedef xbt_dictelm_t sg_storage_t;
index 8e704e7..7a6542b 100644 (file)
@@ -16,7 +16,6 @@ typedef struct lmm_constraint *lmm_constraint_t;
 typedef struct lmm_constraint_light *lmm_constraint_light_t;
 typedef struct lmm_system *lmm_system_t;
 
-typedef struct tmgr_fes *tmgr_fes_t;
 typedef struct tmgr_trace_iterator *tmgr_trace_iterator_t;
 
 
index 5c7bc6e..676e706 100644 (file)
@@ -123,7 +123,7 @@ void CpuCas01Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->setStateEvent(tmgr_history_add_trace(history, trace, 0.0, 0, host));
+    host->setStateEvent(future_evt_set->add_trace(trace, 0.0, 0, host));
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
@@ -133,7 +133,7 @@ void CpuCas01Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->setPowerEvent(tmgr_history_add_trace(history, trace, 0.0, 0, host));
+    host->setPowerEvent(future_evt_set->add_trace(trace, 0.0, 0, host));
   }
 }
 
@@ -154,10 +154,10 @@ CpuCas01::CpuCas01(CpuCas01Model *model, simgrid::s4u::Host *host, xbt_dynar_t s
 
   m_core = core;
   if (speedTrace)
-    p_speedEvent = tmgr_history_add_trace(history, speedTrace, 0.0, 0, this);
+    p_speedEvent = future_evt_set->add_trace(speedTrace, 0.0, 0, this);
 
   if (stateTrace)
-    p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
+    p_stateEvent = future_evt_set->add_trace(stateTrace, 0.0, 0, this);
 }
 
 CpuCas01::~CpuCas01()
index 6a1d618..1d6ea1e 100644 (file)
@@ -515,7 +515,7 @@ void CpuTiModel::addTraces()
       continue;
     }
     XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
-    cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
+    cpu->p_stateEvent = future_evt_set->add_trace(trace, 0.0, 0, cpu);
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
@@ -537,11 +537,8 @@ void CpuTiModel::addTraces()
       xbt_dynar_get_cpy(trace->s_list.event_list,
                         xbt_dynar_length(trace->s_list.event_list) - 1, &val);
       if (val.delta == 0) {
-        tmgr_trace_t empty_trace;
-        empty_trace = tmgr_empty_trace_new();
         cpu->p_speedEvent =
-            tmgr_history_add_trace(history, empty_trace,
-                                   cpu->p_availTrace->m_lastTime, 0, cpu);
+            future_evt_set->add_trace(tmgr_empty_trace_new(), cpu->p_availTrace->m_lastTime, 0, cpu);
       }
     }
   }
@@ -567,7 +564,7 @@ CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
   XBT_DEBUG("CPU create: peak=%f", m_speedPeak);
 
   if (stateTrace)
-    p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
+    p_stateEvent = future_evt_set->add_trace(stateTrace, 0.0, 0, this);
 
   if (speedTrace && xbt_dynar_length(speedTrace->s_list.event_list) > 1) {
        s_tmgr_event_t val;
@@ -575,8 +572,8 @@ CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
     xbt_dynar_get_cpy(speedTrace->s_list.event_list,
                       xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
     if (val.delta == 0) {
-      tmgr_trace_t empty_trace = tmgr_empty_trace_new();
-      p_speedEvent = tmgr_history_add_trace(history, empty_trace, p_availTrace->m_lastTime, 0, this);
+      p_speedEvent =
+          future_evt_set->add_trace(tmgr_empty_trace_new(), p_availTrace->m_lastTime, 0, this);
     }
   }
 }
index e4156e5..f5d4fe9 100644 (file)
@@ -351,7 +351,7 @@ void HostL07Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
+    host->p_stateEvent = future_evt_set->add_trace(trace, 0.0, 0, host);
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
@@ -361,7 +361,7 @@ void HostL07Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->p_speedEvent = tmgr_history_add_trace(history, trace, 0.0, 0, host);
+    host->p_speedEvent = future_evt_set->add_trace(trace, 0.0, 0, host);
   }
 
   /* Connect traces relative to network */
@@ -372,7 +372,7 @@ void HostL07Model::addTraces()
     xbt_assert(link, "Link %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_stateEvent = future_evt_set->add_trace(trace, 0.0, 0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
@@ -382,7 +382,7 @@ void HostL07Model::addTraces()
     xbt_assert(link, "Link %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    link->p_bwEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_bwEvent = future_evt_set->add_trace(trace, 0.0, 0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
@@ -392,7 +392,7 @@ void HostL07Model::addTraces()
     xbt_assert(link, "Link %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_latEvent = future_evt_set->add_trace(trace, 0.0, 0, link);
   }
 }
 
@@ -410,12 +410,12 @@ CpuL07::CpuL07(CpuL07Model *model, simgrid::s4u::Host *host,
   p_constraint = lmm_constraint_new(model->getMaxminSystem(), this, xbt_dynar_get_as(speedPeakList,pstate,double) * speedScale);
 
   if (speedTrace)
-    p_speedEvent = tmgr_history_add_trace(history, speedTrace, 0.0, 0, this);
+    p_speedEvent = future_evt_set->add_trace(speedTrace, 0.0, 0, this);
   else
     p_speedEvent = NULL;
 
   if (state_trace)
-       p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
+       p_stateEvent = future_evt_set->add_trace(state_trace, 0.0, 0, this);
 }
 
 CpuL07::~CpuL07()
@@ -430,11 +430,11 @@ LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
                         int initiallyOn,
                         tmgr_trace_t state_trace,
                         e_surf_link_sharing_policy_t policy)
- : Link(model, name, props, lmm_constraint_new(model->getMaxminSystem(), this, bw_initial), history, state_trace)
+ : Link(model, name, props, lmm_constraint_new(model->getMaxminSystem(), this, bw_initial), future_evt_set, state_trace)
 {
   m_bwCurrent = bw_initial;
   if (bw_trace)
-    p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, this);
+    p_bwEvent = future_evt_set->add_trace(bw_trace, 0.0, 0, this);
 
   if (initiallyOn)
     turnOn();
@@ -443,7 +443,7 @@ LinkL07::LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
   m_latCurrent = lat_initial;
 
   if (lat_trace)
-       p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, this);
+    p_latEvent = future_evt_set->add_trace(lat_trace, 0.0, 0, this);
 
   if (policy == SURF_LINK_FATPIPE)
        lmm_constraint_shared(getConstraint());
index 1432ccd..503bf1b 100644 (file)
@@ -209,7 +209,7 @@ Link* NetworkCm02Model::createLink(const char *name,
              "Link '%s' declared several times in the platform",
              name);
 
-  Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
+  Link* link = new NetworkCm02Link(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, future_evt_set,
                                             initiallyOn, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
   Link::onCreation(link);
   return link;
@@ -479,7 +479,7 @@ void NetworkCm02Model::addTraces(){
                "Cannot connect trace %s to link %s: trace undefined",
                trace_name, elm);
 
-    link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_stateEvent = future_evt_set->add_trace(trace, 0.0, 0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
@@ -492,7 +492,7 @@ void NetworkCm02Model::addTraces(){
                "Cannot connect trace %s to link %s: trace undefined",
                trace_name, elm);
 
-    link->p_speed.event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_speed.event = future_evt_set->add_trace(trace, 0.0, 0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
@@ -505,7 +505,7 @@ void NetworkCm02Model::addTraces(){
                "Cannot connect trace %s to link %s: trace undefined",
                trace_name, elm);
 
-    link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->p_latEvent = future_evt_set->add_trace(trace, 0.0, 0, link);
   }
 }
 
@@ -515,7 +515,7 @@ void NetworkCm02Model::addTraces(){
 NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props,
                                   lmm_system_t system,
                                   double constraint_value,
-                                  tmgr_fes_t history,
+                                  sg_future_evt_set_t fes,
                                   int initiallyOn,
                                   tmgr_trace_t state_trace,
                                   double metric_peak,
@@ -523,7 +523,7 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_
                                   double lat_initial,
                                   tmgr_trace_t lat_trace,
                                   e_surf_link_sharing_policy_t policy)
-: Link(model, name, props, lmm_constraint_new(system, this, constraint_value), history, state_trace)
+: Link(model, name, props, lmm_constraint_new(system, this, constraint_value), fes, state_trace)
 {
   if (initiallyOn)
     turnOn();
@@ -533,13 +533,13 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_
   p_speed.scale = 1.0;
   p_speed.peak = metric_peak;
   if (metric_trace)
-    p_speed.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, this);
+    p_speed.event = fes->add_trace(metric_trace, 0.0, 0, this);
   else
     p_speed.event = NULL;
 
   m_latCurrent = lat_initial;
   if (lat_trace)
-       p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, this);
+       p_latEvent = fes->add_trace(lat_trace, 0.0, 0, this);
 
   if (policy == SURF_LINK_FATPIPE)
        lmm_constraint_shared(getConstraint());
index c9f3e1c..a7f479e 100644 (file)
@@ -75,7 +75,7 @@ public:
   NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_dict_t props,
                                   lmm_system_t system,
                                   double constraint_value,
-                                  tmgr_fes_t history,
+                                  sg_future_evt_set_t fes,
                                   int initiallyOn,
                                   tmgr_trace_t state_trace,
                                   double metric_peak,
index 321c0d8..323652b 100644 (file)
@@ -201,13 +201,13 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop
 
 Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props,
                                 lmm_constraint_t constraint,
-                            tmgr_fes_t history,
+                          sg_future_evt_set_t fes,
                             tmgr_trace_t state_trace)
 : Resource(model, name, constraint),
   PropertyHolder(props)
 {
   if (state_trace)
-    p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
+    p_stateEvent = fes->add_trace(state_trace, 0.0, 0, this);
 
   links->insert({name, this});
   XBT_DEBUG("Create link '%s'",name);
index 16f4ef7..5e26f23 100644 (file)
@@ -185,12 +185,12 @@ public:
    * @param name The name of the Link
    * @param props Dictionary of properties associated to this Link
    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
-   * @param history [TODO]
+   * @param fes Future Event Set in which our events must be registered
    * @param state_trace [TODO]
    */
   Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props,
               lmm_constraint_t constraint,
-              tmgr_fes_t history,
+              sg_future_evt_set_t fes,
               tmgr_trace_t state_trace);
 
   /* Link destruction logic */
index 74b5554..ea95db4 100644 (file)
@@ -38,11 +38,10 @@ void surf_presolve(void)
   unsigned int iter;
 
   XBT_DEBUG ("Consume all trace events occurring before the starting time.");
-  while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
+  while ((next_event_date = future_evt_set->next_date()) != -1.0) {
     if (next_event_date > NOW)
       break;
-    while ((event =
-            tmgr_history_get_next_event_leq(history, next_event_date,
+    while ((event = future_evt_set->pop_leq(next_event_date,
                                             &value,
                                             (void **) &resource))) {
       if (value >= 0){
@@ -94,7 +93,7 @@ double surf_solve(double max_date)
   do {
     XBT_DEBUG("Next TRACE event : %f", next_event_date);
 
-    next_event_date = tmgr_history_next_date(history);
+    next_event_date = future_evt_set->next_date();
 
     if(! surf_network_model->shareResourcesIsIdempotent()){ // NS3, I see you
       if(next_event_date!=-1.0 && surf_min!=-1.0) {
@@ -120,8 +119,7 @@ double surf_solve(double max_date)
     if ((surf_min == -1.0) || (next_event_date > NOW + surf_min)) break;
 
     XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", surf_min, NOW, next_event_date);
-    while ((event =
-            tmgr_history_get_next_event_leq(history, next_event_date,
+    while ((event = future_evt_set->pop_leq(next_event_date,
                                             &value,
                                             (void **) &resource))) {
       if (resource->isUsed() || xbt_dict_get_or_null(watched_hosts_lib, resource->getName())) {
index 9dfbe99..c782e81 100644 (file)
@@ -29,7 +29,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf,
 xbt_dynar_t all_existing_models = NULL; /* to destroy models correctly */
 xbt_dynar_t model_list_invoke = NULL;  /* to invoke callbacks */
 
-tmgr_fes_t history = NULL;
+sg_future_evt_set_t future_evt_set = nullptr;
 xbt_dynar_t surf_path = NULL;
 xbt_dynar_t host_that_restart = NULL;
 xbt_dict_t watched_hosts_lib;
@@ -327,8 +327,8 @@ void surf_init(int *argc, char **argv)
     all_existing_models = xbt_dynar_new(sizeof(simgrid::surf::Model*), NULL);
   if (!model_list_invoke)
     model_list_invoke = xbt_dynar_new(sizeof(simgrid::surf::Model*), NULL);
-  if (!history)
-    history = tmgr_history_new();
+  if (!future_evt_set)
+    future_evt_set = new simgrid::trace_mgr::future_evt_set();
 
   TRACE_add_start_function(TRACE_surf_alloc);
   TRACE_add_end_function(TRACE_surf_release);
@@ -368,9 +368,9 @@ void surf_exit(void)
 
   simgrid::surf::surfExitCallbacks();
 
-  if (history) {
-    tmgr_history_free(history);
-    history = NULL;
+  if (future_evt_set) {
+    delete future_evt_set;
+    future_evt_set = nullptr;
   }
 
 #ifdef CONTEXT_THREADS
index 3644497..3ca6f61 100644 (file)
@@ -25,7 +25,7 @@
 #include "src/surf/trace_mgr.hpp"
 #include "src/internal_config.h"
 
-extern XBT_PRIVATE tmgr_fes_t history;
+extern XBT_PRIVATE sg_future_evt_set_t future_evt_set;
 #define NO_MAX_DURATION -1.0
 
 /*********
index f094f38..fd5d0c1 100644 (file)
@@ -42,8 +42,6 @@ typedef enum {
 
 XBT_PRIVATE FILE *surf_fopen(const char *name, const char *mode);
 
-extern XBT_PRIVATE tmgr_fes_t history;
-
 /* The __surf_is_absolute_file_path() returns 1 if
  * file_path is a absolute file path, in the other
  * case the function returns 0.
index f3cf2ef..79a6e06 100644 (file)
@@ -17,21 +17,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management");
 
 static xbt_dict_t trace_list = NULL;
 
-tmgr_fes_t tmgr_history_new(void)
-{
-  tmgr_fes_t h;
-
-  h = xbt_new0(s_tmgr_history_t, 1);
-
-  h->heap = xbt_heap_new(8, xbt_free_f);        /* Why 8 ? Well, why not... */
-
-  return h;
+simgrid::trace_mgr::future_evt_set::future_evt_set() {
 }
 
-void tmgr_history_free(tmgr_fes_t h)
+simgrid::trace_mgr::future_evt_set::~future_evt_set()
 {
-  xbt_heap_free(h->heap);
-  free(h);
+  xbt_heap_free(p_heap);
 }
 
 
@@ -381,10 +372,11 @@ void tmgr_trace_free(tmgr_trace_t trace)
   free(trace);
 }
 
-tmgr_trace_iterator_t tmgr_history_add_trace(tmgr_fes_t h,
-                                          tmgr_trace_t trace,
-                                          double start_time,
-                                          unsigned int offset, void *resource)
+tmgr_trace_iterator_t simgrid::trace_mgr::future_evt_set::add_trace(
+    tmgr_trace_t trace,
+    double start_time,
+    unsigned int offset,
+    void *resource)
 {
   tmgr_trace_iterator_t trace_iterator = NULL;
 
@@ -398,25 +390,25 @@ tmgr_trace_iterator_t tmgr_history_add_trace(tmgr_fes_t h,
               "You're referring to an event that does not exist!");
   }
 
-  xbt_heap_push(h->heap, trace_iterator, start_time);
+  xbt_heap_push(p_heap, trace_iterator, start_time);
 
   return trace_iterator;
 }
 
-double tmgr_history_next_date(tmgr_fes_t h)
+double simgrid::trace_mgr::future_evt_set::next_date()
 {
-  if (xbt_heap_size(h->heap))
-    return (xbt_heap_maxkey(h->heap));
+  if (xbt_heap_size(p_heap))
+    return (xbt_heap_maxkey(p_heap));
   else
     return -1.0;
 }
 
-tmgr_trace_iterator_t tmgr_history_get_next_event_leq(tmgr_fes_t h,
-                                                   double date,
-                                                   double *value,
-                                                   void** resource)
+tmgr_trace_iterator_t simgrid::trace_mgr::future_evt_set::pop_leq(
+    double date,
+    double *value,
+    void** resource)
 {
-  double event_date = tmgr_history_next_date(h);
+  double event_date = next_date();
   tmgr_trace_iterator_t trace_iterator = NULL;
   tmgr_event_t event = NULL;
   tmgr_trace_t trace = NULL;
@@ -425,7 +417,7 @@ tmgr_trace_iterator_t tmgr_history_get_next_event_leq(tmgr_fes_t h,
   if (event_date > date)
     return NULL;
 
-  if (!(trace_iterator = (tmgr_trace_iterator_t)xbt_heap_pop(h->heap)))
+  if (!(trace_iterator = (tmgr_trace_iterator_t)xbt_heap_pop(p_heap)))
     return NULL;
 
   trace = trace_iterator->trace;
@@ -439,10 +431,10 @@ tmgr_trace_iterator_t tmgr_history_get_next_event_leq(tmgr_fes_t h,
       *value = event->value;
 
       if (trace_iterator->idx < xbt_dynar_length(trace->s_list.event_list) - 1) {
-        xbt_heap_push(h->heap, trace_iterator, event_date + event->delta);
+        xbt_heap_push(p_heap, trace_iterator, event_date + event->delta);
         trace_iterator->idx++;
       } else if (event->delta > 0) {        /* Last element, checking for periodicity */
-        xbt_heap_push(h->heap, trace_iterator, event_date + event->delta);
+        xbt_heap_push(p_heap, trace_iterator, event_date + event->delta);
         trace_iterator->idx = 1; /* not 0 as the first event is a placeholder to handle when events really start */
       } else {                      /* We don't need this trace_event anymore */
         trace_iterator->free_me = 1;
@@ -465,7 +457,7 @@ tmgr_trace_iterator_t tmgr_history_get_next_event_leq(tmgr_fes_t h,
         event_delta = tmgr_event_generator_next_value(trace->s_probabilist.event_generator[0]);
         *value = tmgr_event_generator_next_value(trace->s_probabilist.event_generator[1]);
       }
-      xbt_heap_push(h->heap, trace_iterator, event_date + event_delta);
+      xbt_heap_push(p_heap, trace_iterator, event_date + event_delta);
       XBT_DEBUG("Generating a new event at date %f, with value %f", event_date + event_delta, *value);
 
       break;
index 1c42547..617c6bd 100644 (file)
@@ -12,6 +12,7 @@
 #include "surf/maxmin.h"
 #include "surf/datatypes.h"
 #include "simgrid/platf_interface.h"
+#include "simgrid/forward.h"
 
 SG_BEGIN_DECL()
 #include "xbt/base.h"
@@ -74,18 +75,9 @@ typedef struct tmgr_trace_iterator {
   int free_me;
 } s_tmgr_trace_event_t;
 
-/* Future Event Set (collection of iterators over the traces)
- * That's useful to quickly know which is the next occurring event in a set of traces. */
-typedef struct tmgr_fes {
-  xbt_heap_t heap; /* Content: only trace_events */
-} s_tmgr_history_t;
-
 XBT_PRIVATE double tmgr_event_generator_next_value(probabilist_event_generator_t generator);
 
 /* Creation functions */
-XBT_PUBLIC(tmgr_fes_t) tmgr_history_new(void);
-XBT_PUBLIC(void) tmgr_history_free(tmgr_fes_t history);
-
 XBT_PUBLIC(tmgr_trace_t) tmgr_empty_trace_new(void);
 XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace);
 /**
@@ -97,21 +89,34 @@ XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace);
 */
 XBT_PUBLIC(int) tmgr_trace_event_free(tmgr_trace_iterator_t trace_event);
 
-XBT_PUBLIC(tmgr_trace_iterator_t) tmgr_history_add_trace(tmgr_fes_t
-                                                      history,
-                                                      tmgr_trace_t trace,
-                                                      double start_time,
-                                                      unsigned int offset,
-                                                      void *model);
-
-/* Access functions */
-XBT_PUBLIC(double) tmgr_history_next_date(tmgr_fes_t history);
-XBT_PUBLIC(tmgr_trace_iterator_t)
-    tmgr_history_get_next_event_leq(tmgr_fes_t history, double date,
-                                double *value, void **model);
-
 XBT_PUBLIC(void) tmgr_finalize(void);
 
 SG_END_DECL()
 
+#ifdef __cplusplus
+namespace simgrid {
+  namespace trace_mgr {
+
+/* Future Event Set (collection of iterators over the traces)
+ * That's useful to quickly know which is the next occurring event in a set of traces. */
+XBT_PUBLIC_CLASS future_evt_set {
+public:
+  future_evt_set();
+  virtual ~future_evt_set();
+  double next_date();
+  tmgr_trace_iterator_t pop_leq(double date, double *value, void** resource);
+  tmgr_trace_iterator_t add_trace(
+      tmgr_trace_t trace,
+      double start_time,
+      unsigned int offset,
+      void *model);
+
+private:
+  // TODO: use a boost type for the heap (or a ladder queue)
+  xbt_heap_t p_heap = xbt_heap_new(8, xbt_free_f); /* Content: only trace_events (yep, 8 is an arbitrary value) */
+};
+
+}} // namespace simgrid::trace_mgr
+#endif /* C++ only */
+
 #endif                          /* _SURF_TMGR_H */
index 34005e4..595d649 100644 (file)
@@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
 
 static void test(void)
 {
-  tmgr_fes_t history = tmgr_history_new();
+  simgrid::trace_mgr::future_evt_set *fes = new simgrid::trace_mgr::future_evt_set();
   tmgr_trace_t trace_A = tmgr_trace_new_from_file("trace_A.txt");
   tmgr_trace_t trace_B = tmgr_trace_new_from_file("trace_B.txt");
   double next_event_date = -1.0;
@@ -29,20 +29,19 @@ static void test(void)
   char *host_A = strdup("Host A");
   char *host_B = strdup("Host B");
 
-  tmgr_history_add_trace(history, trace_A, 1.0, 2, host_A);
-  tmgr_history_add_trace(history, trace_B, 0.0, 0, host_B);
+  fes->add_trace(trace_A, 1.0, 2, host_A);
+  fes->add_trace(trace_B, 0.0, 0, host_B);
 
-  while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
+  while ((next_event_date = fes->next_date()) != -1.0) {
     XBT_DEBUG("%g" " : \n", next_event_date);
-    while (tmgr_history_get_next_event_leq(history, next_event_date,
-                                           &value, (void **) &resource)) {
+    while (fes->pop_leq(next_event_date, &value, (void **) &resource)) {
       XBT_DEBUG("\t %s : " "%g" "\n", resource, value);
     }
     if (next_event_date > 1000)
       break;
   }
 
-  tmgr_history_free(history);
+  delete fes;
   free(host_B);
   free(host_A);
 }