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. */
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 #include "src/simix/ActorImpl.hpp"
15 #include "src/mc/checker/Checker.hpp"
16 #include "src/mc/mc_private.hpp"
17 #include "src/mc/mc_request.hpp"
18 #include "src/mc/mc_smx.hpp"
19 #include "src/mc/mc_state.hpp"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
23 " Logging specific to MC record/replay facility");
28 void replay(RecordTrace const& trace)
30 simgrid::mc::wait_for_requests();
32 for (simgrid::mc::Transition const& transition : trace) {
33 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
36 smx_actor_t process = SIMIX_process_from_PID(transition.pid);
38 xbt_die("Unexpected process (pid:%d).", transition.pid);
39 smx_simcall_t simcall = &(process->simcall);
40 if (not simcall || simcall->call == SIMCALL_NONE)
41 xbt_die("No simcall for process %d.", transition.pid);
42 if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(process))
43 xbt_die("Unexpected simcall.");
45 // Execute the request:
46 SIMIX_simcall_handle(simcall, transition.argument);
47 simgrid::mc::wait_for_requests();
51 void replay(std::string path_string)
53 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
54 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
55 simgrid::mc::replay(trace);
56 simgrid::mc::processes_time.clear();
59 RecordTrace parseRecordTrace(const char* data)
62 XBT_INFO("path=%s", data);
63 if (data == nullptr || data[0] == '\0')
64 throw std::invalid_argument("Could not parse record path");
66 const char* current = data;
69 simgrid::mc::Transition item;
70 int count = sscanf(current, "%d/%d", &item.pid, &item.argument);
71 if(count != 2 && count != 1)
72 throw std::invalid_argument("Could not parse record path");
76 const char* end = std::strchr(current, ';');
88 std::string traceToString(simgrid::mc::RecordTrace const& trace)
90 std::ostringstream stream;
91 for (auto i = trace.begin(); i != trace.end(); ++i) {
92 if (i != trace.begin())
96 stream << '/' << i->argument;
101 void dumpRecordPath()
103 if (MC_record_is_active()) {
104 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
105 XBT_INFO("Path = %s", traceToString(trace).c_str());