Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
s:k:profile: turn two functions into static methods
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 2 Feb 2019 16:59:51 +0000 (17:59 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 2 Feb 2019 16:59:51 +0000 (17:59 +0100)
src/kernel/resource/profile/trace_mgr.cpp
src/kernel/resource/profile/trace_mgr.hpp
src/kernel/resource/profile/trace_mgr_test.cpp
src/surf/sg_platf.cpp
src/surf/xml/surfxml_sax_cb.cpp

index c7091a0..d5f4740 100644 (file)
@@ -45,19 +45,7 @@ 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();
@@ -101,24 +89,28 @@ simgrid::kernel::profile::Profile* tmgr_trace_new_from_string(std::string name,
 
   return trace;
 }
-
-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)
index e684228..f4c2fe6 100644 (file)
@@ -41,10 +41,6 @@ XBT_PUBLIC void tmgr_trace_event_unref(simgrid::kernel::profile::Event** trace_e
 
 XBT_PUBLIC void tmgr_finalize();
 
-XBT_PUBLIC simgrid::kernel::profile::Profile* tmgr_trace_new_from_file(std::string filename);
-XBT_PUBLIC simgrid::kernel::profile::Profile* tmgr_trace_new_from_string(std::string id, std::string input,
-                                                                         double periodicity);
-
 namespace simgrid {
 namespace kernel {
 namespace profile {
@@ -81,6 +77,9 @@ public:
   /**  Creates an empty trace */
   explicit Profile();
   virtual ~Profile();
+
+  static Profile* from_file(std::string path);
+  static Profile* from_string(std::string name, std::string input, double periodicity);
   // private:
   std::vector<DatedValue> event_list;
 };
index 5392035..76604b5 100644 (file)
@@ -33,7 +33,7 @@ static std::vector<simgrid::kernel::profile::DatedValue> trace2vector(const char
 {
   std::vector<simgrid::kernel::profile::DatedValue> res;
 
-  simgrid::kernel::profile::Profile* trace = tmgr_trace_new_from_string("TheName", str, 0);
+  simgrid::kernel::profile::Profile* trace = simgrid::kernel::profile::Profile::from_string("TheName", str, 0);
   XBT_VERB("---------------------------------------------------------");
   XBT_VERB("data>>\n%s<<data\n", str);
   for (auto const& evt : trace->event_list)
index b5d0b2d..0e8dce3 100644 (file)
@@ -660,11 +660,11 @@ void sg_platf_new_trace(simgrid::kernel::routing::ProfileCreationArgs* profile)
 {
   simgrid::kernel::profile::Profile* mgr_profile;
   if (not profile->file.empty()) {
-    mgr_profile = tmgr_trace_new_from_file(profile->file);
+    mgr_profile = simgrid::kernel::profile::Profile::from_file(profile->file);
   } else {
     xbt_assert(not profile->pc_data.empty(), "Trace '%s' must have either a content, or point to a file on disk.",
                profile->id.c_str());
-    mgr_profile = tmgr_trace_new_from_string(profile->id, profile->pc_data, profile->periodicity);
+    mgr_profile = simgrid::kernel::profile::Profile::from_string(profile->id, profile->pc_data, profile->periodicity);
   }
   traces_set_list.insert({profile->id, mgr_profile});
 }
index 0448bd7..a0c1577 100644 (file)
@@ -429,8 +429,12 @@ void ETag_surfxml_host()    {
 
   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
-  host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
-  host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
+  host.speed_trace = A_surfxml_host_availability___file[0]
+                         ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_availability___file)
+                         : nullptr;
+  host.state_trace = A_surfxml_host_state___file[0]
+                         ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file)
+                         : nullptr;
   host.pstate      = surf_parse_get_int(A_surfxml_host_pstate);
   host.coord       = A_surfxml_host_coordinates;
 
@@ -554,8 +558,12 @@ void STag_surfxml_peer(){
   peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
   peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
   peer.coord       = A_surfxml_peer_coordinates;
-  peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
-  peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
+  peer.speed_trace = A_surfxml_peer_availability___file[0]
+                         ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_availability___file)
+                         : nullptr;
+  peer.state_trace = A_surfxml_peer_state___file[0]
+                         ? simgrid::kernel::profile::Profile::from_file(A_surfxml_peer_state___file)
+                         : nullptr;
 
   if (A_surfxml_peer_lat[0] != '\0')
     XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
@@ -577,10 +585,16 @@ void ETag_surfxml_link(){
 
   link.id                  = std::string(A_surfxml_link_id);
   link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
-  link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
+  link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0]
+                             ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
+                             : nullptr;
   link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
-  link.latency_trace       = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
-  link.state_trace         = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
+  link.latency_trace       = A_surfxml_link_latency___file[0]
+                           ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
+                           : nullptr;
+  link.state_trace = A_surfxml_link_state___file[0]
+                         ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_state___file)
+                         : nullptr;
 
   switch (A_surfxml_link_sharing___policy) {
   case A_surfxml_link_sharing___policy_SHARED: