From: agiersch Date: Thu, 24 Mar 2011 14:58:35 +0000 (+0000) Subject: Replace, when possible, calls to bprintf() by calls to xbt_strdup(). X-Git-Tag: v3.6_beta2~116 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7141af752d0f9389c4da1c42a151c16369c70f2a Replace, when possible, calls to bprintf() by calls to xbt_strdup(). This should be slightly faster. A quick test shows 10% improvement for basic_parsing_test on a cluster with 1e6 hosts. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9853 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/mc/mc_request.c b/src/mc/mc_request.c index 412a73f121..75a27c0f74 100644 --- a/src/mc/mc_request.c +++ b/src/mc/mc_request.c @@ -150,23 +150,23 @@ char *MC_request_to_string(smx_req_t req, int value) switch(req->call){ case REQ_COMM_ISEND: - type = bprintf("iSend"); + type = xbt_strdup("iSend"); args = bprintf("src=%s, buff=%p, size=%zu", req->issuer->name, req->comm_isend.src_buff, req->comm_isend.src_buff_size); break; case REQ_COMM_IRECV: size = req->comm_irecv.dst_buff_size ? *req->comm_irecv.dst_buff_size : 0; - type = bprintf("iRecv"); + type = xbt_strdup("iRecv"); args = bprintf("dst=%s, buff=%p, size=%zu", req->issuer->name, req->comm_irecv.dst_buff, size); break; case REQ_COMM_WAIT: act = req->comm_wait.comm; if(value == -1){ - type = bprintf("WaitTimeout"); + type = xbt_strdup("WaitTimeout"); args = bprintf("comm=%p", act); }else{ - type = bprintf("Wait"); + type = xbt_strdup("Wait"); args = bprintf("comm=%p [(%lu)%s -> (%lu)%s]", act, act->comm.src_proc ? act->comm.src_proc->pid : 0, act->comm.src_proc ? act->comm.src_proc->name : "", @@ -177,10 +177,10 @@ char *MC_request_to_string(smx_req_t req, int value) case REQ_COMM_TEST: act = req->comm_test.comm; if(act->comm.src_proc == NULL || act->comm.src_proc == NULL){ - type = bprintf("Test FALSE"); + type = xbt_strdup("Test FALSE"); args = bprintf("comm=%p", act); }else{ - type = bprintf("Test TRUE"); + type = xbt_strdup("Test TRUE"); args = bprintf("comm=%p [(%lu)%s -> (%lu)%s]", act, act->comm.src_proc ? act->comm.src_proc->pid : 0, act->comm.src_proc ? act->comm.src_proc->name : "", @@ -190,17 +190,17 @@ char *MC_request_to_string(smx_req_t req, int value) break; case REQ_COMM_WAITANY: - type = bprintf("WaitAny"); + type = xbt_strdup("WaitAny"); args = bprintf("comm=%p (%d of %lu)", xbt_dynar_get_as(req->comm_waitany.comms, value, smx_action_t), value+1, xbt_dynar_length(req->comm_waitany.comms)); break; case REQ_COMM_TESTANY: if(value == -1){ - type = bprintf("TestAny FALSE"); - args = bprintf("-"); + type = xbt_strdup("TestAny FALSE"); + args = xbt_strdup("-"); }else{ - type = bprintf("TestAny"); + type = xbt_strdup("TestAny"); args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(req->comm_testany.comms)); } break; diff --git a/src/simdag/sd_global.c b/src/simdag/sd_global.c index 1688cacfd9..572898dd6e 100644 --- a/src/simdag/sd_global.c +++ b/src/simdag/sd_global.c @@ -185,7 +185,7 @@ void SD_create_environment(const char *platform_file) void **surf_workstation = NULL; void **surf_link = NULL; - platform_filename = bprintf("%s",platform_file); + platform_filename = xbt_strdup(platform_file); // Reset callbacks surf_parse_reset_callbacks(); diff --git a/src/simix/smx_environment.c b/src/simix/smx_environment.c index 600d6da7b8..c342abc4a8 100644 --- a/src/simix/smx_environment.c +++ b/src/simix/smx_environment.c @@ -39,7 +39,7 @@ void SIMIX_create_environment(const char *file) double start, end; - platform_filename = bprintf("%s",file); + platform_filename = xbt_strdup(file); // Reset callbacks surf_parse_reset_callbacks(); diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 2bc91e53b3..348513ca0c 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -3353,8 +3353,8 @@ static void routing_parse_Scluster(void) char *cluster_state_file = A_surfxml_cluster_state_file; char *host_id, *groups, *link_id = NULL; char *router_id, *link_router, *link_backbone; - char *availability_file = bprintf("%s",cluster_availability_file); - char *state_file = bprintf("%s",cluster_state_file); + char *availability_file = xbt_strdup(cluster_availability_file); + char *state_file = xbt_strdup(cluster_state_file); if(xbt_dict_size(patterns)==0) patterns = xbt_dict_new(); @@ -3412,7 +3412,7 @@ static void routing_parse_Scluster(void) link_id = bprintf("%s_link_%d", cluster_id, start); xbt_dict_set(patterns, "radical", bprintf("%d", start), xbt_free); - temp_cluster_power = bprintf("%s",cluster_power); + temp_cluster_power = xbt_strdup(cluster_power); temp_cluster_power = replace_random_parameter(temp_cluster_power); XBT_DEBUG("", host_id, temp_cluster_power); A_surfxml_host_state = A_surfxml_host_state_ON; @@ -3422,9 +3422,9 @@ static void routing_parse_Scluster(void) SURFXML_BUFFER_SET(host_availability, "1.0"); SURFXML_BUFFER_SET(host_coordinates, ""); xbt_free(availability_file); - availability_file = bprintf("%s",cluster_availability_file); + availability_file = xbt_strdup(cluster_availability_file); xbt_free(state_file); - state_file = bprintf("%s",cluster_state_file); + state_file = xbt_strdup(cluster_state_file); XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns)); XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns)); SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns)); @@ -3434,9 +3434,9 @@ static void routing_parse_Scluster(void) SURFXML_END_TAG(host); - temp_cluster_bw = bprintf("%s",cluster_bw); + temp_cluster_bw = xbt_strdup(cluster_bw); temp_cluster_bw = replace_random_parameter(temp_cluster_bw); - temp_cluster_lat = bprintf("%s",cluster_lat); + temp_cluster_lat = xbt_strdup(cluster_lat); temp_cluster_lat = replace_random_parameter(temp_cluster_lat); XBT_DEBUG("", link_id,temp_cluster_bw, cluster_lat); A_surfxml_link_state = A_surfxml_link_state_ON; @@ -3474,7 +3474,7 @@ static void routing_parse_Scluster(void) link_id = bprintf("%s_link_%d", cluster_id, i); xbt_dict_set(patterns, "radical", bprintf("%d", i), xbt_free); - temp_cluster_power = bprintf("%s",cluster_power); + temp_cluster_power = xbt_strdup(cluster_power); temp_cluster_power = replace_random_parameter(temp_cluster_power); XBT_DEBUG("", host_id, temp_cluster_power); A_surfxml_host_state = A_surfxml_host_state_ON; @@ -3484,9 +3484,9 @@ static void routing_parse_Scluster(void) SURFXML_BUFFER_SET(host_availability, "1.0"); SURFXML_BUFFER_SET(host_coordinates, ""); xbt_free(availability_file); - availability_file = bprintf("%s",cluster_availability_file); + availability_file = xbt_strdup(cluster_availability_file); xbt_free(state_file); - state_file = bprintf("%s",cluster_state_file); + state_file = xbt_strdup(cluster_state_file); XBT_DEBUG("\tavailability_file=\"%s\"",xbt_str_varsubst(availability_file,patterns)); XBT_DEBUG("\tstate_file=\"%s\"",xbt_str_varsubst(state_file,patterns)); SURFXML_BUFFER_SET(host_availability_file, xbt_str_varsubst(availability_file,patterns)); @@ -3497,9 +3497,9 @@ static void routing_parse_Scluster(void) xbt_free(temp_cluster_power); - temp_cluster_bw = bprintf("%s",cluster_bw); + temp_cluster_bw = xbt_strdup(cluster_bw); temp_cluster_bw = replace_random_parameter(temp_cluster_bw); - temp_cluster_lat = bprintf("%s",cluster_lat); + temp_cluster_lat = xbt_strdup(cluster_lat); temp_cluster_lat = replace_random_parameter(temp_cluster_lat); XBT_DEBUG("", link_id,temp_cluster_bw, cluster_lat); A_surfxml_link_state = A_surfxml_link_state_ON; @@ -3546,10 +3546,10 @@ static void routing_parse_Scluster(void) SURFXML_END_TAG(router); //TODO - xbt_dict_set(patterns, "radical", bprintf("_router"), xbt_free); - temp_cluster_bw = bprintf("%s",cluster_bw); + xbt_dict_set(patterns, "radical", xbt_strdup("_router"), xbt_free); + temp_cluster_bw = xbt_strdup(cluster_bw); temp_cluster_bw = replace_random_parameter(temp_cluster_bw); - temp_cluster_lat = bprintf("%s",cluster_lat); + temp_cluster_lat = xbt_strdup(cluster_lat); temp_cluster_lat = replace_random_parameter(temp_cluster_lat); XBT_DEBUG("", link_router,temp_cluster_bw, temp_cluster_lat); A_surfxml_link_state = A_surfxml_link_state_ON; diff --git a/src/xbt/backtrace_linux.c b/src/xbt/backtrace_linux.c index 77f856d140..1c6b5bca01 100644 --- a/src/xbt/backtrace_linux.c +++ b/src/xbt/backtrace_linux.c @@ -128,9 +128,9 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) p = strchr(buff, ']'); *p = '\0'; if (strcmp(buff, "(nil)")) - addrs[i] = bprintf("%s", buff); + addrs[i] = xbt_strdup(buff); else - addrs[i] = bprintf("0x0"); + addrs[i] = xbt_strdup("0x0"); XBT_DEBUG("Set up a new address: %d, '%s'(%p)", i, addrs[i], addrs[i]); /* Add it to the command line args */ @@ -304,7 +304,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) ("xbt_thread_context_wrapper", line_func, strlen("xbt_thread_context_wrapper"))) { free(e->bt_strings[i]); - e->bt_strings[i] = bprintf("** (in a separate thread)"); + e->bt_strings[i] = xbt_strdup("** (in a separate thread)"); } } diff --git a/teshsuite/simdag/platforms/flatifier.c b/teshsuite/simdag/platforms/flatifier.c index 90c7cc3bb0..907169a93a 100644 --- a/teshsuite/simdag/platforms/flatifier.c +++ b/teshsuite/simdag/platforms/flatifier.c @@ -138,7 +138,7 @@ int main(int argc, char **argv) { void *link = xbt_dynar_get_as(route,i,void *); - char *link_name = bprintf("%s",((surf_resource_t) link)->name); + char *link_name = xbt_strdup(((surf_resource_t)link)->name); printf("",link_name); free(link_name); } @@ -155,7 +155,7 @@ int main(int argc, char **argv) { void *link = xbt_dynar_get_as(route,i,void *); - char *link_name = bprintf("%s",((surf_resource_t) link)->name); + char *link_name = xbt_strdup(((surf_resource_t)link)->name); printf("",link_name); free(link_name); } @@ -178,7 +178,7 @@ int main(int argc, char **argv) { void *link = xbt_dynar_get_as(route,i,void *); - char *link_name = bprintf("%s",((surf_resource_t) link)->name); + char *link_name = xbt_strdup(((surf_resource_t)link)->name); printf("",link_name); free(link_name); } @@ -195,7 +195,7 @@ int main(int argc, char **argv) { void *link = xbt_dynar_get_as(route,i,void *); - char *link_name = bprintf("%s",((surf_resource_t) link)->name); + char *link_name = xbt_strdup(((surf_resource_t)link)->name); printf("",link_name); free(link_name); } diff --git a/tools/graphicator/graphicator.c b/tools/graphicator/graphicator.c index a760788c3d..908cbdbb41 100644 --- a/tools/graphicator/graphicator.c +++ b/tools/graphicator/graphicator.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) for(i=0;iname); + char *link_name = xbt_strdup(((surf_resource_t)link)->name); if (strcmp(link_name, "loopback")==0 || strcmp(link_name, "__loopback__")==0) continue; xbt_node_t link_node = xbt_graph_search_node (graph, link_name, strcmp); if (!link_node){