Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename routing_component to as, since that's just an AS at the end of the day
[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.h"
16
17 #include "instr/jedule/jedule_sd_binding.h"
18 #include "instr/jedule/jedule_events.h"
19 #include "instr/jedule/jedule_platform.h"
20 #include "instr/jedule/jedule_output.h"
21
22 #ifdef HAVE_JEDULE
23
24 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule,
26                                 "Logging specific to Jedule SD binding");
27
28 jedule_t jedule;
29
30 void jedule_log_sd_event(SD_task_t task) {
31         xbt_dynar_t host_list;
32         jed_event_t event;
33         int i;
34
35         xbt_assert(task != NULL);
36
37         host_list = xbt_dynar_new(sizeof(char*), NULL);
38
39         for(i=0; i<task->workstation_nb; i++) {
40                 char *hostname = (char*)surf_resource_name(task->workstation_list[i]->surf_workstation);
41                 xbt_dynar_push(host_list, &hostname);
42         }
43
44         create_jed_event(&event,
45                         (char*)SD_task_get_name(task),
46                         task->start_time,
47                         task->finish_time,
48                         "SD");
49
50         jed_event_add_resources(event, host_list);
51         jedule_store_event(event);
52
53         xbt_dynar_free(&host_list);
54 }
55
56 static void create_hierarchy(AS_t current_comp,
57                 jed_simgrid_container_t current_container) {
58         xbt_dict_cursor_t cursor = NULL;
59         char *key;
60         AS_t elem;
61         network_element_t network_elem;
62
63         if( xbt_dict_length(current_comp->routing_sons) == 0 ) {
64                 // I am no AS
65                 // add hosts to jedule platform
66                 xbt_dynar_t hosts;
67
68                 hosts = xbt_dynar_new(sizeof(char*), NULL);
69
70                 xbt_dict_foreach(current_comp->to_index, cursor, key, network_elem) {
71                         char *hostname;
72                         XBT_DEBUG("key %s value %p\n", key, network_elem);
73                         //xbt_dynar_push_as(hosts, char*, key);
74                         hostname = strdup(key);
75                         xbt_dynar_push(hosts, &hostname);
76                 }
77
78                 jed_simgrid_add_resources(current_container, hosts);
79
80         } else {
81                 xbt_dict_foreach(current_comp->routing_sons, cursor, key, elem) {
82                         jed_simgrid_container_t child_container;
83                         jed_simgrid_create_container(&child_container, elem->name);
84                         jed_simgrid_add_container(current_container, child_container);
85                         XBT_DEBUG("name : %s\n", elem->name);
86                         create_hierarchy(elem, child_container);
87                 }
88         }
89 }
90
91 void jedule_setup_platform() {
92
93         AS_t root_comp;
94         // e_surf_network_element_type_t type;
95
96         jed_simgrid_container_t root_container;
97
98
99         jed_create_jedule(&jedule);
100
101         root_comp = global_routing->root;
102         XBT_DEBUG("root name %s\n", root_comp->name);
103
104         // that doesn't work
105         // type = root_comp->get_network_element_type(root_comp->name);
106
107         jed_simgrid_create_container(&root_container, root_comp->name);
108         jedule->root_container = root_container;
109
110         create_hierarchy(root_comp, root_container);
111
112 }
113
114
115 void jedule_sd_cleanup() {
116
117         jedule_cleanup_output();
118 }
119
120 void jedule_sd_init() {
121
122         XBT_LOG_CONNECT(jed_sd, jedule);
123
124         jedule_init_output();
125 }
126
127 void jedule_sd_dump() {
128         FILE *fh;
129
130         fh = fopen("simgrid.jed", "w");
131
132         write_jedule_output(fh, jedule, jedule_event_list, NULL);
133
134         fclose(fh);
135
136 }
137
138 #endif