Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d780d3c3d8522bbc3eef3c8d6dbf457b75992419
[simgrid.git] / src / instr / jedule / jedule_sd_binding.c
1 /* Copyright (c) 2010-2015. 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 "xbt/asserts.h"
8 #include "xbt/dynar.h"
9
10 #include "src/surf/surf_private.h"
11 #include "surf/surf.h"
12
13 #include "simgrid/jedule/jedule_sd_binding.h"
14 #include "simgrid/jedule/jedule_events.h"
15 #include "simgrid/jedule/jedule_platform.h"
16 #include "simgrid/jedule/jedule_output.h"
17
18 #include "simgrid/simdag.h"
19 #include "src/simdag/simdag_private.h"
20
21 #include <stdio.h>
22
23 #ifdef HAVE_JEDULE
24
25 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule,
27                                 "Logging specific to Jedule SD binding");
28
29 jedule_t jedule;
30
31 void jedule_log_sd_event(SD_task_t task)
32 {
33   xbt_dynar_t host_list;
34   jed_event_t event;
35   int i;
36
37   xbt_assert(task != NULL);
38
39   host_list = xbt_dynar_new(sizeof(char*), NULL);
40
41   for(i=0; i<task->host_count; i++) {
42     const char *hostname = sg_host_get_name(task->host_list[i]);
43     xbt_dynar_push(host_list, &hostname);
44   }
45
46   create_jed_event(&event, (char*)SD_task_get_name(task),
47       task->start_time, task->finish_time,"SD");
48
49   jed_event_add_resources(event, host_list);
50   jedule_store_event(event);
51
52   xbt_dynar_free(&host_list);
53 }
54
55 static void create_hierarchy(AS_t current_comp,
56                              jed_simgrid_container_t current_container)
57 {
58   xbt_dict_cursor_t cursor = NULL;
59   char *key;
60   AS_t elem;
61   xbt_dict_t routing_sons = surf_AS_get_routing_sons(current_comp);
62
63   if (xbt_dict_is_empty(routing_sons)) {
64     // I am no AS
65     // add hosts to jedule platform
66     xbt_dynar_t table = surf_AS_get_hosts(current_comp);
67     xbt_dynar_t hosts;
68     unsigned int dynar_cursor;
69     sg_host_t host_elem;
70
71     hosts = xbt_dynar_new(sizeof(char*), NULL);
72
73     xbt_dynar_foreach(table, dynar_cursor, host_elem) {
74       xbt_dynar_push_as(hosts, const char*, sg_host_get_name(host_elem));
75     }
76
77     jed_simgrid_add_resources(current_container, hosts);
78     xbt_dynar_free(&hosts);
79     xbt_dynar_free(&table);
80   } else {
81     xbt_dict_foreach(routing_sons, cursor, key, elem) {
82       jed_simgrid_container_t child_container;
83       jed_simgrid_create_container(&child_container, surf_AS_get_name(elem));
84       jed_simgrid_add_container(current_container, child_container);
85       XBT_DEBUG("name : %s\n", surf_AS_get_name(elem));
86       create_hierarchy(elem, child_container);
87     }
88   }
89 }
90
91 void jedule_setup_platform()
92 {
93   AS_t root_comp;
94
95   jed_simgrid_container_t root_container;
96
97   jed_create_jedule(&jedule);
98
99   root_comp = surf_AS_get_routing_root();
100   XBT_DEBUG("root name %s\n", surf_AS_get_name(root_comp));
101
102   jed_simgrid_create_container(&root_container, surf_AS_get_name(root_comp));
103   jedule->root_container = root_container;
104
105   create_hierarchy(root_comp, root_container);
106 }
107
108
109 void jedule_sd_cleanup()
110 {
111   jedule_cleanup_output();
112 }
113
114 void jedule_sd_init()
115 {
116   jedule_init_output();
117 }
118
119 void jedule_sd_exit(void)
120 {
121   if (jedule) {
122     jed_free_jedule(jedule);
123     jedule = NULL;
124   }
125 }
126
127 void jedule_sd_dump(const char * filename)
128 {
129   if (jedule) {
130     char *fname;
131     FILE *fh;
132     if (!filename) {
133       fname = bprintf("%s.jed", xbt_binary_name);
134     } else {
135       fname = xbt_strdup(filename);
136     }
137
138     fh = fopen(fname, "w");
139
140     write_jedule_output(fh, jedule, jedule_event_list, NULL);
141
142     fclose(fh);
143     free(fname);
144   }
145 }
146
147 #endif