Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove declarations for never used signal slots.
[simgrid.git] / src / mc / mc_record.cpp
1 /* Copyright (c) 2014-2019. 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.h"
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_smx.hpp"
18 #include "src/mc/mc_state.hpp"
19 #endif
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
22   " Logging specific to MC record/replay facility");
23
24 namespace simgrid {
25 namespace mc {
26
27 void replay(RecordTrace const& trace)
28 {
29   simgrid::mc::wait_for_requests();
30
31   for (simgrid::mc::Transition const& transition : trace) {
32     XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
33
34     // Choose a request:
35     smx_actor_t process = SIMIX_process_from_PID(transition.pid);
36     if (not process)
37       xbt_die("Unexpected process (pid:%d).", transition.pid);
38     smx_simcall_t simcall = &(process->simcall);
39     if (not simcall || simcall->call == SIMCALL_NONE)
40       xbt_die("No simcall for process %d.", transition.pid);
41     if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
42       xbt_die("Unexpected simcall.");
43
44     // Execute the request:
45     SIMIX_simcall_handle(simcall, transition.argument);
46     simgrid::mc::wait_for_requests();
47   }
48 }
49
50 void replay(const std::string& path_string)
51 {
52   simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
53   simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
54   simgrid::mc::replay(trace);
55   simgrid::mc::processes_time.clear();
56 }
57
58 RecordTrace parseRecordTrace(const char* data)
59 {
60   RecordTrace res;
61   XBT_INFO("path=%s", data);
62   if (data == nullptr || data[0] == '\0')
63     throw std::invalid_argument("Could not parse record path");
64
65   const char* current = data;
66   while (*current) {
67
68     simgrid::mc::Transition item;
69     int count = sscanf(current, "%d/%d", &item.pid, &item.argument);
70     if(count != 2 && count != 1)
71       throw std::invalid_argument("Could not parse record path");
72     res.push_back(item);
73
74     // Find next chunk:
75     const char* end = std::strchr(current, ';');
76     if(end == nullptr)
77       break;
78     else
79       current = end + 1;
80   }
81
82   return res;
83 }
84
85 #if SIMGRID_HAVE_MC
86
87 std::string traceToString(simgrid::mc::RecordTrace const& trace)
88 {
89   std::ostringstream stream;
90   for (auto i = trace.begin(); i != trace.end(); ++i) {
91     if (i != trace.begin())
92       stream << ';';
93     stream << i->pid;
94     if (i->argument)
95       stream << '/' << i->argument;
96   }
97   return stream.str();
98 }
99
100 void dumpRecordPath()
101 {
102   if (MC_record_is_active()) {
103     RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
104     XBT_INFO("Path = %s", traceToString(trace).c_str());
105   }
106 }
107
108 #endif
109
110 }
111 }