]> AND Public Git Repository - simgrid.git/blobdiff - examples/cpp/replay-io/s4u-replay-io.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Workaround false alarm stack-use-after-scope from Asan with operator<<.
[simgrid.git] / examples / cpp / replay-io / s4u-replay-io.cpp
index 66ebcffdc5eac2137ee275e8d9c788038a99859f..8755783897b5afcaf838704fc50a1ba4749bf975 100644 (file)
@@ -40,7 +40,12 @@ public:
   explicit Replayer(std::vector<std::string> args)
   {
     const char* actor_name = args[0].c_str();
-    simgrid::xbt::replay_runner(actor_name, nullptr);
+    if (args.size() > 1) { // split mode, the trace file was provided in the deployment file
+      const char* trace_filename = args[1].c_str();
+      simgrid::xbt::replay_runner(actor_name, trace_filename);
+    } else { // Merged mode
+      simgrid::xbt::replay_runner(actor_name);
+    }
   }
 
   void operator()() const
@@ -83,8 +88,7 @@ public:
     double clock          = simgrid::s4u::Engine::get_clock();
 
     ACT_DEBUG("Entering Close: %s (filename: %s)", NAME.c_str(), file_name.c_str());
-    XBT_ATTRIB_UNUSED auto count = opened_files.erase(full_name);
-    xbt_assert(count == 1, "File not found in opened files: %s", full_name.c_str());
+    xbt_assert(opened_files.erase(full_name) == 1, "File not found in opened files: %s", full_name.c_str());
 
     log_action(action, simgrid::s4u::Engine::get_clock() - clock);
   }
@@ -108,21 +112,16 @@ int main(int argc, char* argv[])
   e.register_actor<Replayer>("p0");
   e.load_deployment(argv[2]);
 
+  if (argv[3] != nullptr)
+    xbt_replay_set_tracefile(argv[3]);
+
   /*   Action registration */
   xbt_replay_action_register("open", Replayer::open);
   xbt_replay_action_register("read", Replayer::read);
   xbt_replay_action_register("close", Replayer::close);
 
-  std::ifstream ifs;
-  if (argv[3]) {
-    ifs.open(argv[3], std::ifstream::in);
-    simgrid::xbt::action_fs = &ifs;
-  }
-
   e.run();
 
-  simgrid::xbt::action_fs = nullptr;
-
   XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
 
   return 0;