Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
commit f00F8da2 broke the binding between SD and jedule
[simgrid.git] / src / instr / jedule / jedule_sd_binding.c
1 /*
2  * jedule_sd_binding.c
3  *
4  *  Created on: Dec 2, 2010
5  *      Author: sascha
6  */
7
8
9 #include <stdio.h>
10
11 #include "xbt/asserts.h"
12 #include "xbt/dynar.h"
13
14 #include "surf/surf_private.h"
15 #include "surf/surf_resource.h"
16 #include "surf/surf.h"
17
18 #include "instr/jedule/jedule_sd_binding.h"
19 #include "instr/jedule/jedule_events.h"
20 #include "instr/jedule/jedule_platform.h"
21 #include "instr/jedule/jedule_output.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         xbt_dynar_t host_list;
33         jed_event_t event;
34         int i;
35
36         xbt_assert(task != NULL);
37
38         host_list = xbt_dynar_new(sizeof(char*), NULL);
39
40         for(i=0; i<task->workstation_nb; i++) {
41                 char *hostname = (char*)surf_resource_name(task->workstation_list[i]->surf_workstation);
42                 xbt_dynar_push(host_list, &hostname);
43         }
44
45         create_jed_event(&event,
46                         (char*)SD_task_get_name(task),
47                         task->start_time,
48                         task->finish_time,
49                         "SD");
50
51         jed_event_add_resources(event, host_list);
52         jedule_store_event(event);
53
54         xbt_dynar_free(&host_list);
55 }
56
57 static void create_hierarchy(AS_t current_comp,
58                 jed_simgrid_container_t current_container) {
59         xbt_dict_cursor_t cursor = NULL;
60         unsigned int dynar_cursor;
61         char *key;
62         AS_t elem;
63         network_element_t network_elem;
64
65         if(xbt_dict_is_empty(current_comp->routing_sons)) {
66                 // I am no AS
67                 // add hosts to jedule platform
68                 xbt_dynar_t hosts;
69
70                 hosts = xbt_dynar_new(sizeof(char*), NULL);
71
72                 xbt_dynar_foreach(current_comp->index_network_elm, 
73                                   dynar_cursor, network_elem) {
74                         char *hostname;
75                         hostname = strdup(network_elem->name);
76                         xbt_dynar_push(hosts, &hostname);
77                 }
78
79                 jed_simgrid_add_resources(current_container, hosts);
80
81         } else {
82                 xbt_dict_foreach(current_comp->routing_sons, cursor, key, elem) {
83                         jed_simgrid_container_t child_container;
84                         jed_simgrid_create_container(&child_container, elem->name);
85                         jed_simgrid_add_container(current_container, child_container);
86                         XBT_DEBUG("name : %s\n", elem->name);
87                         create_hierarchy(elem, child_container);
88                 }
89         }
90 }
91
92 void jedule_setup_platform() {
93
94         AS_t root_comp;
95         // e_surf_network_element_type_t type;
96
97         jed_simgrid_container_t root_container;
98
99
100         jed_create_jedule(&jedule);
101
102         root_comp = global_routing->root;
103         XBT_DEBUG("root name %s\n", root_comp->name);
104
105         // that doesn't work
106         // type = root_comp->get_network_element_type(root_comp->name);
107
108         jed_simgrid_create_container(&root_container, root_comp->name);
109         jedule->root_container = root_container;
110
111         create_hierarchy(root_comp, root_container);
112
113 }
114
115
116 void jedule_sd_cleanup() {
117
118         jedule_cleanup_output();
119 }
120
121 void jedule_sd_init() {
122
123         XBT_LOG_CONNECT(jed_sd, jedule);
124
125         jedule_init_output();
126 }
127
128 void jedule_sd_dump() {
129         FILE *fh;
130
131         fh = fopen("simgrid.jed", "w");
132
133         write_jedule_output(fh, jedule, jedule_event_list, NULL);
134
135         fclose(fh);
136
137 }
138
139 #endif