1 /* Copyright (c) 2014-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/mc_record.hpp"
7 #include "src/kernel/activity/CommImpl.hpp"
8 #include "src/kernel/context/Context.hpp"
9 #include "src/mc/Transition.hpp"
10 #include "src/mc/mc_base.hpp"
11 #include "src/mc/mc_replay.hpp"
14 #include "src/mc/checker/Checker.hpp"
15 #include "src/mc/mc_private.hpp"
16 #include "src/mc/mc_state.hpp"
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
24 void replay(RecordTrace const& trace)
26 simgrid::mc::execute_actors();
28 for (simgrid::mc::Transition const& transition : trace) {
29 XBT_DEBUG("Executing %i$%i", transition.pid_, transition.times_considered_);
32 kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(transition.pid_);
34 xbt_die("Unexpected actor (id:%d).", transition.pid_);
35 const s_smx_simcall* simcall = &(actor->simcall_);
36 if (simcall->call_ == simix::Simcall::NONE)
37 xbt_die("No simcall for process %d.", transition.pid_);
38 if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(actor))
39 xbt_die("Unexpected simcall.");
41 // Execute the request:
42 simcall->issuer_->simcall_handle(transition.times_considered_);
43 simgrid::mc::execute_actors();
47 void replay(const std::string& path_string)
49 simgrid::mc::processes_time.resize(simgrid::kernel::actor::get_maxpid());
50 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
51 simgrid::mc::replay(trace);
52 simgrid::mc::processes_time.clear();
55 RecordTrace parseRecordTrace(const char* data)
58 XBT_INFO("path=%s", data);
59 if (data == nullptr || data[0] == '\0')
60 throw std::invalid_argument("Could not parse record path");
62 const char* current = data;
64 simgrid::mc::Transition item;
65 int count = sscanf(current, "%d/%d", &item.pid_, &item.times_considered_);
67 if(count != 2 && count != 1)
68 throw std::invalid_argument("Could not parse record path");
72 const char* end = std::strchr(current, ';');
84 std::string traceToString(simgrid::mc::RecordTrace const& trace)
86 std::ostringstream stream;
87 for (auto i = trace.begin(); i != trace.end(); ++i) {
88 if (i != trace.begin())
91 if (i->times_considered_)
92 stream << '/' << i->times_considered_;
99 RecordTrace trace = mc_model_checker->getChecker()->get_record_trace();
100 XBT_INFO("Path = %s", traceToString(trace).c_str());