Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ahem. You mean I need to actually compile with MC after moving files?
[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, "Logging specific to MC record/replay facility");
22
23 namespace simgrid {
24 namespace mc {
25
26 void replay(RecordTrace const& trace)
27 {
28   simgrid::mc::wait_for_requests();
29
30   for (simgrid::mc::Transition const& transition : trace) {
31     XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
32
33     // Choose a request:
34     smx_actor_t process = SIMIX_process_from_PID(transition.pid);
35     if (not process)
36       xbt_die("Unexpected process (pid:%d).", transition.pid);
37     smx_simcall_t simcall = &(process->simcall);
38     if (not simcall || simcall->call == SIMCALL_NONE)
39       xbt_die("No simcall for process %d.", transition.pid);
40     if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
41       xbt_die("Unexpected simcall.");
42
43     // Execute the request:
44     SIMIX_simcall_handle(simcall, transition.argument);
45     simgrid::mc::wait_for_requests();
46   }
47 }
48
49 void replay(const std::string& path_string)
50 {
51   simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
52   simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
53   simgrid::mc::replay(trace);
54   simgrid::mc::processes_time.clear();
55 }
56
57 RecordTrace parseRecordTrace(const char* data)
58 {
59   RecordTrace res;
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
67     simgrid::mc::Transition item;
68     int count = sscanf(current, "%d/%d", &item.pid, &item.argument);
69     if(count != 2 && count != 1)
70       throw std::invalid_argument("Could not parse record path");
71     res.push_back(item);
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   return res;
82 }
83
84 #if SIMGRID_HAVE_MC
85
86 std::string traceToString(simgrid::mc::RecordTrace const& trace)
87 {
88   std::ostringstream stream;
89   for (auto i = trace.begin(); i != trace.end(); ++i) {
90     if (i != trace.begin())
91       stream << ';';
92     stream << i->pid;
93     if (i->argument)
94       stream << '/' << i->argument;
95   }
96   return stream.str();
97 }
98
99 void dumpRecordPath()
100 {
101   RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
102   XBT_INFO("Path = %s", traceToString(trace).c_str());
103 }
104
105 #endif
106
107 }
108 }