X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1a64ca4c11a1eb7ba2ecd102f877ac571486a034..5be69ef689eace0d9c4f15033c0fb6aa9e544ded:/examples/cpp/replay-io/s4u-replay-io.cpp diff --git a/examples/cpp/replay-io/s4u-replay-io.cpp b/examples/cpp/replay-io/s4u-replay-io.cpp index 66ebcffdc5..7d98484955 100644 --- a/examples/cpp/replay-io/s4u-replay-io.cpp +++ b/examples/cpp/replay-io/s4u-replay-io.cpp @@ -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 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("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;