Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further s/trace/profile/ cleanups
[simgrid.git] / src / surf / trace_mgr.cpp
index d5e70c1..d84999c 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2004-2005, 2007, 2009-2014, 2016-2017. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -10,7 +9,6 @@
 #include "src/surf/surf_interface.hpp"
 #include "src/surf/trace_mgr.hpp"
 #include "surf_private.hpp"
-#include "xbt/RngStream.h"
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string/join.hpp>
 #include <boost/algorithm/string/split.hpp>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management");
 
-namespace tmgr = simgrid::trace_mgr;
-
-static std::unordered_map<std::string, tmgr::trace*> trace_list;
+static std::unordered_map<std::string, simgrid::kernel::profile::Profile*> trace_list;
 
 static inline bool doubleEq(double d1, double d2)
 {
   return fabs(d1 - d2) < 0.0001;
 }
 namespace simgrid {
-namespace trace_mgr {
+namespace kernel {
+namespace profile {
 
 bool DatedValue::operator==(DatedValue e2)
 {
@@ -42,36 +39,37 @@ std::ostream& operator<<(std::ostream& out, const DatedValue& e)
   return out;
 }
 
-trace::trace()
+Profile::Profile()
 {
   /* Add the first fake event storing the time at which the trace begins */
-  tmgr::DatedValue val(0, -1);
+  DatedValue val(0, -1);
   event_list.push_back(val);
 }
-trace::~trace()                  = default;
-future_evt_set::future_evt_set() = default;
-future_evt_set::~future_evt_set()
+Profile::~Profile()          = default;
+FutureEvtSet::FutureEvtSet() = default;
+FutureEvtSet::~FutureEvtSet()
 {
   while (not heap_.empty()) {
     delete heap_.top().second;
     heap_.pop();
   }
 }
-}
-}
+} // namespace profile
+} // namespace kernel
+} // namespace simgrid
 
