1 /* Copyright (c) 2014-2017. The SimGrid Team. All rights reserved. */
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. */
15 #include "xbt/sysdep.h"
17 #include "simgrid/simix.h"
19 #include "src/kernel/context/Context.hpp"
20 #include "src/mc/mc_record.hpp"
21 #include "src/mc/mc_replay.hpp"
22 #include "src/simix/ActorImpl.hpp"
23 #include "src/simix/smx_private.hpp"
25 #include "src/mc/mc_base.h"
26 #include "src/mc/Transition.hpp"
29 #include "src/mc/checker/Checker.hpp"
30 #include "src/mc/mc_private.hpp"
31 #include "src/mc/mc_request.hpp"
32 #include "src/mc/mc_smx.hpp"
33 #include "src/mc/mc_state.hpp"
36 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
37 " Logging specific to MC record/replay facility");
39 std::string MC_record_path;
44 void replay(RecordTrace const& trace)
46 simgrid::mc::wait_for_requests();
48 for (simgrid::mc::Transition const& transition : trace) {
49 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
52 smx_actor_t process = SIMIX_process_from_PID(transition.pid);
54 xbt_die("Unexpected process (pid:%d).", transition.pid);
55 smx_simcall_t simcall = &(process->simcall);
56 if (not simcall || simcall->call == SIMCALL_NONE)
57 xbt_die("No simcall for process %d.", transition.pid);
58 if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
59 xbt_die("Unexpected simcall.");
61 // Execute the request:
62 SIMIX_simcall_handle(simcall, transition.argument);
63 simgrid::mc::wait_for_requests();
67 void replay(std::string path_string)
69 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
70 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
71 simgrid::mc::replay(trace);
72 simgrid::mc::processes_time.clear();
75 RecordTrace parseRecordTrace(const char* data)
78 XBT_INFO("path=%s", data);
79 if (data == nullptr || data[0] == '\0')
80 throw std::invalid_argument("Could not parse record path");
82 const char* current = data;
85 simgrid::mc::Transition item;
86 int count = sscanf(current, "%d/%d", &item.pid, &item.argument);
87 if(count != 2 && count != 1)
88 throw std::invalid_argument("Could not parse record path");
92 const char* end = std::strchr(current, ';');
104 std::string traceToString(simgrid::mc::RecordTrace const& trace)
106 std::ostringstream stream;
107 for (auto i = trace.begin(); i != trace.end(); ++i) {
108 if (i != trace.begin())
112 stream << '/' << i->argument;
117 void dumpRecordPath()
119 if (MC_record_is_active()) {
120 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
121 XBT_INFO("Path = %s", traceToString(trace).c_str());