Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
986762b3e3b7830336dac50d85762f799ae279f3
[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 void write_jedule_output(FILE *file, jedule_t jedule, xbt_dynar_t event_list) {
26   if (!xbt_dynar_is_empty(jedule_event_list)){
27
28     fprintf(file, "<jedule>\n");
29
30     if (!jedule->jedule_meta_info.empty()){
31       fprintf(file, "  <jedule_meta>\n");
32       for (auto elm: jedule->jedule_meta_info)
33         fprintf(file, "        <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
34       fprintf(file, "  </jedule_meta>\n");
35     }
36
37     fprintf(file, "  <platform>\n");
38     jedule->root_container->print(file);
39     fprintf(file, "  </platform>\n");
40
41     fprintf(file, "  <events>\n");
42     unsigned int i;
43     jed_event_t event;
44     xbt_dynar_foreach(event_list, i, event) {
45         event->print(file);
46     }
47     fprintf(file, "  </events>\n");
48
49     fprintf(file, "</jedule>\n");
50   }
51 }
52
53 void jedule_init_output() {
54   jedule_event_list = xbt_dynar_new(sizeof(jed_event_t), nullptr);
55 }
56
57 void jedule_cleanup_output() {
58   while (!xbt_dynar_is_empty(jedule_event_list)) {
59     jed_event_t evt = xbt_dynar_pop_as(jedule_event_list, jed_event_t) ;
60     evt->deleteEvent();
61   }
62
63   xbt_dynar_free_container(&jedule_event_list);
64 }
65
66 void jedule_store_event(jed_event_t event) {
67   xbt_assert(event != nullptr);
68   xbt_dynar_push(jedule_event_list, &event);
69 }
70 #endif