Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / instr / jedule / jedule_sd_binding.c
1 /* Copyright (c) 2010-2014. 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 "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->workstation_nb; i++) {
42     char *hostname = sg_host_name(task->workstation_list[i]);
43     xbt_dynar_push(host_list, &hostname);
44   }
45
46   create_jed_event(&event,
47       (char*)SD_task_get_name(task),
48       task->start_time,
49       task->finish_time,
50       "SD");
51
52   jed_event_add_resources(event, host_list);
53   jedule_store_event(event);
54
55   xbt_dynar_free(&host_list);
56 }
57
58 static void create_hierarchy(AS_t current_comp,
59                              jed_simgrid_container_t current_container)
60 {
61   xbt_dict_cursor_t cursor = NULL;
62   char *key;
63   AS_t elem;
64   xbt_dict_t routing_sons = surf_AS_get_routing_sons(current_comp);
65
66   if (xbt_dict_is_empty(routing_sons)) {
67     // I am no AS
68     // add hosts to jedule platform
69     xbt_dynar_t table = surf_AS_get_hosts(current_comp);
70     xbt_dynar_t hosts;
71     unsigned int dynar_cursor;
72     sg_host_t host_elem;
73
74     hosts = xbt_dynar_new(sizeof(char*), NULL);
75
76     xbt_dynar_foreach(table, dynar_cursor, host_elem) {
77       xbt_dynar_push_as(hosts, char*, sg_host_name(host_elem));
78     }
79
80     jed_simgrid_add_resources(current_container, hosts);
81     xbt_dynar_free(&hosts);
82     xbt_dynar_free(&table);
83   } else {
84     xbt_dict_foreach(routing_sons, cursor, key, elem) {
85       jed_simgrid_container_t child_container;
86       jed_simgrid_create_container(&child_container, surf_AS_get_name(elem));
87       jed_simgrid_add_container(current_container, child_container);
88       XBT_DEBUG("name : %s\n", surf_AS_get_name(elem));
89       create_hierarchy(elem, child_container);
90     }
91   }
92 }
93
94 void jedule_setup_platform()
95 {
96   AS_t root_comp;
97   // e_surf_network_element_type_t type;
98
99   jed_simgrid_container_t root_container;
100
101   jed_create_jedule(&jedule);
102
103   root_comp = surf_AS_get_routing_root();
104   XBT_DEBUG("root name %s\n", surf_AS_get_name(root_comp));
105
106   jed_simgrid_create_container(&root_container, surf_AS_get_name(root_comp));
107   jedule->root_container = root_container;
108
109   create_hierarchy(root_comp, root_container);
110 }
111
112
113 void jedule_sd_cleanup()
114 {
115   jedule_cleanup_output();
116 }
117
118 void jedule_sd_init()
119 {
120   jedule_init_output();
121 }
122
123 void jedule_sd_exit(void)
124 {
125   if (jedule) {
126     jed_free_jedule(jedule);
127     jedule = NULL;
128   }
129 }
130
131 void jedule_sd_dump()
132 {
133   if (jedule) {
134     FILE *fh;
135     char fname[1024];
136
137     fname[0] = '\0';
138     strcat(fname, xbt_binary_name);
139     strcat(fname, ".jed\0");
140
141     fh = fopen(fname, "w");
142
143     write_jedule_output(fh, jedule, jedule_event_list, NULL);
144
145     fclose(fh);
146   }
147 }
148
149 #endif