From dd89cc2577e61b4b86b1ae7bc58dfa2ad00747e6 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 19 Oct 2017 11:00:22 +0200 Subject: [PATCH] more strings --- src/instr/instr_config.cpp | 7 +-- src/instr/instr_interface.cpp | 10 ++-- src/instr/instr_private.hpp | 8 +-- src/msg/instr_msg_task.cpp | 6 +- src/msg/msg_vm.cpp | 3 +- src/smpi/internals/instr_smpi.cpp | 98 ++++++++++++------------------- src/smpi/internals/smpi_bench.cpp | 8 +-- src/smpi/mpi/smpi_request.cpp | 3 +- src/surf/instr_routing.cpp | 23 ++++---- 9 files changed, 66 insertions(+), 100 deletions(-) diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index eb86e1d068..546c055e44 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -356,11 +356,10 @@ void TRACE_global_init() static void print_line (const char *option, const char *desc, const char *longdesc, int detailed) { - char str[INSTR_DEFAULT_STR_SIZE]; - snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option); + std::string str = std::string("--cfg=") + option + " "; - int len = strlen (str); - printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc); + int len = str.size(); + printf("%s%*.*s %s\n", str.c_str(), 30 - len, 30 - len, "", desc); if (longdesc != nullptr && detailed){ printf ("%s\n\n", longdesc); } diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 65d54c7654..3d002d6e9d 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -87,18 +87,18 @@ void TRACE_category_with_color (const char *category, const char *color) created_categories.insert(category); //define final_color - char final_color[INSTR_DEFAULT_STR_SIZE]; + std::string final_color; if (not color) { //generate a random color double red = drand48(); double green = drand48(); double blue = drand48(); - snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue); + final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue); }else{ - snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color); + final_color = std::string(color); } - XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color); + XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", category, color, final_color.c_str()); //define the type of this category on top of hosts and links instr_new_variable_type (category, final_color); @@ -269,7 +269,7 @@ static void instr_user_variable(double time, const char* resource, const char* v if (what == INSTR_US_DECLARE){ if (created == filter->end()) { // not declared yet filter->insert(variable); - instr_new_user_variable_type (father_type, variable, color); + instr_new_user_variable_type(father_type, variable, color == nullptr ? "" : color); } }else{ if (created != filter->end()) { // declared, let's work diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index 1a1c9c7d0a..4c1136d52c 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -26,8 +26,6 @@ #define drand48() (rand() / (RAND_MAX + 1.0)) #endif -#define INSTR_DEFAULT_STR_SIZE 500 - namespace simgrid { namespace instr { @@ -328,10 +326,10 @@ extern XBT_PRIVATE std::set trivaEdgeTypes; XBT_PRIVATE long long int instr_new_paje_id(); XBT_PUBLIC(container_t) PJ_container_get_root (); XBT_PUBLIC(void) PJ_container_set_root (container_t root); -void instr_new_variable_type(std::string new_typename, const char* color); -void instr_new_user_variable_type(std::string father_type, std::string new_typename, const char* color); +void instr_new_variable_type(std::string new_typename, std::string color); +void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color); void instr_new_user_state_type(std::string father_type, std::string new_typename); -void instr_new_value_for_user_state_type(std::string new_typename, const char* value, const char* color); +void instr_new_value_for_user_state_type(std::string new_typename, const char* value, std::string color); /* instr_config.c */ XBT_PRIVATE void TRACE_TI_start(); diff --git a/src/msg/instr_msg_task.cpp b/src/msg/instr_msg_task.cpp index d3a8972883..8d2f0782cf 100644 --- a/src/msg/instr_msg_task.cpp +++ b/src/msg/instr_msg_task.cpp @@ -99,8 +99,7 @@ void TRACE_msg_task_get_end(double start_time, msg_task_t task) simgrid::instr::Type* type = process_container->type_->byName("MSG_PROCESS_STATE"); new simgrid::instr::PopStateEvent(MSG_get_clock(), process_container, type); - char key[INSTR_DEFAULT_STR_SIZE]; - snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter); + std::string key = std::string("p") + std::to_string(task->counter); type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_TASK_LINK"); new simgrid::instr::EndLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key); } @@ -117,8 +116,7 @@ int TRACE_msg_task_put_start(msg_task_t task) simgrid::instr::Value* val = type->getEntityValue("send"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, type, val); - char key[INSTR_DEFAULT_STR_SIZE]; - snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter); + std::string key = std::string("p") + std::to_string(task->counter); type = simgrid::instr::Type::getRootType()->byName("MSG_PROCESS_TASK_LINK"); new simgrid::instr::StartLinkEvent(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key); } diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 032b24c774..2a569bd846 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -289,8 +289,7 @@ static int migration_rx_fun(int argc, char *argv[]) if (TRACE_msg_vm_is_enabled()) { static long long int counter = 0; - char key[INSTR_DEFAULT_STR_SIZE]; - snprintf(key, INSTR_DEFAULT_STR_SIZE, "%lld", counter); + std::string key = std::to_string(counter); counter++; // start link diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index f7f905741a..581f87fabb 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -15,50 +15,26 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_smpi, instr, "Tracing SMPI"); -static std::unordered_map*> keys; - -static const char *smpi_colors[] ={ - "recv", "1 0 0", - "irecv", "1 0.52 0.52", - "send", "0 0 1", - "isend", "0.52 0.52 1", - "sendrecv", "0 1 1", - "wait", "1 1 0", - "waitall", "0.78 0.78 0", - "waitany", "0.78 0.78 0.58", - "test", "0.52 0.52 0", - - "allgather", "1 0 0", - "allgatherv", "1 0.52 0.52", - "allreduce", "1 0 1", - "alltoall", "0.52 0 1", - "alltoallv", "0.78 0.52 1", - "barrier", "0 0.78 0.78", - "bcast", "0 0.78 0.39", - "gather", "1 1 0", - "gatherv", "1 1 0.52", - "reduce", "0 1 0", - "reducescatter", "0.52 1 0.52", - "scan", "1 0.58 0.23", - "exscan", "1 0.54 0.25", - "scatterv", "0.52 0 0.52", - "scatter", "1 0.74 0.54", - - "computing", "0 1 1", - "sleeping", "0 0.5 0.5", - - "init", "0 1 0", - "finalize", "0 1 0", - - "put", "0.3 1 0", - "get", "0 1 0.3", - "accumulate", "1 0.3 0", - "win_fence", "1 0 0.3", - "win_post", "1 0 0.8", - "win_wait", "1 0.8 0", - "win_start", "0.8 0 1", - "win_complete", "0.8 1 0", - nullptr, nullptr, +static std::unordered_map*> keys; + +static const char* smpi_colors[] = { + "recv", "1 0 0", "irecv", "1 0.52 0.52", "send", "0 0 1", + "isend", "0.52 0.52 1", "sendrecv", "0 1 1", "wait", "1 1 0", + "waitall", "0.78 0.78 0", "waitany", "0.78 0.78 0.58", "test", "0.52 0.52 0", + + "allgather", "1 0 0", "allgatherv", "1 0.52 0.52", "allreduce", "1 0 1", + "alltoall", "0.52 0 1", "alltoallv", "0.78 0.52 1", "barrier", "0 0.78 0.78", + "bcast", "0 0.78 0.39", "gather", "1 1 0", "gatherv", "1 1 0.52", + "reduce", "0 1 0", "reducescatter", "0.52 1 0.52", "scan", "1 0.58 0.23", + "exscan", "1 0.54 0.25", "scatterv", "0.52 0 0.52", "scatter", "1 0.74 0.54", + + "computing", "0 1 1", "sleeping", "0 0.5 0.5", + + "init", "0 1 0", "finalize", "0 1 0", + + "put", "0.3 1 0", "get", "0 1 0.3", "accumulate", "1 0.3 0", + "win_fence", "1 0 0.3", "win_post", "1 0 0.8", "win_wait", "1 0.8 0", + "win_start", "0.8 0 1", "win_complete", "0.8 1 0", nullptr, nullptr, }; static const char* instr_find_color(const char* state) @@ -85,13 +61,11 @@ XBT_PRIVATE std::string smpi_container(int rank) return std::string("rank-") + std::to_string(rank); } -static char *TRACE_smpi_get_key(int src, int dst, int tag, char *key, int n, int send); - -static char *TRACE_smpi_put_key(int src, int dst, int tag, char *key, int n, int send) +static std::string TRACE_smpi_put_key(int src, int dst, int tag, int send) { - //get the dynar for src#dst - char aux[INSTR_DEFAULT_STR_SIZE]; - snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d#%d#%d", src, dst, tag, send); + // get the deque for src#dst + std::string aux = + std::to_string(src) + "#" + std::to_string(dst) + "#" + std::to_string(tag) + "#" + std::to_string(send); auto it = keys.find(aux); std::deque* d; @@ -104,7 +78,8 @@ static char *TRACE_smpi_put_key(int src, int dst, int tag, char *key, int n, int //generate the key static unsigned long long counter = 0; counter++; - snprintf(key, n, "%d_%d_%d_%llu", src, dst, tag, counter); + std::string key = + std::to_string(src) + "_" + std::to_string(dst) + "_" + std::to_string(tag) + "_" + std::to_string(counter); //push it d->push_back(key); @@ -112,16 +87,17 @@ static char *TRACE_smpi_put_key(int src, int dst, int tag, char *key, int n, int return key; } -static char *TRACE_smpi_get_key(int src, int dst, int tag, char *key, int n, int send) +static std::string TRACE_smpi_get_key(int src, int dst, int tag, int send) { - char aux[INSTR_DEFAULT_STR_SIZE]; - snprintf(aux, INSTR_DEFAULT_STR_SIZE, "%d#%d#%d#%d", src, dst, tag, send==1?0:1); + std::string key; + std::string aux = std::to_string(src) + "#" + std::to_string(dst) + "#" + std::to_string(tag) + "#" + + std::to_string(send == 1 ? 0 : 1); auto it = keys.find(aux); if (it == keys.end()) { // first posted - TRACE_smpi_put_key(src, dst, tag, key, n, send); + key = TRACE_smpi_put_key(src, dst, tag, send); } else { - snprintf(key, n, "%s", it->second->front().c_str()); + key = it->second->front(); it->second->pop_front(); } return key; @@ -369,12 +345,11 @@ void TRACE_smpi_send(int rank, int src, int dst, int tag, int size) if (not TRACE_smpi_is_enabled()) return; - char key[INSTR_DEFAULT_STR_SIZE] = {0}; - TRACE_smpi_get_key(src, dst, tag, key, INSTR_DEFAULT_STR_SIZE,1); + std::string key = TRACE_smpi_get_key(src, dst, tag, 1); container_t container = simgrid::instr::Container::byName(smpi_container(rank)); simgrid::instr::Type* type = simgrid::instr::Type::getRootType()->byName("MPI_LINK"); - XBT_DEBUG("Send tracing from %d to %d, tag %d, with key %s", src, dst, tag, key); + XBT_DEBUG("Send tracing from %d to %d, tag %d, with key %s", src, dst, tag, key.c_str()); new simgrid::instr::StartLinkEvent(SIMIX_get_clock(), PJ_container_get_root(), type, container, "PTP", key, size); } @@ -383,11 +358,10 @@ void TRACE_smpi_recv(int src, int dst, int tag) if (not TRACE_smpi_is_enabled()) return; - char key[INSTR_DEFAULT_STR_SIZE] = {0}; - TRACE_smpi_get_key(src, dst, tag, key, INSTR_DEFAULT_STR_SIZE,0); + std::string key = TRACE_smpi_get_key(src, dst, tag, 0); container_t container = simgrid::instr::Container::byName(smpi_container(dst)); simgrid::instr::Type* type = simgrid::instr::Type::getRootType()->byName("MPI_LINK"); - XBT_DEBUG("Recv tracing from %d to %d, tag %d, with key %s", src, dst, tag, key); + XBT_DEBUG("Recv tracing from %d to %d, tag %d, with key %s", src, dst, tag, key.c_str()); new simgrid::instr::EndLinkEvent(SIMIX_get_clock(), PJ_container_get_root(), type, container, "PTP", key); } diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 4e1243a93b..3f61b79c93 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -157,14 +157,12 @@ void smpi_bench_end() #if HAVE_PAPI if (xbt_cfg_get_string("smpi/papi-events")[0] != '\0' && TRACE_smpi_is_enabled()) { - char container_name[INSTR_DEFAULT_STR_SIZE]; - smpi_container(smpi_process()->index(), container_name, INSTR_DEFAULT_STR_SIZE); - container_t container = PJ_container_get(container_name); + container_t container = new simgrid::instr::Container(smpi_container(smpi_process()->index())); papi_counter_t& counter_data = smpi_process()->papi_counters(); for (auto const& pair : counter_data) { - new_pajeSetVariable(surf_get_clock(), container, - PJ_type_get(/* countername */ pair.first.c_str(), container->type), pair.second); + new simgrid::instr::SetVariableEvent( + surf_get_clock(), container, PJ_type_get(/* countername */ pair.first.c_str(), container->type), pair.second); } } #endif diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 8834d3215c..10a6da27aa 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -31,7 +31,8 @@ extern void (*smpi_comm_copy_data_callback) (smx_activity_t, void*, size_t); namespace simgrid{ namespace smpi{ -Request::Request(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags) : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags) +Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags) + : buf_(buf), old_type_(datatype), src_(src), dst_(dst), tag_(tag), comm_(comm), flags_(flags) { void *old_buf = nullptr; // FIXME Handle the case of a partial shared malloc. diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index ccb7013263..fdb97b0faa 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -106,8 +106,7 @@ static void linkContainers(container_t src, container_t dst, std::setgetName() == "HOST" || root->getName() == "MSG_VM") - root->getOrCreateVariableType(std::string("p") + new_typename, color == nullptr ? "" : color); + root->getOrCreateVariableType(std::string("p") + new_typename, color); if (root->getName() == "LINK") - root->getOrCreateVariableType(std::string("b") + new_typename, color == nullptr ? "" : color); + root->getOrCreateVariableType(std::string("b") + new_typename, color); for (auto elm : root->children_) { - recursiveNewVariableType(new_typename, color == nullptr ? "" : color, elm.second); + recursiveNewVariableType(new_typename, color, elm.second); } } -void instr_new_variable_type(std::string new_typename, const char* color) +void instr_new_variable_type(std::string new_typename, std::string color) { recursiveNewVariableType(new_typename, color, simgrid::instr::Type::getRootType()); } -static void recursiveNewUserVariableType(std::string father_type, std::string new_typename, const char* color, +static void recursiveNewUserVariableType(std::string father_type, std::string new_typename, std::string color, simgrid::instr::Type* root) { if (root->getName() == father_type) { - root->getOrCreateVariableType(new_typename, color == nullptr ? "" : color); + root->getOrCreateVariableType(new_typename, color); } for (auto elm : root->children_) recursiveNewUserVariableType(father_type, new_typename, color, elm.second); } -void instr_new_user_variable_type(std::string father_type, std::string new_typename, const char* color) +void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color) { recursiveNewUserVariableType(father_type, new_typename, color, simgrid::instr::Type::getRootType()); } @@ -329,7 +328,7 @@ void instr_new_user_state_type(std::string father_type, std::string new_typename recursiveNewUserStateType(father_type, new_typename, simgrid::instr::Type::getRootType()); } -static void recursiveNewValueForUserStateType(std::string type_name, const char* val, const char* color, +static void recursiveNewValueForUserStateType(std::string type_name, const char* val, std::string color, simgrid::instr::Type* root) { if (root->getName() == type_name) @@ -339,7 +338,7 @@ static void recursiveNewValueForUserStateType(std::string type_name, const char* recursiveNewValueForUserStateType(type_name, val, color, elm.second); } -void instr_new_value_for_user_state_type(std::string type_name, const char* value, const char* color) +void instr_new_value_for_user_state_type(std::string type_name, const char* value, std::string color) { recursiveNewValueForUserStateType(type_name, value, color, simgrid::instr::Type::getRootType()); } -- 2.20.1