Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / msg / msg_actions.cpp
1 /* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/msg/msg_private.h"
7 #include "xbt/replay.hpp"
8
9 #include <cerrno>
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_action, msg, "MSG actions for trace driven simulation");
12
13 SG_BEGIN_DECL()
14
15 void MSG_action_init()
16 {
17   MSG_function_register_default(simgrid::xbt::replay_runner);
18 }
19
20 void MSG_action_exit()
21 {
22   // Nothing to do anymore here
23 }
24
25 /** \ingroup msg_trace_driven
26  * \brief A trace loader
27  *
28  *  If path!=nullptr, load a trace file containing actions, and execute them.
29  *  Else, assume that each process gets the path in its deployment file
30  */
31 msg_error_t MSG_action_trace_run(char *path)
32 {
33   if (path) {
34     simgrid::xbt::action_fs = new std::ifstream(path, std::ifstream::in);
35   }
36
37   msg_error_t res = MSG_main();
38
39   if (not simgrid::xbt::action_queues.empty()) {
40     XBT_WARN("Not all actions got consumed. If the simulation ended successfully (without deadlock),"
41              " you may want to add new processes to your deployment file.");
42
43     for (auto actions_of : simgrid::xbt::action_queues) {
44       XBT_WARN("Still %zu actions for %s", actions_of.second->size(), actions_of.first.c_str());
45     }
46   }
47
48   if (path) {
49     delete simgrid::xbt::action_fs;
50     simgrid::xbt::action_fs = nullptr;
51   }
52
53   return res;
54 }
55
56 SG_END_DECL()