From 5e9351c7145890c8105dd81af2f09cd6dc50383f Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 27 May 2021 11:04:25 +0200 Subject: [PATCH] Use std::string for xbt_parse_units. Combine parameters 'entity_kind' and 'name'. Also rename surf_parse_* to xbt_parse_*. --- include/xbt/parse_units.hpp | 26 +++++---- src/bindings/lua/lua_platf.cpp | 15 +++-- src/plugins/file_system/s4u_FileSystem.cpp | 2 +- src/s4u/s4u_Host.cpp | 6 +- src/s4u/s4u_Link.cpp | 2 +- src/s4u/s4u_Netzone.cpp | 2 +- src/smpi/internals/smpi_config.cpp | 8 +-- src/smpi/internals/smpi_utils.cpp | 3 +- src/surf/xml/surfxml_sax_cb.cpp | 68 +++++++++++----------- src/xbt/xbt_parse_units.cpp | 66 ++++++++++----------- 10 files changed, 98 insertions(+), 100 deletions(-) diff --git a/include/xbt/parse_units.hpp b/include/xbt/parse_units.hpp index 05954faaec..6ced9416c1 100644 --- a/include/xbt/parse_units.hpp +++ b/include/xbt/parse_units.hpp @@ -7,17 +7,19 @@ #ifndef SIMGRID_XBT_PARSE_UNITS_HPP #define SIMGRID_XBT_PARSE_UNITS_HPP -double xbt_parse_get_time(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name); -double surf_parse_get_size(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name); -double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name); -std::vector xbt_parse_get_bandwidths(const std::string& filename, int lineno, const char* string, - const char* entity_kind, const std::string& name); -double xbt_parse_get_speed(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name); -std::vector xbt_parse_get_all_speeds(const std::string& filename, int lineno, char* speeds, - const char* entity_kind, const std::string& id); +#include + +double xbt_parse_get_time(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind); +double xbt_parse_get_size(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind); +double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind); +std::vector xbt_parse_get_bandwidths(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind); +double xbt_parse_get_speed(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind); +std::vector xbt_parse_get_all_speeds(const std::string& filename, int lineno, const std::string& speeds, + const std::string& entity_kind); #endif diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index 48dface9c1..1df2436ef5 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -96,8 +96,8 @@ int console_add_backbone(lua_State *L) { type = lua_gettable(L, -2); lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER, "Attribute 'bandwidth' must be specified for backbone and must either be a string (in the right format; see docs) or a number."); - link->bandwidths.push_back(xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1), - "bandwidth of backbone", link->id.c_str())); + link->bandwidths.push_back( + xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1), "bandwidth of backbone " + link->id)); lua_pop(L, 1); lua_pushstring(L, "lat"); @@ -105,7 +105,7 @@ int console_add_backbone(lua_State *L) { lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER, "Attribute 'lat' must be specified for backbone and must either be a string (in the right format; see docs) or a number."); link->latency = - xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of backbone", link->id.c_str()); + xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of backbone " + link->id); lua_pop(L, 1); lua_pushstring(L, "sharing_policy"); @@ -179,7 +179,7 @@ int console_add_host(lua_State *L) { host.speed_per_pstate.push_back(lua_tonumber(L, -1)); else // LUA_TSTRING host.speed_per_pstate.push_back( - xbt_parse_get_speed(ar.short_src, ar.currentline, lua_tostring(L, -1), "speed of host", host.id)); + xbt_parse_get_speed(ar.short_src, ar.currentline, lua_tostring(L, -1), "speed of host " + host.id)); lua_pop(L, 1); // get core @@ -241,8 +241,8 @@ int console_add_link(lua_State *L) { if (type == LUA_TNUMBER) link.bandwidths.push_back(lua_tonumber(L, -1)); else // LUA_TSTRING - link.bandwidths.push_back(xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1), - "bandwidth of link", link.id.c_str())); + link.bandwidths.push_back( + xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1), "bandwidth of link " + link.id)); lua_pop(L, 1); //get latency value @@ -253,8 +253,7 @@ int console_add_link(lua_State *L) { if (type == LUA_TNUMBER) link.latency = lua_tonumber(L, -1); else // LUA_TSTRING - link.latency = - xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of link", link.id.c_str()); + link.latency = xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of link " + link.id); lua_pop(L, 1); /*Optional Arguments */ diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index bfa07cc1c0..12dd673424 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -329,7 +329,7 @@ FileSystemDiskExt::FileSystemDiskExt(const Disk* ptr) const char* size_str = ptr->get_property("size"); std::string dummyfile; if (size_str) - size_ = surf_parse_get_size(dummyfile, -1, size_str, "disk size", ptr->get_name()); + size_ = xbt_parse_get_size(dummyfile, -1, size_str, "disk size " + ptr->get_name()); const char* current_mount_str = ptr->get_property("mount"); if (current_mount_str) diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 7005ea07de..b56ad8fe02 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -277,7 +277,7 @@ std::vector Host::convert_pstate_speed_vector(const std::vector _smpi_cfg_host_speed_string{ - "smpi/host-speed", - "Speed of the host running the simulation (in flop/s). " - "Used to bench the operations.", - "20000f", [](const std::string& str) { - _smpi_cfg_host_speed = xbt_parse_get_speed("smpi/host-speed", 1, str.c_str(), "option", "smpi/host-speed"); + "smpi/host-speed", "Speed of the host running the simulation (in flop/s). Used to bench the operations.", "20000f", + [](const std::string& str) { + _smpi_cfg_host_speed = xbt_parse_get_speed("smpi/host-speed", 1, str, "option smpi/host-speed"); xbt_assert(_smpi_cfg_host_speed > 0.0, "Invalid value (%s) for 'smpi/host-speed': it must be positive.", _smpi_cfg_host_speed_string.get().c_str()); }}; diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index aec528f32b..870ae3002a 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -85,8 +85,7 @@ std::vector parse_factor(const std::string& smpi_coef_string) } } else { try { - fact.values.push_back( - xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, (*factor_iter).c_str(), "smpi factor", "")); + fact.values.push_back(xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, *factor_iter, "")); } catch (const std::invalid_argument&) { throw std::invalid_argument(std::string("Invalid factor value ") + std::to_string(iteration) + " in chunk " + std::to_string(smpi_factor.size() + 1) + ": " + *factor_iter); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index fc31b33291..b95eb0b77c 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -237,8 +237,8 @@ void STag_surfxml_host() property_sets.emplace_back(); host.id = A_surfxml_host_id; - host.speed_per_pstate = - xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed, "speed of host", host.id); + host.speed_per_pstate = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed, + "speed of host " + host.id); XBT_DEBUG("pstate: %s", A_surfxml_host_pstate); host.core_amount = surf_parse_get_int(A_surfxml_host_core); @@ -276,9 +276,9 @@ void ETag_surfxml_disk() { disk.id = A_surfxml_disk_id; disk.read_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_read___bw, - "read_bw of disk ", disk.id); + "read_bw of disk " + disk.id); disk.write_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_write___bw, - "write_bw of disk ", disk.id); + "write_bw of disk " + disk.id); sg_platf_new_disk(&disk); } @@ -307,29 +307,30 @@ void ETag_surfxml_cluster(){ cluster.suffix = A_surfxml_cluster_suffix; explodesRadical(A_surfxml_cluster_radical, &cluster.radicals); - cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed, - "speed of cluster", cluster.id); + cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed, + "speed of cluster " + cluster.id); cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core); - cluster.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw, "bw of cluster", - cluster.id); - cluster.lat = - xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat, "lat of cluster", cluster.id); + cluster.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw, + "bw of cluster " + cluster.id); + cluster.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat, + "lat of cluster " + cluster.id); if(strcmp(A_surfxml_cluster_bb___bw,"")) cluster.bb_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___bw, - "bb_bw of cluster", cluster.id); + "bb_bw of cluster " + cluster.id); if(strcmp(A_surfxml_cluster_bb___lat,"")) cluster.bb_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___lat, - "bb_lat of cluster", cluster.id); + "bb_lat of cluster " + cluster.id); if(strcmp(A_surfxml_cluster_limiter___link,"")) cluster.limiter_link = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_limiter___link, - "limiter_link of cluster", cluster.id); + "limiter_link of cluster " + cluster.id); if(strcmp(A_surfxml_cluster_loopback___bw,"")) - cluster.loopback_bw = xbt_parse_get_bandwidth( - surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id); + cluster.loopback_bw = + xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw, + "loopback_bw of cluster " + cluster.id); if(strcmp(A_surfxml_cluster_loopback___lat,"")) cluster.loopback_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___lat, - "loopback_lat of cluster", cluster.id); + "loopback_lat of cluster " + cluster.id); switch(AX_surfxml_cluster_topology){ case A_surfxml_cluster_topology_FLAT: @@ -391,11 +392,11 @@ void STag_surfxml_cabinet(){ cabinet.prefix = A_surfxml_cabinet_prefix; cabinet.suffix = A_surfxml_cabinet_suffix; cabinet.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_speed, - "speed of cabinet", cabinet.id.c_str()); - cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw, "bw of cabinet", - cabinet.id.c_str()); - cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat, "lat of cabinet", - cabinet.id.c_str()); + "speed of cabinet " + cabinet.id); + cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw, + "bw of cabinet " + cabinet.id); + cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat, + "lat of cabinet " + cabinet.id); explodesRadical(A_surfxml_cabinet_radical, &cabinet.radicals); sg_platf_new_cabinet(&cabinet); @@ -405,12 +406,12 @@ void STag_surfxml_peer(){ simgrid::kernel::routing::PeerCreationArgs peer; peer.id = std::string(A_surfxml_peer_id); - peer.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer", - peer.id.c_str()); - peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in, "bw_in of peer", - peer.id.c_str()); - peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out, - "bw_out of peer", peer.id.c_str()); + peer.speed = + xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer " + peer.id); + peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in, + "bw_in of peer " + peer.id); + peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out, + "bw_out of peer " + peer.id); peer.coord = A_surfxml_peer_coordinates; peer.speed_trace = nullptr; if (A_surfxml_peer_availability___file[0] != '\0') { @@ -442,12 +443,12 @@ void ETag_surfxml_link(){ link.id = std::string(A_surfxml_link_id); link.bandwidths = xbt_parse_get_bandwidths(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_bandwidth, - "bandwidth of link", link.id.c_str()); + "bandwidth of link " + link.id); link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file) : nullptr; - link.latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link", - link.id.c_str()); + link.latency = + xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link " + link.id); link.latency_trace = A_surfxml_link_latency___file[0] ? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file) : nullptr; @@ -517,11 +518,10 @@ void ETag_surfxml_backbone() auto link = std::make_unique(); link->id = std::string(A_surfxml_backbone_id); - link->bandwidths.push_back(xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, - A_surfxml_backbone_bandwidth, "bandwidth of backbone", - link->id.c_str())); + link->bandwidths.push_back(xbt_parse_get_bandwidth( + surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_bandwidth, "bandwidth of backbone " + link->id)); link->latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_latency, - "latency of backbone", link->id.c_str()); + "latency of backbone " + link->id); link->policy = simgrid::s4u::Link::SharingPolicy::SHARED; routing_cluster_add_backbone(std::move(link)); diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index 7bdcbf97e7..01066f2f1c 100644 --- a/src/xbt/xbt_parse_units.cpp +++ b/src/xbt/xbt_parse_units.cpp @@ -51,14 +51,14 @@ unit_scale::unit_scale(std::initializer_listsecond; } -double xbt_parse_get_time(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_time(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60), std::make_pair("d", 24 * 60 * 60), @@ -88,31 +88,31 @@ double xbt_parse_get_time(const std::string& filename, int lineno, const char* s std::make_pair("us", 1e-6), std::make_pair("ns", 1e-9), std::make_pair("ps", 1e-12)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 's' to your time to get seconds", "s"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 's' to your time to get seconds", "s"); } -double surf_parse_get_size(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_size(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true), std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B"); } -double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true), std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", - "Bps"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", + "Bps"); } -std::vector xbt_parse_get_bandwidths(const std::string& filename, int lineno, const char* string, - const char* entity_kind, const std::string& name) +std::vector xbt_parse_get_bandwidths(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true), std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)}; @@ -121,36 +121,36 @@ std::vector xbt_parse_get_bandwidths(const std::string& filename, int li std::vector tokens; boost::split(tokens, string, boost::is_any_of(";,")); for (auto const& token : tokens) { - bandwidths.push_back(surf_parse_get_value_with_unit( - filename, lineno, token.c_str(), units, entity_kind, name, + bandwidths.push_back(xbt_parse_get_value_with_unit( + filename, lineno, token.c_str(), units, entity_kind, "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps")); } return bandwidths; } -double xbt_parse_get_speed(const std::string& filename, int lineno, const char* string, const char* entity_kind, - const std::string& name) +double xbt_parse_get_speed(const std::string& filename, int lineno, const std::string& string, + const std::string& entity_kind) { static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)}; - return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name, - "Append 'f' or 'flops' to your speed to get flop per second", "f"); + return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, + "Append 'f' or 'flops' to your speed to get flop per second", "f"); } -std::vector xbt_parse_get_all_speeds(const std::string& filename, int lineno, char* speeds, - const char* entity_kind, const std::string& id) +std::vector xbt_parse_get_all_speeds(const std::string& filename, int lineno, const std::string& speeds, + const std::string& entity_kind) { std::vector speed_per_pstate; - if (strchr(speeds, ',') == nullptr) { - double speed = xbt_parse_get_speed(filename, lineno, speeds, entity_kind, id); + if (speeds.find('.') == std::string::npos) { + double speed = xbt_parse_get_speed(filename, lineno, speeds, entity_kind); speed_per_pstate.push_back(speed); } else { std::vector pstate_list; boost::split(pstate_list, speeds, boost::is_any_of(",")); for (auto speed_str : pstate_list) { boost::trim(speed_str); - double speed = xbt_parse_get_speed(filename, lineno, speed_str.c_str(), entity_kind, id); + double speed = xbt_parse_get_speed(filename, lineno, speed_str, entity_kind); speed_per_pstate.push_back(speed); XBT_DEBUG("Speed value: %f", speed); } -- 2.20.1