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"
28 #include "src/mc/mc_request.h"
29 #include "src/mc/mc_private.h"
30 #include "src/mc/mc_state.h"
31 #include "src/mc/mc_smx.h"
32 #include "src/mc/Checker.hpp"
35 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc,
36 " Logging specific to MC record/replay facility");
39 char* MC_record_path = nullptr;
45 void replay(RecordTrace const& trace)
47 simgrid::mc::wait_for_requests();
49 for (auto& item : trace) {
50 XBT_DEBUG("Executing %i$%i", item.pid, item.value);
53 smx_process_t process = SIMIX_process_from_PID(item.pid);
55 xbt_die("Unexpected process.");
56 smx_simcall_t simcall = &(process->simcall);
57 if(!simcall || simcall->call == SIMCALL_NONE)
58 xbt_die("No simcall for this process.");
59 if (!simgrid::mc::request_is_visible(simcall)
60 || !simgrid::mc::request_is_enabled(simcall))
61 xbt_die("Unexpected simcall.");
63 // Execute the request:
64 SIMIX_simcall_handle(simcall, item.value);
65 simgrid::mc::wait_for_requests();
69 void replay(const char* path_string)
71 simgrid::mc::processes_time.resize(simix_process_maxpid);
72 simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string);
73 simgrid::mc::replay(trace);
74 simgrid::mc::processes_time.clear();
77 RecordTrace parseRecordTrace(const char* data)
80 XBT_INFO("path=%s", data);
81 if (!data || !data[0])
82 throw std::runtime_error("Could not parse record path");
84 const char* current = data;
87 simgrid::mc::RecordTraceElement item;
88 int count = sscanf(current, "%u/%u", &item.pid, &item.value);
89 if(count != 2 && count != 1)
90 throw std::runtime_error("Could not parse record path");
94 const char* end = std::strchr(current, ';');
106 std::string traceToString(simgrid::mc::RecordTrace const& trace)
108 std::ostringstream stream;
109 for (auto i = trace.begin(); i != trace.end(); ++i) {
110 if (i != trace.begin())
114 stream << '/' << i->value;
119 void dumpRecordPath()
121 if (MC_record_is_active()) {
122 RecordTrace trace = mc_model_checker->getChecker()->getRecordTrace();
123 XBT_INFO("Path = %s", traceToString(trace).c_str());