1 /* Copyright (c) 2014-2023. 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/EngineImpl.hpp"
8 #include "src/kernel/activity/CommImpl.hpp"
9 #include "src/mc/mc_base.hpp"
10 #include "src/mc/mc_replay.hpp"
11 #include "src/mc/transition/Transition.hpp"
14 #include "src/mc/api/State.hpp"
15 #include "src/mc/explo/Exploration.hpp"
16 #include "src/mc/mc_private.hpp"
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
21 namespace simgrid::mc {
23 void RecordTrace::replay() const
25 simgrid::mc::execute_actors();
26 auto* engine = kernel::EngineImpl::get_instance();
30 XBT_INFO("The backtrace of each transition will not be shown because of --log=no_loc");
32 simgrid_mc_replay_show_backtraces = true;
34 for (const simgrid::mc::Transition* transition : transitions_) {
35 kernel::actor::ActorImpl* actor = engine->get_actor_by_pid(transition->aid_);
36 xbt_assert(actor != nullptr, "Unexpected actor (id:%ld).", transition->aid_);
37 const kernel::actor::Simcall* simcall = &(actor->simcall_);
38 xbt_assert(simgrid::mc::request_is_visible(simcall), "Simcall %s of actor %s is not visible.", simcall->get_cname(),
41 XBT_INFO("***********************************************************************************");
42 XBT_INFO("* Path chunk #%d '%ld/%i' Actor %s(pid:%ld): %s", frame_count++, transition->aid_,
43 transition->times_considered_, simcall->issuer_->get_cname(), simcall->issuer_->get_pid(),
44 simcall->observer_->to_string().c_str());
45 XBT_INFO("***********************************************************************************");
46 if (not mc::actor_is_enabled(actor))
47 simgrid::kernel::EngineImpl::get_instance()->display_all_actor_status();
49 xbt_assert(simgrid::mc::actor_is_enabled(actor), "Actor %s (simcall %s) is not enabled.", actor->get_cname(),
50 simcall->get_cname());
52 // Execute the request:
53 simcall->issuer_->simcall_handle(transition->times_considered_);
54 simgrid::mc::execute_actors();
57 const auto& actor_list = engine->get_actor_list();
58 if (actor_list.empty()) {
59 XBT_INFO("The replay of the trace is complete. The application is terminating.");
60 } else if (std::none_of(begin(actor_list), end(actor_list),
61 [](const auto& kv) { return mc::actor_is_enabled(kv.second); })) {
62 XBT_INFO("The replay of the trace is complete. DEADLOCK detected.");
63 engine->display_all_actor_status();
65 XBT_INFO("The replay of the trace is complete. The application could run further.");
69 void simgrid::mc::RecordTrace::replay(const std::string& path_string)
71 simgrid::mc::processes_time.resize(kernel::actor::ActorImpl::get_maxpid());
72 simgrid::mc::RecordTrace trace(path_string.c_str());
74 for (auto* item : trace.transitions_)
76 simgrid::mc::processes_time.clear();
79 simgrid::mc::RecordTrace::RecordTrace(const char* data)
81 XBT_INFO("path=%s", data);
82 if (data == nullptr || data[0] == '\0')
83 throw std::invalid_argument("Could not parse record path");
85 const char* current = data;
88 int times_considered = 0;
90 if (int count = sscanf(current, "%ld/%d", &aid, ×_considered); count != 2 && count != 1)
91 throw std::invalid_argument("Could not parse record path");
92 push_back(new simgrid::mc::Transition(simgrid::mc::Transition::Type::UNKNOWN, aid, times_considered));
95 const char* end = std::strchr(current, ';');
105 std::string simgrid::mc::RecordTrace::to_string() const
107 std::ostringstream stream;
108 for (auto i = transitions_.begin(); i != transitions_.end(); ++i) {
109 if (i != transitions_.begin())
111 stream << (*i)->aid_;
112 if ((*i)->times_considered_ > 0)
113 stream << '/' << (*i)->times_considered_;
120 } // namespace simgrid::mc