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"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
15 namespace simgrid::mc {
17 void RecordTrace::replay() const
19 simgrid::mc::execute_actors();
20 auto* engine = kernel::EngineImpl::get_instance();
24 XBT_INFO("The backtrace of each transition will not be shown because of --log=no_loc");
26 simgrid_mc_replay_show_backtraces = true;
28 for (const simgrid::mc::Transition* transition : transitions_) {
29 kernel::actor::ActorImpl* actor = engine->get_actor_by_pid(transition->aid_);
30 xbt_assert(actor != nullptr, "Unexpected actor (id:%ld).", transition->aid_);
31 const kernel::actor::Simcall* simcall = &(actor->simcall_);
32 xbt_assert(simgrid::mc::request_is_visible(simcall), "Simcall %s of actor %s is not visible.", simcall->get_cname(),
35 XBT_INFO("***********************************************************************************");
36 XBT_INFO("* Path chunk #%d '%ld/%i' Actor %s(pid:%ld): %s", frame_count++, transition->aid_,
37 transition->times_considered_, simcall->issuer_->get_cname(), simcall->issuer_->get_pid(),
38 simcall->observer_->to_string().c_str());
39 XBT_INFO("***********************************************************************************");
40 if (not mc::actor_is_enabled(actor))
41 simgrid::kernel::EngineImpl::get_instance()->display_all_actor_status();
43 xbt_assert(simgrid::mc::actor_is_enabled(actor), "Actor %s (simcall %s) is not enabled.", actor->get_cname(),
44 simcall->get_cname());
46 // Execute the request:
47 simcall->issuer_->simcall_handle(transition->times_considered_);
48 simgrid::mc::execute_actors();
51 const auto& actor_list = engine->get_actor_list();
52 if (actor_list.empty()) {
53 XBT_INFO("The replay of the trace is complete. The application is terminating.");
54 } else if (std::none_of(std::begin(actor_list), std::end(actor_list),
55 [](const auto& kv) { return mc::actor_is_enabled(kv.second); })) {
56 XBT_INFO("The replay of the trace is complete. DEADLOCK detected.");
57 engine->display_all_actor_status();
59 XBT_INFO("The replay of the trace is complete. The application could run further.");
63 void simgrid::mc::RecordTrace::replay(const std::string& path_string)
65 simgrid::mc::processes_time.resize(kernel::actor::ActorImpl::get_maxpid());
66 simgrid::mc::RecordTrace trace(path_string.c_str());
68 for (auto* item : trace.transitions_)
70 simgrid::mc::processes_time.clear();
73 simgrid::mc::RecordTrace::RecordTrace(const char* data)
75 XBT_INFO("path=%s", data);
76 if (data == nullptr || data[0] == '\0')
77 throw std::invalid_argument("Could not parse record path");
79 const char* current = data;
82 int times_considered = 0;
84 if (int count = sscanf(current, "%ld/%d", &aid, ×_considered); count != 2 && count != 1)
85 throw std::invalid_argument("Could not parse record path");
86 push_back(new simgrid::mc::Transition(simgrid::mc::Transition::Type::UNKNOWN, aid, times_considered));
89 const char* end = std::strchr(current, ';');
97 std::string simgrid::mc::RecordTrace::to_string() const
99 std::ostringstream stream;
100 for (auto i = transitions_.begin(); i != transitions_.end(); ++i) {
103 if (i != transitions_.begin())
105 stream << (*i)->aid_;
106 if ((*i)->times_considered_ > 0)
107 stream << '/' << (*i)->times_considered_;
111 } // namespace simgrid::mc