Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge tag 'v3_9_90' into hypervisor
[simgrid.git] / src / instr / jedule / jedule_sd_binding.c
1 /* Copyright (c) 2010-2013. 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 "surf/surf_private.h"
11 #include "surf/surf_resource.h"
12 #include "surf/surf.h"
13
14 #include "instr/jedule/jedule_sd_binding.h"
15 #include "instr/jedule/jedule_events.h"
16 #include "instr/jedule/jedule_platform.h"
17 #include "instr/jedule/jedule_output.h"
18
19 #include <stdio.h>
20
21 #ifdef HAVE_JEDULE
22
23 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule,
25                                 "Logging specific to Jedule SD binding");
26
27 jedule_t jedule;
28
29 void jedule_log_sd_event(SD_task_t task)
30 {
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 = sg_host_name(task->workstation_list[i]);
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 {
59   xbt_dict_cursor_t cursor = NULL;
60   unsigned int dynar_cursor;
61   char *key;
62   AS_t elem;
63   sg_routing_edge_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       xbt_dynar_push_as(hosts, char*, network_elem->name);
75     }
76
77     jed_simgrid_add_resources(current_container, hosts);
78     xbt_dynar_free(&hosts);
79   } else {
80     xbt_dict_foreach(current_comp->routing_sons, cursor, key, elem) {
81       jed_simgrid_container_t child_container;
82       jed_simgrid_create_container(&child_container, elem->name);
83       jed_simgrid_add_container(current_container, child_container);
84       XBT_DEBUG("name : %s\n", elem->name);
85       create_hierarchy(elem, child_container);
86     }
87   }
88 }
89
90 void jedule_setup_platform()
91 {
92   AS_t root_comp;
93   // e_surf_network_element_type_t type;
94
95   jed_simgrid_container_t root_container;
96
97
98   jed_create_jedule(&jedule);
99
100   root_comp = routing_platf->root;
101   XBT_DEBUG("root name %s\n", root_comp->name);
102
103   // that doesn't work
104   // type = root_comp->get_network_element_type(root_comp->name);
105
106   jed_simgrid_create_container(&root_container, root_comp->name);
107   jedule->root_container = root_container;
108
109   create_hierarchy(root_comp, root_container);
110
111 }
112
113
114 void jedule_sd_cleanup()
115 {
116   jedule_cleanup_output();
117 }
118
119 void jedule_sd_init()
120 {
121   jedule_init_output();
122 }
123
124 void jedule_sd_exit(void)
125 {
126   if (jedule) {
127     jed_free_jedule(jedule);
128     jedule = NULL;
129   }
130 }
131
132 void jedule_sd_dump()
133 {
134   if (jedule) {
135     FILE *fh;
136     char fname[1024];
137
138     fname[0] = '\0';
139     strcat(fname, xbt_binary_name);
140     strcat(fname, ".jed\0");
141
142     fh = fopen(fname, "w");
143
144     write_jedule_output(fh, jedule, jedule_event_list, NULL);
145
146     fclose(fh);
147   }
148 }
149
150 #endif