Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move surf::As to s4u::As
[simgrid.git] / src / instr / jedule / jedule_sd_binding.cpp
1 /* Copyright (c) 2010-2015. 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 "src/surf/surf_private.h"
11 #include "surf/surf.h"
12
13 #include "simgrid/jedule/jedule_sd_binding.h"
14 #include "simgrid/jedule/jedule_events.h"
15 #include "simgrid/jedule/jedule_platform.h"
16 #include "simgrid/jedule/jedule_output.h"
17
18 #include "simgrid/simdag.h"
19 #include "src/simdag/simdag_private.h"
20
21 #include "simgrid/s4u/as.hpp"
22 #include "simgrid/s4u/engine.hpp"
23
24 #include <stdio.h>
25
26 #ifdef HAVE_JEDULE
27
28 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
29 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule, "Logging specific to Jedule SD binding");
30
31 jedule_t jedule;
32
33 void jedule_log_sd_event(SD_task_t task)
34 {
35   jed_event_t event;
36
37   xbt_assert(task != NULL);
38
39   xbt_dynar_t host_list = xbt_dynar_new(sizeof(char*), NULL);
40
41   for(int i=0; i<task->host_count; i++) {
42     const char *hostname = sg_host_get_name(task->host_list[i]);
43     xbt_dynar_push(host_list, &hostname);
44   }
45
46   create_jed_event(&event, (char*)SD_task_get_name(task), task->start_time, task->finish_time,"SD");
47
48   jed_event_add_resources(event, host_list);
49   jedule_store_event(event);
50
51   xbt_dynar_free(&host_list);
52 }
53
54 static void create_hierarchy(AS_t current_comp, jed_simgrid_container_t current_container)
55 {
56   xbt_dict_cursor_t cursor = NULL;
57   char *key;
58   AS_t elem;
59   xbt_dict_t routing_sons = current_comp->children();
60
61   if (xbt_dict_is_empty(routing_sons)) {
62     // I am no AS
63     // add hosts to jedule platform
64     xbt_dynar_t table = current_comp->hosts();
65     xbt_dynar_t hosts;
66     unsigned int dynar_cursor;
67     sg_host_t host_elem;
68
69     hosts = xbt_dynar_new(sizeof(char*), NULL);
70
71     xbt_dynar_foreach(table, dynar_cursor, host_elem) {
72       xbt_dynar_push_as(hosts, const char*, sg_host_get_name(host_elem));
73     }
74
75     jed_simgrid_add_resources(current_container, hosts);
76     xbt_dynar_free(&hosts);
77     xbt_dynar_free(&table);
78   } else {
79     xbt_dict_foreach(routing_sons, cursor, key, elem) {
80       jed_simgrid_container_t child_container;
81       jed_simgrid_create_container(&child_container, elem->name());
82       jed_simgrid_add_container(current_container, child_container);
83       XBT_DEBUG("name : %s\n", elem->name());
84       create_hierarchy(elem, child_container);
85     }
86   }
87 }
88
89 void jedule_setup_platform()
90 {
91   jed_create_jedule(&jedule);
92
93   AS_t root_comp = simgrid::s4u::Engine::instance()->rootAs();
94   XBT_DEBUG("root name %s\n", root_comp->name());
95
96   jed_simgrid_container_t root_container;
97   jed_simgrid_create_container(&root_container, root_comp->name());
98   jedule->root_container = root_container;
99
100   create_hierarchy(root_comp, root_container);
101 }
102
103 void jedule_sd_cleanup()
104 {
105   jedule_cleanup_output();
106 }
107
108 void jedule_sd_init()
109 {
110   jedule_init_output();
111 }
112
113 void jedule_sd_exit(void)
114 {
115   if (jedule) {
116     jed_free_jedule(jedule);
117     jedule = NULL;
118   }
119 }
120
121 void jedule_sd_dump(const char * filename)
122 {
123   if (jedule) {
124     char *fname;
125     FILE *fh;
126     if (!filename) {
127       fname = bprintf("%s.jed", xbt_binary_name);
128     } else {
129       fname = xbt_strdup(filename);
130     }
131
132     fh = fopen(fname, "w");
133
134     write_jedule_output(fh, jedule, jedule_event_list, NULL);
135
136     fclose(fh);
137     free(fname);
138   }
139 }
140 #endif