-tmgr_trace_t tmgr_trace_new_from_string(std::string name, std::string input, double periodicity)
+simgrid::kernel::profile::Profile* tmgr_trace_new_from_string(std::string name, std::string input, double periodicity)
 {
   int linecount = 0;
-  tmgr_trace_t trace           = new simgrid::trace_mgr::trace();
-  tmgr::DatedValue* last_event = &(trace->event_list.back());
+  simgrid::kernel::profile::Profile* trace         = new simgrid::kernel::profile::Profile();
+  simgrid::kernel::profile::DatedValue* last_event = &(trace->event_list.back());
 
   xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name.c_str());
 
   std::vector<std::string> list;
   boost::split(list, input, boost::is_any_of("\n\r"));
   for (auto val : list) {
-    tmgr::DatedValue event;
+    simgrid::kernel::profile::DatedValue event;
     linecount++;
     boost::trim(val);
     if (val[0] == '#' || val[0] == '\0' || val[0] == '%') // pass comments
@@ -105,7 +103,7 @@ tmgr_trace_t tmgr_trace_new_from_string(std::string name, std::string input, dou
   return trace;
 }
 
-tmgr_trace_t tmgr_trace_new_from_file(std::string filename)
+simgrid::kernel::profile::Profile* tmgr_trace_new_from_file(std::string filename)
 {
   xbt_assert(not filename.empty(), "Cannot parse a trace from an empty filename");
   xbt_assert(trace_list.find(filename) == trace_list.end(), "Refusing to define trace %s twice", filename.c_str());
@@ -119,34 +117,34 @@ tmgr_trace_t tmgr_trace_new_from_file(std::string filename)
 
   return tmgr_trace_new_from_string(filename, buffer.str(), -1);
 }
+namespace simgrid {
+namespace kernel {
+namespace profile {
 
 /** @brief Registers a new trace into the future event set, and get an iterator over the integrated trace  */
-tmgr_trace_event_t simgrid::trace_mgr::future_evt_set::add_trace(tmgr_trace_t trace, surf::Resource* resource)
+Event* FutureEvtSet::add_trace(Profile* profile, resource::Resource* resource)
 {
-  tmgr_trace_event_t trace_iterator = nullptr;
-
-  trace_iterator           = new s_tmgr_trace_event_t;
-  trace_iterator->trace    = trace;
-  trace_iterator->idx      = 0;
-  trace_iterator->resource = resource;
-  trace_iterator->free_me  = false;
+  Event* event    = new Event();
+  event->profile  = profile;
+  event->idx      = 0;
+  event->resource = resource;
+  event->free_me  = false;
 
-  xbt_assert((trace_iterator->idx < trace->event_list.size()), "Your trace should have at least one event!");
+  xbt_assert((event->idx < profile->event_list.size()), "Your profile should have at least one event!");
 
-  heap_.emplace(0.0 /* start time */, trace_iterator);
+  heap_.emplace(0.0 /* start time */, event);
 
-  return trace_iterator;
+  return event;
 }
 
-/** @brief returns the date of the next occurring event (pure function) */
-double simgrid::trace_mgr::future_evt_set::next_date() const
+/** @brief returns the date of the next occurring event */
+double FutureEvtSet::next_date() const
 {
   return heap_.empty() ? -1.0 : heap_.top().first;
 }
 
-/** @brief Retrieves the next occurring event, or nullptr if none happens before #date */
-tmgr_trace_event_t simgrid::trace_mgr::future_evt_set::pop_leq(double date, double* value,
-                                                               simgrid::surf::Resource** resource)
+/** @brief Retrieves the next occurring event, or nullptr if none happens before date */
+Event* FutureEvtSet::pop_leq(double date, double* value, resource::Resource** resource)
 {
   double event_date = next_date();
   if (event_date > date)
@@ -154,29 +152,31 @@ tmgr_trace_event_t simgrid::trace_mgr::future_evt_set::pop_leq(double date, doub
 
   if (heap_.empty())
     return nullptr;
-  tmgr_trace_event_t trace_iterator = heap_.top().second;
+  Event* event = heap_.top().second;
   heap_.pop();
 
-  tmgr_trace_t trace = trace_iterator->trace;
-  *resource = trace_iterator->resource;
+  Profile* profile = event->profile;
+  *resource        = event->resource;
 
-  tmgr::DatedValue dateVal = trace->event_list.at(trace_iterator->idx);
+  DatedValue dateVal = profile->event_list.at(event->idx);
 
   *value = dateVal.value_;
 
-  if (trace_iterator->idx < trace->event_list.size() - 1) {
-    heap_.emplace(event_date + dateVal.date_, trace_iterator);
-    trace_iterator->idx++;
+  if (event->idx < profile->event_list.size() - 1) {
+    heap_.emplace(event_date + dateVal.date_, event);
+    event->idx++;
   } else if (dateVal.date_ > 0) { /* Last element. Shall we loop? */
-    heap_.emplace(event_date + dateVal.date_, trace_iterator);
-    trace_iterator->idx = 1; /* idx=0 is a placeholder to store when events really start */
-  } else {                   /* If we don't loop, we don't need this trace_event anymore */
-    trace_iterator->free_me = true;
+    heap_.emplace(event_date + dateVal.date_, event);
+    event->idx = 1; /* idx=0 is a placeholder to store when events really start */
+  } else {          /* If we don't loop, we don't need this event anymore */
+    event->free_me = true;
   }
 
-  return trace_iterator;
+  return event;
 }
-
+} // namespace profile
+} // namespace kernel
+} // namespace simgrid
 void tmgr_finalize()
 {
   for (auto const& kv : trace_list)
@@ -184,10 +184,10 @@ void tmgr_finalize()
   trace_list.clear();
 }
 
-void tmgr_trace_event_unref(tmgr_trace_event_t* trace_event)
+void tmgr_trace_event_unref(simgrid::kernel::profile::Event** event)
 {
-  if ((*trace_event)->free_me) {
-    delete *trace_event;
-    *trace_event = nullptr;
+  if ((*event)->free_me) {
+    delete *event;
+    *event = nullptr;
   }
 }