Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
profile: cosmetics: inline a function and rename a variable
[simgrid.git] / src / kernel / resource / profile / trace_mgr.cpp
index c7091a0..151f1f1 100644 (file)
 #include <sstream>
 #include <unordered_map>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(profile, resource, "Surf profile management");
 
 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 kernel {
 namespace profile {
 
 bool DatedValue::operator==(DatedValue const& e2) const
 {
-  return (doubleEq(date_, e2.date_)) && (doubleEq(value_, e2.value_));
+  return (fabs(date_ - e2.date_) < 0.0001) && (fabs(value_ - e2.value_) < 0.0001);
 }
 std::ostream& operator<<(std::ostream& out, const DatedValue& e)
 {
@@ -45,23 +41,11 @@ Profile::Profile()
   event_list.push_back(val);
 }
 Profile::~Profile()          = default;
-FutureEvtSet::FutureEvtSet() = default;
-FutureEvtSet::~FutureEvtSet()
-{
-  while (not heap_.empty()) {
-    delete heap_.top().second;
-    heap_.pop();
-  }
-}
-} // namespace profile
-} // namespace kernel
-} // namespace simgrid
-
-simgrid::kernel::profile::Profile* tmgr_trace_new_from_string(std::string name, std::string input, double periodicity)
+Profile* Profile::from_string(std::string name, std::string input, double periodicity)
 {
   int linecount                                    = 0;
-  simgrid::kernel::profile::Profile* trace         = new simgrid::kernel::profile::Profile();
-  simgrid::kernel::profile::DatedValue* last_event = &(trace->event_list.back());
+  simgrid::kernel::profile::Profile* profile       = new simgrid::kernel::profile::Profile();
+  simgrid::kernel::profile::DatedValue* last_event = &(profile->event_list.back());
 
   xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name.c_str());
 
@@ -86,39 +70,43 @@ simgrid::kernel::profile::Profile* tmgr_trace_new_from_string(std::string name,
                last_event->date_, event.date_, input.c_str());
     last_event->date_ = event.date_ - last_event->date_;
 
-    trace->event_list.push_back(event);
-    last_event = &(trace->event_list.back());
+    profile->event_list.push_back(event);
+    last_event = &(profile->event_list.back());
   }
   if (last_event) {
     if (periodicity > 0) {
-      last_event->date_ = periodicity + trace->event_list.at(0).date_;
+      last_event->date_ = periodicity + profile->event_list.at(0).date_;
     } else {
       last_event->date_ = -1;
     }
   }
 
-  trace_list.insert({name, trace});
+  trace_list.insert({name, profile});
 
-  return trace;
+  return profile;
 }
-
-simgrid::kernel::profile::Profile* tmgr_trace_new_from_file(std::string filename)
+Profile* Profile::from_file(std::string path)
 {
-  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());
+  xbt_assert(not path.empty(), "Cannot parse a trace from an empty filename");
+  xbt_assert(trace_list.find(path) == trace_list.end(), "Refusing to define trace %s twice", path.c_str());
 
-  std::ifstream* f = surf_ifsopen(filename);
-  xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", filename.c_str(), (boost::join(surf_path, ":")).c_str());
+  std::ifstream* f = surf_ifsopen(path);
+  xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", path.c_str(), (boost::join(surf_path, ":")).c_str());
 
   std::stringstream buffer;
   buffer << f->rdbuf();
   delete f;
 
-  return tmgr_trace_new_from_string(filename, buffer.str(), -1);
+  return Profile::from_string(path, buffer.str(), -1);
+}
+FutureEvtSet::FutureEvtSet() = default;
+FutureEvtSet::~FutureEvtSet()
+{
+  while (not heap_.empty()) {
+    delete heap_.top().second;
+    heap_.pop();
+  }
 }
-namespace simgrid {
-namespace kernel {
-namespace profile {
 
 /** @brief Registers a new trace into the future event set, and get an iterator over the integrated trace  */
 Event* FutureEvtSet::add_trace(Profile* profile, resource::Resource* resource)