1 /* Copyright (c) 2010-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
11 #include "xbt/dynar.h"
12 #include "xbt/asserts.h"
14 #include "simgrid/jedule/jedule_output.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_out, jedule,
19 "Logging specific to Jedule output");
21 /*********************************************************/
23 xbt_dynar_t jedule_event_list;
25 static FILE *jed_file;
27 static void print_platform(jed_simgrid_container_t root_container);
28 static void print_container(jed_simgrid_container_t container);
29 static void print_resources(jed_simgrid_container_t resource_parent);
30 static void print_key_value_dict(xbt_dict_t meta_info_dict);
31 static void print_events(xbt_dynar_t event_list);
32 static void get_hierarchy_list(xbt_dynar_t hier_list,
33 jed_simgrid_container_t container);
35 /*********************************************************/
38 static void get_hierarchy_list(xbt_dynar_t hier_list,
39 jed_simgrid_container_t container) {
41 xbt_assert( container != NULL );
43 if( container->parent != NULL ) {
45 if( container->parent->container_children == NULL ) {
46 // we are in the last level
47 get_hierarchy_list(hier_list, container->parent);
52 jed_simgrid_container_t child_container;
54 xbt_dynar_foreach(container->parent->container_children, i,
56 if( child_container == container ) {
62 xbt_assert( child_nb > - 1);
64 xbt_dynar_insert_at(hier_list, 0, &child_nb);
66 get_hierarchy_list(hier_list, container->parent);
70 xbt_dynar_insert_at(hier_list, 0, &top_level);
75 static void get_hierarchy_string(jed_simgrid_container_t container,
78 xbt_dynar_t hier_list;
84 hier_list = xbt_dynar_new(sizeof(int), NULL);
85 get_hierarchy_list(hier_list, container);
87 length = xbt_dynar_length(hier_list);
89 xbt_dynar_foreach(hier_list, iter, number) {
90 if( iter != length-1 ) {
91 sprintf(buf, "%d.", number);
93 sprintf(buf, "%d", number);
98 xbt_dynar_free(&hier_list);
101 static void print_key_value_dict(xbt_dict_t key_value_dict) {
102 xbt_dict_cursor_t cursor=NULL;
105 if( key_value_dict != NULL ) {
106 xbt_dict_foreach(key_value_dict,cursor,key,data) {
107 fprintf(jed_file, " <prop key=\"%s\" value=\"%s\" />\n",key,data);
112 static void print_container(jed_simgrid_container_t container) {
114 jed_simgrid_container_t child_container;
116 xbt_assert( container != NULL );
118 fprintf(jed_file, " <res name=\"%s\">\n", container->name);
119 if( container->container_children != NULL ) {
120 xbt_dynar_foreach(container->container_children, i, child_container) {
121 print_container(child_container);
124 print_resources(container);
126 fprintf(jed_file, " </res>\n");
129 static void print_resources(jed_simgrid_container_t resource_parent) {
134 xbt_assert( resource_parent->resource_list != NULL );
136 res_nb = xbt_dynar_length(resource_parent->resource_list);
138 get_hierarchy_string(resource_parent, resid);
140 fprintf(jed_file, " <rset id=\"%s\" nb=\"%d\" names=\"", resid, res_nb);
141 xbt_dynar_foreach(resource_parent->resource_list, i, res_name) {
142 fprintf(jed_file, "%s", res_name);
143 if( i != res_nb-1 ) {
144 fprintf(jed_file, "|");
147 fprintf(jed_file, "\" />\n");
151 static void print_platform(jed_simgrid_container_t root_container) {
152 fprintf(jed_file, " <platform>\n");
153 print_container(root_container);
154 fprintf(jed_file, " </platform>\n");
157 static void print_event(jed_event_t event) {
159 jed_res_subset_t subset;
162 xbt_assert( event != NULL );
163 xbt_assert( event->resource_subsets != NULL );
165 fprintf(jed_file, " <event>\n");
168 fprintf(jed_file, " <prop key=\"name\" value=\"%s\" />\n", event->name);
169 fprintf(jed_file, " <prop key=\"start\" value=\"%g\" />\n",
171 fprintf(jed_file, " <prop key=\"end\" value=\"%g\" />\n",
173 fprintf(jed_file, " <prop key=\"type\" value=\"%s\" />\n", event->type);
175 fprintf(jed_file, " <res_util>\n");
177 xbt_dynar_foreach(event->resource_subsets, i, subset) {
179 int start = subset->start_idx;
180 int end = subset->start_idx + subset->nres - 1;
183 get_hierarchy_string(subset->parent, resid);
185 fprintf(jed_file, " <select resources=\"");
186 fprintf(jed_file, "%s", resid);
187 fprintf(jed_file, ".[%d-%d]", start, end);
188 fprintf(jed_file, "\" />\n");
192 fprintf(jed_file, " </res_util>\n");
193 if (!xbt_dynar_is_empty(event->characteristics_list)){
194 fprintf(jed_file, " <characteristics>\n");
198 xbt_dynar_foreach(event->characteristics_list, iter, ch) {
199 fprintf(jed_file, " <characteristic name=\"%s\" />\n", ch);
202 fprintf(jed_file, " </characteristics>\n");
205 if (!xbt_dict_is_empty(event->info_hash)){
206 fprintf(jed_file, " <info>\n");
207 print_key_value_dict(event->info_hash);
208 fprintf(jed_file, " </info>\n");
211 fprintf(jed_file, " </event>\n");
214 static void print_events(xbt_dynar_t event_list) {
218 fprintf(jed_file, " <events>\n");
219 xbt_dynar_foreach(event_list, i, event) {
222 fprintf(jed_file, " </events>\n");
225 void write_jedule_output(FILE *file, jedule_t jedule,
226 xbt_dynar_t event_list, xbt_dict_t meta_info_dict) {
229 if (!xbt_dynar_is_empty(jedule_event_list)){
231 fprintf(jed_file, "<jedule>\n");
233 if (!xbt_dict_is_empty(jedule->jedule_meta_info)){
234 fprintf(jed_file, " <jedule_meta>\n");
235 print_key_value_dict(jedule->jedule_meta_info);
236 fprintf(jed_file, " </jedule_meta>\n");
239 print_platform(jedule->root_container);
241 print_events(event_list);
243 fprintf(jed_file, "</jedule>\n");
247 static void jed_event_free_ref(void *evp)
249 jed_event_t ev = *(jed_event_t *)evp;
253 void jedule_init_output() {
254 jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), jed_event_free_ref);
257 void jedule_cleanup_output() {
258 xbt_dynar_free(&jedule_event_list);
261 void jedule_store_event(jed_event_t event) {
262 xbt_assert(event != NULL);
263 xbt_dynar_push(jedule_event_list, &event);