]> 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
Revalidate the tesh of some working MC tests
[simgrid.git] / examples / cpp / replay-io / s4u-replay-io.cpp
index 66ebcffdc5eac2137ee275e8d9c788038a99859f..7d98484955efdb37fcd41912b7a8a1164ce8ea63 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2017-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -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;