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/kernel/context/Context.hpp"
21 #include "src/simix/ActorImpl.hpp"
22 #include "src/simix/smx_private.h"
23 #include "src/mc/mc_replay.h"
24 #include "src/mc/mc_record.h"
26 #include "src/mc/mc_base.h"
27 #include "src/mc/Transition.hpp"
30 #include "src/mc/mc_request.h"
31 #include "src/mc/mc_private.h"
32 #include "src/mc/mc_state.h"
33 #include "src/mc/mc_smx.h"
34 #include "src/mc/Checker.hpp"
37 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
38 " Logging specific to MC record/replay facility");
41 char* MC_record_path = nullptr;
47 void replay(RecordTrace const& trace)
49 simgrid::mc::wait_for_requests();
51 for (simgrid::mc::Transition const& transition : trace) {
52 XBT_DEBUG("Executing %i$%i", transition.pid, transition.argument);
55 smx_actor_t process = SIMIX_process_from_PID(transition.pid);
57 xbt_die("Unexpected process.");
58 smx_simcall_t simcall = &(process->simcall);
59 if(!simcall || simcall->call == SIMCALL_NONE)
60 xbt_die("No simcall for this process.");
61 if (!simgrid::mc::request_is_visible(simcall)
62 || !simgrid::mc::request_is_enabled(simcall))
63 xbt_die("Unexpected simcall.");
65 // Execute the request:
66 SIMIX_simcall_handle(simcall, transition.argument);
67 simgrid::mc::wait_for_requests();
71 void replay(const char* path_string)
73 simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
74 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string);
75 simgrid::mc::replay(trace);
76 simgrid::mc::processes_time.clear();
79 RecordTrace parseRecordTrace(const char* data)
82 XBT_INFO("path=%s", data);
83 if (data == nullptr || data[0] == '\0')
84 throw std::runtime_error("Could not parse record path");
86 const char* current = data;
89 simgrid::mc::Transition item;
90 int count = sscanf(current, "%u/%u", &item.pid, &item.argument);
91 if(count != 2 && count != 1)
92 throw std::runtime_error("Could not parse record path");
96 const char* end = std::strchr(current, ';');
108 std::string traceToString(simgrid::mc::RecordTrace const& trace)
110 std::ostringstream stream;
111 for (auto i = trace.begin(); i != trace.end(); ++i) {
112 if (i != trace.begin())
116 stream << '/' << i->argument;
121 void dumpRecordPath()
123 if (MC_record_is_active()) {
124 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
125 XBT_INFO("Path = %s", traceToString(trace).c_str());