From a977a7934d6566d51de5153a9a3c76632a0e2f64 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 2 Feb 2019 17:59:51 +0100 Subject: [PATCH] s:k:profile: turn two functions into static methods --- src/kernel/resource/profile/trace_mgr.cpp | 38 ++++++++----------- src/kernel/resource/profile/trace_mgr.hpp | 7 ++-- .../resource/profile/trace_mgr_test.cpp | 2 +- src/surf/sg_platf.cpp | 4 +- src/surf/xml/surfxml_sax_cb.cpp | 28 ++++++++++---- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/kernel/resource/profile/trace_mgr.cpp b/src/kernel/resource/profile/trace_mgr.cpp index c7091a048b..d5f47400d7 100644 --- a/src/kernel/resource/profile/trace_mgr.cpp +++ b/src/kernel/resource/profile/trace_mgr.cpp @@ -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) diff --git a/src/kernel/resource/profile/trace_mgr.hpp b/src/kernel/resource/profile/trace_mgr.hpp index e684228e6f..f4c2fe6192 100644 --- a/src/kernel/resource/profile/trace_mgr.hpp +++ b/src/kernel/resource/profile/trace_mgr.hpp @@ -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 event_list; }; diff --git a/src/kernel/resource/profile/trace_mgr_test.cpp b/src/kernel/resource/profile/trace_mgr_test.cpp index 53920352ce..76604b52ec 100644 --- a/src/kernel/resource/profile/trace_mgr_test.cpp +++ b/src/kernel/resource/profile/trace_mgr_test.cpp @@ -33,7 +33,7 @@ static std::vector trace2vector(const char { std::vector 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<event_list) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b5d0b2d614..0e8dce3f45 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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}); } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 0448bd70eb..a0c1577c16 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -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 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: -- 2.20.1