Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid unsafe things
[simgrid.git] / src / msg / msg_actions.cpp
1 /* Copyright (c) 2009-2015. 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.h"
8
9 #include <errno.h>
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_action, msg, "MSG actions for trace driven simulation");
12
13 void MSG_action_init()
14 {
15   _xbt_replay_action_init();
16   MSG_function_register_default(xbt_replay_action_runner);
17 }
18
19 void MSG_action_exit()
20 {
21   _xbt_replay_action_exit();
22 }
23
24 /** \ingroup msg_trace_driven
25  * \brief A trace loader
26  *
27  *  If path!=nullptr, load a trace file containing actions, and execute them.
28  *  Else, assume that each process gets the path in its deployment file
29  */
30 msg_error_t MSG_action_trace_run(char *path)
31 {
32   msg_error_t res;
33   char *name;
34   xbt_dynar_t todo;
35   xbt_dict_cursor_t cursor;
36
37   xbt_action_fp=nullptr;
38   if (path) {
39     xbt_action_fp = fopen(path, "r");
40     xbt_assert(xbt_action_fp != nullptr, "Cannot open %s: %s", path, strerror(errno));
41   }
42   res = MSG_main();
43
44   if (!xbt_dict_is_empty(xbt_action_queues)) {
45     XBT_WARN("Not all actions got consumed. If the simulation ended successfully (without deadlock),"
46              " you may want to add new processes to your deployment file.");
47
48     xbt_dict_foreach(xbt_action_queues, cursor, name, todo) {
49       XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
50     }
51   }
52
53   if (path)
54     fclose(xbt_action_fp);
55   xbt_dict_free(&xbt_action_queues);
56   xbt_action_queues = xbt_dict_new_homogeneous(nullptr);
57
58   return res;
59 }