Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
added jedule output to SimDAG
[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 jedule_t jedule;
25
26 void jedule_log_sd_event(SD_task_t task) {
27         xbt_dynar_t host_list;
28         jed_event_t event;
29         int i;
30
31         xbt_assert(task != NULL);
32
33         host_list = xbt_dynar_new(sizeof(char*), NULL);
34
35         for(i=0; i<task->workstation_nb; i++) {
36                 char *hostname = surf_resource_name(task->workstation_list[i]->surf_workstation);
37                 xbt_dynar_push(host_list, &hostname);
38         }
39
40         create_jed_event(&event,
41                         SD_task_get_name(task),
42                         task->start_time,
43                         task->finish_time,
44                         "SD");
45
46         jed_event_add_resources(event, host_list);
47         jedule_store_event(event);
48
49         xbt_dynar_free(&host_list);
50 }
51
52 static void create_hierarchy(routing_component_t current_comp,
53                 jed_simgrid_container_t current_container) {
54         xbt_dict_cursor_t cursor = NULL;
55         char *key;
56         routing_component_t elem;
57         network_element_t network_elem;
58
59         if( xbt_dict_length(current_comp->routing_sons) == 0 ) {
60                 // I am no AS
61                 // add hosts to jedule platform
62                 xbt_dynar_t hosts;
63
64                 hosts = xbt_dynar_new(sizeof(char*), NULL);
65
66                 xbt_dict_foreach(current_comp->to_index, cursor, key, network_elem) {
67                         char *hostname;
68                         printf("key %s value %d\n", key, network_elem);
69                         //xbt_dynar_push_as(hosts, char*, key);
70                         hostname = strdup(key);
71                         xbt_dynar_push(hosts, &hostname);
72                 }
73
74                 jed_simgrid_add_resources(current_container, hosts);
75
76         } else {
77                 xbt_dict_foreach(current_comp->routing_sons, cursor, key, elem) {
78                         jed_simgrid_container_t child_container;
79                         jed_simgrid_create_container(&child_container, elem->name);
80                         jed_simgrid_add_container(current_container, child_container);
81                         printf("name : %s\n", elem->name);
82                         create_hierarchy(elem, child_container);
83                 }
84         }
85 }
86
87 void jedule_setup_platform() {
88
89         routing_component_t root_comp;
90         e_surf_network_element_type_t type;
91
92         jed_simgrid_container_t root_container;
93
94
95         jed_create_jedule(&jedule);
96
97         root_comp = global_routing->root;
98         printf("root name %s\n", root_comp->name);
99
100         // that doesn't work
101         type = root_comp->get_network_element_type(root_comp->name);
102
103         jed_simgrid_create_container(&root_container, root_comp->name);
104         jedule->root_container = root_container;
105
106         create_hierarchy(root_comp, root_container);
107
108 }
109
110
111 void jedule_sd_cleanup() {
112
113         jedule_cleanup_output();
114 }
115
116 void jedule_sd_init() {
117
118         jedule_init_output();
119 }
120
121 void jedule_sd_dump() {
122
123         write_jedule_output(stdout, jedule, jedule_event_list, NULL);
124 }
125
126 #endif