#include "xbt/dict.h"
#ifdef __cplusplus
#include <fstream>
+#include <queue>
+#include <unordered_map>
namespace simgrid {
namespace xbt {
/* To split the file if a unique one is given (specific variable for the other case live in runner()) */
+typedef std::vector<std::string> ReplayAction;
+static std::unordered_map<std::string, std::queue<ReplayAction*>*> action_queues;
+
XBT_PUBLIC_DATA(std::ifstream*) action_fs;
XBT_PUBLIC(bool) replay_is_active();
XBT_PUBLIC(void) replay_init();
SG_BEGIN_DECL()
typedef void (*action_fun)(const char* const* args);
-XBT_PUBLIC_DATA(xbt_dict_t) xbt_action_queues;
XBT_PUBLIC(void) xbt_replay_action_register(const char* action_name, action_fun function);
SG_END_DECL()
*/
msg_error_t MSG_action_trace_run(char *path)
{
- msg_error_t res;
- char *name;
- xbt_dynar_t todo;
- xbt_dict_cursor_t cursor;
-
if (path) {
simgrid::xbt::action_fs = new std::ifstream(path, std::ifstream::in);
}
- res = MSG_main();
- if (!xbt_dict_is_empty(xbt_action_queues)) {
+ msg_error_t res = MSG_main();
+
+ if (!simgrid::xbt::action_queues.empty()) {
XBT_WARN("Not all actions got consumed. If the simulation ended successfully (without deadlock),"
" you may want to add new processes to your deployment file.");
- xbt_dict_foreach(xbt_action_queues, cursor, name, todo) {
- XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
+ for (auto actions_of : simgrid::xbt::action_queues) {
+ XBT_WARN("Still %zu actions for %s", actions_of.second->size(), actions_of.first.c_str());
}
}
simgrid::xbt::action_fs = nullptr;
}
- xbt_dict_free(&xbt_action_queues);
- xbt_action_queues = xbt_dict_new_homogeneous(nullptr);
-
return res;
}
#include <boost/algorithm/string.hpp>
#include <ctype.h>
#include <errno.h>
-#include <fstream>
-#include <queue>
-#include <unordered_map>
#include <wchar.h>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(replay,xbt,"Replay trace reader");
-xbt_dict_t xbt_action_queues = nullptr;
bool is_replay_active = false;
namespace simgrid {
std::ifstream* action_fs = nullptr;
std::unordered_map<std::string, action_fun> action_funs;
-typedef std::vector<std::string> ReplayAction;
static void read_and_trim_line(std::ifstream* fs, std::string* line)
{
void replay_init()
{
if (!is_replay_active) {
- xbt_action_queues = xbt_dict_new_homogeneous(nullptr);
is_replay_active = true;
}
}
void replay_exit()
{
- xbt_dict_free(&xbt_action_queues);
- xbt_action_queues = nullptr;
}
bool replay_is_active()
{
ReplayAction* action;
- std::queue<ReplayAction*>* myqueue =
- static_cast<std::queue<ReplayAction*>*>(xbt_dict_get_or_null(xbt_action_queues, name));
+ std::queue<ReplayAction*>* myqueue = nullptr;
+ if (action_queues.find(std::string(name)) != action_queues.end())
+ myqueue = action_queues.at(std::string(name));
if (myqueue == nullptr || myqueue->empty()) { // Nothing stored for me. Read the file further
if (action_fs == nullptr) { // File closed now. There's nothing more to read. I'm out of here
goto todo_done;
return action;
} else {
// Else, I have to store it for the relevant colleague
- std::queue<ReplayAction*>* otherqueue =
- static_cast<std::queue<ReplayAction*>*>(xbt_dict_get_or_null(xbt_action_queues, evtname.c_str()));
+ std::queue<ReplayAction*>* otherqueue = nullptr;
+ if (action_queues.find(evtname) != action_queues.end())
+ otherqueue = action_queues.at(evtname);
if (otherqueue == nullptr) { // Damn. Create the queue of that guy
otherqueue = new std::queue<ReplayAction*>();
- xbt_dict_set(xbt_action_queues, evtname.c_str(), otherqueue, nullptr);
+ action_queues.insert({evtname, otherqueue});
}
otherqueue->push(action);
}
todo_done:
if (myqueue != nullptr) {
delete myqueue;
- xbt_dict_remove(xbt_action_queues, name);
+ action_queues.erase(std::string(name));
}
return nullptr;
}