Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless declaration of default destructor.
[simgrid.git] / src / mc / mc_record.cpp
1 /* Copyright (c) 2014-2021. 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/activity/CommImpl.hpp"
8 #include "src/kernel/context/Context.hpp"
9 #include "src/mc/Transition.hpp"
10 #include "src/mc/mc_base.hpp"
11 #include "src/mc/mc_replay.hpp"
12
13 #if SIMGRID_HAVE_MC
14 #include "src/mc/checker/Checker.hpp"
15 #include "src/mc/mc_private.hpp"
16 #include "src/mc/mc_request.hpp"
17 #include "src/mc/mc_state.hpp"
18 #endif
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, "Logging specific to MC record/replay facility");
21
22 namespace simgrid {
23 namespace mc {
24
25 void replay(RecordTrace const& trace)
26 {
27   simgrid::mc::wait_for_requests();
28
29   for (simgrid::mc::Transition const& transition : trace) {
30     XBT_DEBUG("Executing %i$%i", transition.pid_, transition.times_considered_);
31
32     // Choose a request:
33     kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_PID(transition.pid_);
34     if (actor == nullptr)
35       xbt_die("Unexpected actor (id:%d).", transition.pid_);
36     const s_smx_simcall* simcall = &(actor->simcall_);
37     if (simcall->call_ == simix::Simcall::NONE)
38       xbt_die("No simcall for process %d.", transition.pid_);
39     if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(actor))
40       xbt_die("Unexpected simcall.");
41
42     // Execute the request:
43     simcall->issuer_->simcall_handle(transition.times_considered_);
44     simgrid::mc::wait_for_requests();
45   }
46 }
47
48 void replay(const std::string& path_string)
49 {
50   simgrid::mc::processes_time.resize(simgrid::kernel::actor::get_maxpid());
51   simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
52   simgrid::mc::replay(trace);
53   simgrid::mc::processes_time.clear();
54 }
55
56 RecordTrace parseRecordTrace(const char* data)
57 {
58   RecordTrace res;
59   XBT_INFO("path=%s", data);
60   if (data == nullptr || data[0] == '\0')
61     throw std::invalid_argument("Could not parse record path");
62
63   const char* current = data;
64   while (*current) {
65     simgrid::mc::Transition item;
66     int count = sscanf(current, "%d/%d", &item.pid_, &item.times_considered_);
67
68     if(count != 2 && count != 1)
69       throw std::invalid_argument("Could not parse record path");
70     res.push_back(item);
71
72     // Find next chunk:
73     const char* end = std::strchr(current, ';');
74     if(end == nullptr)
75       break;
76     else
77       current = end + 1;
78   }
79
80   return res;
81 }
82
83 #if SIMGRID_HAVE_MC
84
85 std::string traceToString(simgrid::mc::RecordTrace const& trace)
86 {
87   std::ostringstream stream;
88   for (auto i = trace.begin(); i != trace.end(); ++i) {
89     if (i != trace.begin())
90       stream << ';';
91     stream << i->pid_;
92     if (i->times_considered_)
93       stream << '/' << i->times_considered_;
94   }
95   return stream.str();
96 }
97
98 void dumpRecordPath()
99 {
100   RecordTrace trace = mc_model_checker->getChecker()->get_record_trace();
101   XBT_INFO("Path = %s", traceToString(trace).c_str());
102 }
103
104 #endif
105
106 }
107 }