1 /* Copyright (c) 2014-2018. 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");
42 void replay(RecordTrace const& trace)
44 simgrid::mc::wait_for_requests();
46 for (simgrid::mc::Transition const& transition : trace) {
47 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
50 smx_actor_t process = SIMIX_process_from_PID(transition.pid);
52 xbt_die("Unexpected process (pid:%d).", transition.pid);
53 smx_simcall_t simcall = &(process->simcall);
54 if (not simcall || simcall->call == SIMCALL_NONE)
55 xbt_die("No simcall for process %d.", transition.pid);
56 if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
57 xbt_die("Unexpected simcall.");
59 // Execute the request:
60 SIMIX_simcall_handle(simcall, transition.argument);
61 simgrid::mc::wait_for_requests();
65 void replay(std::string path_string)
67 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
68 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
69 simgrid::mc::replay(trace);
70 simgrid::mc::processes_time.clear();
73 RecordTrace parseRecordTrace(const char* data)
76 XBT_INFO("path=%s", data);
77 if (data == nullptr || data[0] == '\0')
78 throw std::invalid_argument("Could not parse record path");
80 const char* current = data;
83 simgrid::mc::Transition item;
84 int count = sscanf(current, "%d/%d", &item.pid, &item.argument);
85 if(count != 2 && count != 1)
86 throw std::invalid_argument("Could not parse record path");
90 const char* end = std::strchr(current, ';');
102 std::string traceToString(simgrid::mc::RecordTrace const& trace)
104 std::ostringstream stream;
105 for (auto i = trace.begin(); i != trace.end(); ++i) {
106 if (i != trace.begin())
110 stream << '/' << i->argument;
115 void dumpRecordPath()
117 if (MC_record_is_active()) {
118 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
119 XBT_INFO("Path = %s", traceToString(trace).c_str());