1 /* Copyright (c) 2014-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
16 #include <xbt/sysdep.h>
18 #include "simgrid/simix.h"
20 #include "src/simix/smx_private.h"
21 #include "src/simix/smx_process_private.h"
23 #include "src/mc/mc_replay.h"
24 #include "src/mc/mc_record.h"
25 #include "src/mc/mc_base.h"
26 #include "src/mc/Transition.hpp"
29 #include "src/mc/mc_request.h"
30 #include "src/mc/mc_private.h"
31 #include "src/mc/mc_state.h"
32 #include "src/mc/mc_smx.h"
33 #include "src/mc/Checker.hpp"
36 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
37 " Logging specific to MC record/replay facility");
40 char* MC_record_path = nullptr;
46 void replay(RecordTrace const& trace)
48 simgrid::mc::wait_for_requests();
50 for (simgrid::mc::Transition const& transition : trace) {
51 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
54 smx_process_t process = SIMIX_process_from_PID(transition.pid);
56 xbt_die("Unexpected process.");
57 smx_simcall_t simcall = &(process->simcall);
58 if(!simcall || simcall->call == SIMCALL_NONE)
59 xbt_die("No simcall for this process.");
60 if (!simgrid::mc::request_is_visible(simcall)
61 || !simgrid::mc::request_is_enabled(simcall))
62 xbt_die("Unexpected simcall.");
64 // Execute the request:
65 SIMIX_simcall_handle(simcall, transition.argument);
66 simgrid::mc::wait_for_requests();
70 void replay(const char* path_string)
72 simgrid::mc::processes_time.resize(simix_process_maxpid);
73 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string);
74 simgrid::mc::replay(trace);
75 simgrid::mc::processes_time.clear();
78 RecordTrace parseRecordTrace(const char* data)
81 XBT_INFO("path=%s", data);
82 if (!data || !data[0])
83 throw std::runtime_error("Could not parse record path");
85 const char* current = data;
88 simgrid::mc::Transition item;
89 int count = sscanf(current, "%u/%u", &item.pid, &item.argument);
90 if(count != 2 && count != 1)
91 throw std::runtime_error("Could not parse record path");
95 const char* end = std::strchr(current, ';');
107 std::string traceToString(simgrid::mc::RecordTrace const& trace)
109 std::ostringstream stream;
110 for (auto i = trace.begin(); i != trace.end(); ++i) {
111 if (i != trace.begin())
115 stream << '/' << i->argument;
120 void dumpRecordPath()
122 if (MC_record_is_active()) {
123 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
124 XBT_INFO("Path = %s", traceToString(trace).c_str());