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/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();
27 for (const simgrid::mc::Transition* transition : transitions_) {
28 XBT_DEBUG("Executing %ld$%i", transition->aid_, transition->times_considered_);
31 kernel::actor::ActorImpl* actor = kernel::EngineImpl::get_instance()->get_actor_by_pid(transition->aid_);
32 xbt_assert(actor != nullptr, "Unexpected actor (id:%ld).", transition->aid_);
33 const kernel::actor::Simcall* simcall = &(actor->simcall_);
34 xbt_assert(simgrid::mc::request_is_visible(simcall), "Simcall %s of actor %s is not visible.", simcall->get_cname(),
36 if (not mc::actor_is_enabled(actor))
37 simgrid::kernel::EngineImpl::get_instance()->display_all_actor_status();
39 xbt_assert(simgrid::mc::actor_is_enabled(actor), "Actor %s (simcall %s) is not enabled.", actor->get_cname(),
40 simcall->get_cname());
42 // Execute the request:
43 simcall->issuer_->simcall_handle(transition->times_considered_);
44 simgrid::mc::execute_actors();
48 void simgrid::mc::RecordTrace::replay(const std::string& path_string)
50 simgrid::mc::processes_time.resize(kernel::actor::ActorImpl::get_maxpid());
51 simgrid::mc::RecordTrace trace(path_string.c_str());
53 for (auto* item : trace.transitions_)
55 simgrid::mc::processes_time.clear();
58 simgrid::mc::RecordTrace::RecordTrace(const char* data)
60 XBT_INFO("path=%s", data);
61 if (data == nullptr || data[0] == '\0')
62 throw std::invalid_argument("Could not parse record path");
64 const char* current = data;
67 int times_considered = 0;
69 if (int count = sscanf(current, "%ld/%d", &aid, ×_considered); count != 2 && count != 1)
70 throw std::invalid_argument("Could not parse record path");
71 push_back(new simgrid::mc::Transition(simgrid::mc::Transition::Type::UNKNOWN, aid, times_considered));
74 const char* end = std::strchr(current, ';');
84 std::string simgrid::mc::RecordTrace::to_string() const
86 std::ostringstream stream;
87 for (auto i = transitions_.begin(); i != transitions_.end(); ++i) {
88 if (i != transitions_.begin())
91 if ((*i)->times_considered_ > 0)
92 stream << '/' << (*i)->times_considered_;
99 } // namespace simgrid::mc