Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
64f6875f6e29cc5e8809e50dcb9b1983630449af
[simgrid.git] / src / instr / jedule / jedule_output.cpp
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 "simgrid/jedule/jedule_output.hpp"
8 #include "simgrid/host.h"
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "xbt/dynar.h"
15 #include "xbt/asserts.h"
16
17 #if HAVE_JEDULE
18
19 #define STR_BUF_SIZE 1024
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_out, jedule, "Logging specific to Jedule output");
22
23 xbt_dynar_t jedule_event_list;
24
25
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);
30     }
31   }
32 }
33
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");
38 }
39
40 static void print_events(FILE *jed_file, xbt_dynar_t event_list)  {
41   unsigned int i;
42   jed_event_t event;
43
44   fprintf(jed_file, "  <events>\n");
45   xbt_dynar_foreach(event_list, i, event) {
46       event->print(jed_file);
47   }
48   fprintf(jed_file, "  </events>\n");
49 }
50
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)){
53
54     fprintf(file, "<jedule>\n");
55
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");
60     }
61
62     print_platform(file, jedule->root_container);
63
64     print_events(file, event_list);
65
66     fprintf(file, "</jedule>\n");
67   }
68 }
69
70 void jedule_init_output() {
71   jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), nullptr);
72 }
73
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) ;
77     evt->deleteEvent();
78   }
79
80   xbt_dynar_free_container(&jedule_event_list);
81 }
82
83 void jedule_store_event(jed_event_t event) {
84   xbt_assert(event != nullptr);
85   xbt_dynar_push(jedule_event_list, &event);
86 }
87 #endif