Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Be more verbose on the blocking transition when displaying the actor state on Ctrl-C
[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(simgrid::mc::request_is_visible(simcall), "Simcall %s of actor %s is not visible.", simcall->get_cname(),
35                actor->get_cname());
36     if (not mc::actor_is_enabled(actor))
37       simgrid::kernel::EngineImpl::get_instance()->display_all_actor_status();
38
39     xbt_assert(simgrid::mc::actor_is_enabled(actor), "Actor %s (simcall %s) is not enabled.", actor->get_cname(),
40                simcall->get_cname());
41
42     // Execute the request:
43     simcall->issuer_->simcall_handle(transition->times_considered_);
44     simgrid::mc::execute_actors();
45   }
46 }
47
48 void simgrid::mc::RecordTrace::replay(const std::string& path_string)
49 {
50   simgrid::mc::processes_time.resize(kernel::actor::ActorImpl::get_maxpid());
51   simgrid::mc::RecordTrace trace(path_string.c_str());
52   trace.replay();
53   for (auto* item : trace.transitions_)
54     delete item;
55   simgrid::mc::processes_time.clear();
56 }
57
58 simgrid::mc::RecordTrace::RecordTrace(const char* data)
59 {
60   XBT_INFO("path=%s", data);
61   if (data == nullptr || data[0] == '\0')
62     throw std::invalid_argument("Could not parse record path");
63
64   const char* current = data;
65   while (*current) {
66     long aid;
67     int times_considered = 0;
68
69     if (int count = sscanf(current, "%ld/%d", &aid, &times_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));
72
73     // Find next chunk:
74     const char* end = std::strchr(current, ';');
75     if(end == nullptr)
76       break;
77     else
78       current = end + 1;
79   }
80 }
81
82 #if SIMGRID_HAVE_MC
83
84 std::string simgrid::mc::RecordTrace::to_string() const
85 {
86   std::ostringstream stream;
87   for (auto i = transitions_.begin(); i != transitions_.end(); ++i) {
88     if (i != transitions_.begin())
89       stream << ';';
90     stream << (*i)->aid_;
91     if ((*i)->times_considered_ > 0)
92       stream << '/' << (*i)->times_considered_;
93   }
94   return stream.str();
95 }
96
97 #endif
98
99 } // namespace simgrid::mc