Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove/add a few includes.
[simgrid.git] / src / msg / msg_actions.c
1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "simgrid_config.h" //For getline, keep that include first
8
9 #include "msg_private.h"
10 #include "xbt/str.h"
11 #include "xbt/dynar.h"
12 #include "xbt/replay.h"
13
14 #include <errno.h>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_action, msg,
17                                 "MSG actions for trace driven simulation");
18
19
20 void _MSG_action_init()
21 {
22   _xbt_replay_action_init();
23   MSG_function_register_default(xbt_replay_action_runner);
24 }
25
26 void _MSG_action_exit()
27 {
28   _xbt_replay_action_exit();
29 }
30
31
32
33 /** \ingroup msg_trace_driven
34  * \brief A trace loader
35  *
36  *  If path!=NULL, load a trace file containing actions, and execute them.
37  *  Else, assume that each process gets the path in its deployment file
38  */
39 msg_error_t MSG_action_trace_run(char *path)
40 {
41   msg_error_t res;
42   char *name;
43   xbt_dynar_t todo;
44   xbt_dict_cursor_t cursor;
45
46   action_fp=NULL;  
47   if (path) {
48     action_fp = fopen(path, "r");
49     xbt_assert(action_fp != NULL, "Cannot open %s: %s", path,
50                 strerror(errno));
51   }
52   res = MSG_main();
53
54   if (!xbt_dict_is_empty(action_queues)) {
55     XBT_WARN
56         ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file.");
57
58
59     xbt_dict_foreach(action_queues, cursor, name, todo) {
60       XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
61     }
62   }
63
64   if (path)
65     fclose(action_fp);
66   xbt_dict_free(&action_queues);
67   action_queues = xbt_dict_new_homogeneous(NULL);
68
69   return res;
70 }