Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use std::string in simgrid::mc::request_to_string
[simgrid.git] / src / mc / mc_request.cpp
index d6be451..556e335 100644 (file)
 
 using simgrid::mc::remote;
 
-extern "C" {
-
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
                                 "Logging specific to MC (request)");
 
-}
-
 static char *pointer_to_string(void *pointer);
 static char *buff_size_to_string(size_t size);
 
@@ -140,9 +136,6 @@ bool request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2)
 // Those are MC_state_get_internal_request(state)
 bool request_depend(smx_simcall_t r1, smx_simcall_t r2)
 {
-  if (simgrid::mc::reduction_mode == simgrid::mc::ReductionMode::none)
-    return true;
-
   if (r1->issuer == r2->issuer)
     return false;
 
@@ -207,7 +200,7 @@ static char *buff_size_to_string(size_t buff_size)
 }
 
 
-char *simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType request_type)
+std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType request_type)
 {
   bool use_remote_comm = true;
   switch(request_type) {
@@ -408,16 +401,14 @@ char *simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::
     THROW_UNIMPLEMENTED;
   }
 
-  char* str;
+  std::string str;
   if (args != nullptr)
-    str =
-        bprintf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
+    str = simgrid::xbt::string_printf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
                 MC_smx_process_get_host_name(issuer),
                 MC_smx_process_get_name(issuer),
                 type, args);
   else
-    str =
-        bprintf("[(%lu)%s (%s)] %s ", issuer->pid,
+    str = simgrid::xbt::string_printf("[(%lu)%s (%s)] %s ", issuer->pid,
                 MC_smx_process_get_host_name(issuer),
                 MC_smx_process_get_name(issuer),
                 type);
@@ -469,6 +460,27 @@ bool process_is_enabled(smx_process_t process)
   return simgrid::mc::request_is_enabled(&process->simcall);
 }
 
+static const char* colors[] = {
+  "blue",
+  "red",
+  "green3",
+  "goldenrod",
+  "brown",
+  "purple",
+  "magenta",
+  "turquoise4",
+  "gray25",
+  "forestgreen",
+  "hotpink",
+  "lightblue",
+  "tan",
+};
+
+static inline const char* get_color(int id)
+{
+  return colors[id % (sizeof(colors) / sizeof(colors[0])) ];
+}
+
 char *request_get_dot_output(smx_simcall_t req, int value)
 {
   char *label = nullptr;
@@ -606,9 +618,10 @@ char *request_get_dot_output(smx_simcall_t req, int value)
     THROW_UNIMPLEMENTED;
   }
 
+  const char* color = get_color(issuer->pid - 1);
   char* str =
       bprintf("label = \"%s\", color = %s, fontcolor = %s", label,
-              colors[issuer->pid - 1], colors[issuer->pid - 1]);
+              color, color);
   xbt_free(label);
   return str;