Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace, when possible, calls to bprintf() by calls to xbt_strdup().
authoragiersch <agiersch@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 24 Mar 2011 14:58:35 +0000 (14:58 +0000)
committeragiersch <agiersch@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 24 Mar 2011 14:58:35 +0000 (14:58 +0000)
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

src/mc/mc_request.c
src/simdag/sd_global.c
src/simix/smx_environment.c
src/surf/surf_routing.c
src/xbt/backtrace_linux.c
teshsuite/simdag/platforms/flatifier.c
tools/graphicator/graphicator.c

index 412a73f..75a27c0 100644 (file)
@@ -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;
index 1688cac..572898d 100644 (file)
@@ -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();
index 600d6da..c342abc 100644 (file)
@@ -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();
index 2bc91e5..348513c 100644 (file)
@@ -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\tid=\"%s\"\tpower=\"%s\">", 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\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", 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\tid=\"%s\"\tpower=\"%s\">", 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\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>", 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\tid=\"%s\" bw=\"%s\" lat=\"%s\"/>", link_router,temp_cluster_bw, temp_cluster_lat);
   A_surfxml_link_state = A_surfxml_link_state_ON;
index 77f856d..1c6b5bc 100644 (file)
@@ -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)");
       }
     }
 
index 90c7cc3..907169a 100644 (file)
@@ -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_ctn id=\"%s\"/>",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_ctn id=\"%s\"/>",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_ctn id=\"%s\"/>",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_ctn id=\"%s\"/>",link_name);
                                        free(link_name);
                                }
index a760788..908cbdb 100644 (file)
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
         for(i=0;i<xbt_dynar_length(route) ;i++)
         {
           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);
           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){