Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correctly disable DPOR when StateEq reduction is enabled
[simgrid.git] / src / mc / mc_record.cpp
1 /* Copyright (c) 2014-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
12
13 #if SIMGRID_HAVE_MC
14 #include "src/mc/api/State.hpp"
15 #include "src/mc/explo/Exploration.hpp"
16 #include "src/mc/mc_private.hpp"
17 #endif
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
20
21 namespace simgrid::mc {
22
23 void RecordTrace::replay() const
24 {
25   simgrid::mc::execute_actors();
26
27   for (const simgrid::mc::Transition* transition : transitions_) {
28     XBT_DEBUG("Executing %ld$%i", transition->aid_, transition->times_considered_);
29
30     // Choose a request:
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(simcall->call_ != kernel::actor::Simcall::Type::NONE, "No simcall for process %ld.", transition->aid_);
35     xbt_assert(simgrid::mc::request_is_visible(simcall) && simgrid::mc::actor_is_enabled(actor), "Unexpected simcall.");
36
37     // Execute the request:
38     simcall->issuer_->simcall_handle(transition->times_considered_);
39     simgrid::mc::execute_actors();
40   }
41 }
42
43 void simgrid::mc::RecordTrace::replay(const std::string& path_string)
44 {
45   simgrid::mc::processes_time.resize(kernel::actor::ActorImpl::get_maxpid());
46   simgrid::mc::RecordTrace trace(path_string.c_str());
47   trace.replay();
48   for (auto* item : trace.transitions_)
49     delete item;
50   simgrid::mc::processes_time.clear();
51 }
52
53 simgrid::mc::RecordTrace::RecordTrace(const char* data)
54 {
55   XBT_INFO("path=%s", data);
56   if (data == nullptr || data[0] == '\0')
57     throw std::invalid_argument("Could not parse record path");
58
59   const char* current = data;
60   while (*current) {
61     long aid;
62     int times_considered;
63
64     if (int count = sscanf(current, "%ld/%d", &aid, &times_considered); count != 2 && count != 1)
65       throw std::invalid_argument("Could not parse record path");
66     push_back(new simgrid::mc::Transition(simgrid::mc::Transition::Type::UNKNOWN, aid, times_considered));
67
68     // Find next chunk:
69     const char* end = std::strchr(current, ';');
70     if(end == nullptr)
71       break;
72     else
73       current = end + 1;
74   }
75 }
76
77 #if SIMGRID_HAVE_MC
78
79 std::string simgrid::mc::RecordTrace::to_string() const
80 {
81   std::ostringstream stream;
82   for (auto i = transitions_.begin(); i != transitions_.end(); ++i) {
83     if (i != transitions_.begin())
84       stream << ';';
85     stream << (*i)->aid_;
86     if ((*i)->times_considered_ > 0)
87       stream << '/' << (*i)->times_considered_;
88   }
89   return stream.str();
90 }
91
92 #endif
93
94 } // namespace simgrid::mc