1 /* Copyright (c) 2014-2022. 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/api/Transition.hpp"
10 #include "src/mc/mc_base.hpp"
11 #include "src/mc/mc_replay.hpp"
14 #include "src/mc/api/State.hpp"
15 #include "src/mc/checker/Checker.hpp"
16 #include "src/mc/mc_private.hpp"
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
24 void RecordTrace::replay()
26 simgrid::mc::execute_actors();
28 for (simgrid::mc::Transition* const transition : transitions_) {
29 XBT_DEBUG("Executing %ld$%i", transition->aid_, transition->times_considered_);
32 kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(transition->aid_);
33 xbt_assert(actor != nullptr, "Unexpected actor (id:%ld).", transition->aid_);
34 const s_smx_simcall* simcall = &(actor->simcall_);
35 xbt_assert(simcall->call_ != simix::Simcall::NONE, "No simcall for process %ld.", transition->aid_);
36 xbt_assert(simgrid::mc::request_is_visible(simcall) && simgrid::mc::actor_is_enabled(actor), "Unexpected simcall.");
38 // Execute the request:
39 simcall->issuer_->simcall_handle(transition->times_considered_);
40 simgrid::mc::execute_actors();
44 void simgrid::mc::RecordTrace::replay(const std::string& path_string)
46 simgrid::mc::processes_time.resize(simgrid::kernel::actor::get_maxpid());
47 simgrid::mc::RecordTrace trace(path_string.c_str());
49 for (auto* item : trace.transitions_)
51 simgrid::mc::processes_time.clear();
54 simgrid::mc::RecordTrace::RecordTrace(const char* data)
56 XBT_INFO("path=%s", data);
57 if (data == nullptr || data[0] == '\0')
58 throw std::invalid_argument("Could not parse record path");
60 const char* current = data;
64 int count = sscanf(current, "%ld/%d", &aid, ×_considered);
66 if(count != 2 && count != 1)
67 throw std::invalid_argument("Could not parse record path");
68 push_back(new simgrid::mc::Transition(simgrid::mc::Transition::Type::UNKNOWN, aid, times_considered));
71 const char* end = std::strchr(current, ';');
81 std::string simgrid::mc::RecordTrace::to_string() const
83 std::ostringstream stream;
84 for (auto i = transitions_.begin(); i != transitions_.end(); ++i) {
85 if (i != transitions_.begin())
88 if ((*i)->times_considered_ > 0)
89 stream << '/' << (*i)->times_considered_;