Logo AND Algorithmique Numérique Distribuée

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