1 /* Copyright (c) 2014-2019. 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"
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"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
22 " Logging specific to MC record/replay facility");
27 void replay(RecordTrace const& trace)
29 simgrid::mc::wait_for_requests();
31 for (simgrid::mc::Transition const& transition : trace) {
32 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
35 smx_actor_t process = SIMIX_process_from_PID(transition.pid);
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.");
44 // Execute the request:
45 SIMIX_simcall_handle(simcall, transition.argument);
46 simgrid::mc::wait_for_requests();
50 void replay(const std::string& path_string)
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();
58 RecordTrace parseRecordTrace(const char* data)
61 XBT_INFO("path=%s", data);
62 if (data == nullptr || data[0] == '\0')
63 throw std::invalid_argument("Could not parse record path");
65 const char* current = data;
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");
75 const char* end = std::strchr(current, ';');
87 std::string traceToString(simgrid::mc::RecordTrace const& trace)
89 std::ostringstream stream;
90 for (auto i = trace.begin(); i != trace.end(); ++i) {
91 if (i != trace.begin())
95 stream << '/' << i->argument;
100 void dumpRecordPath()
102 if (MC_record_is_active()) {
103 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
104 XBT_INFO("Path = %s", traceToString(trace).c_str());