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. */
7 #include "simgrid/jedule/jedule_output.hpp"
8 #include "simgrid/host.h"
14 #include "xbt/dynar.h"
15 #include "xbt/asserts.h"
19 #define STR_BUF_SIZE 1024
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_out, jedule, "Logging specific to Jedule output");
23 xbt_dynar_t jedule_event_list;
26 void print_key_value_dict(FILE *jed_file, std::unordered_map<char*, char*> key_value_dict) {
27 if(!key_value_dict.empty()) {
28 for (auto elm: key_value_dict) {
29 fprintf(jed_file, " <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
34 static void print_platform(FILE *jed_file, jed_container_t root_container) {
35 fprintf(jed_file, " <platform>\n");
36 root_container->print(jed_file);
37 fprintf(jed_file, " </platform>\n");
40 static void print_events(FILE *jed_file, xbt_dynar_t event_list) {
44 fprintf(jed_file, " <events>\n");
45 xbt_dynar_foreach(event_list, i, event) {
46 event->print(jed_file);
48 fprintf(jed_file, " </events>\n");
51 void write_jedule_output(FILE *file, jedule_t jedule, xbt_dynar_t event_list, xbt_dict_t meta_info_dict) {
52 if (!xbt_dynar_is_empty(jedule_event_list)){
54 fprintf(file, "<jedule>\n");
56 if (!jedule->jedule_meta_info.empty()){
57 fprintf(file, " <jedule_meta>\n");
58 print_key_value_dict(file, jedule->jedule_meta_info);
59 fprintf(file, " </jedule_meta>\n");
62 print_platform(file, jedule->root_container);
64 print_events(file, event_list);
66 fprintf(file, "</jedule>\n");
70 void jedule_init_output() {
71 jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), nullptr);
74 void jedule_cleanup_output() {
75 while (!xbt_dynar_is_empty(jedule_event_list)) {
76 jed_event_t evt = xbt_dynar_pop_as(jedule_event_list, jed_event_t) ;
80 xbt_dynar_free_container(&jedule_event_list);
83 void jedule_store_event(jed_event_t event) {
84 xbt_assert(event != nullptr);
85 xbt_dynar_push(jedule_event_list, &event);