Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c321a598b648d70cb0929bf8e3ed9c9f944e639a
[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/simdag.h"
15 #include "simgrid/s4u/As.hpp"
16 #include "simgrid/s4u/engine.hpp"
17
18 #include <stdio.h>
19 #include "simgrid/forward.h"
20
21 #include "simgrid/jedule/jedule_events.hpp"
22 #include "simgrid/jedule/jedule_output.hpp"
23 #include "simgrid/jedule/jedule_platform.hpp"
24 #include "../../simdag/simdag_private.hpp"
25
26 #if 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 my_jedule;
32
33 void jedule_log_sd_event(SD_task_t task)
34 {
35   xbt_assert(task != nullptr);
36
37   jed_event_t event =
38       new simgrid::jedule::Event(std::string(SD_task_get_name(task)), task->start_time, task->finish_time,"SD");
39   event->addResources(task->allocation);
40   jedule_store_event(event);
41 }
42
43 void jedule_setup_platform()
44 {
45   jed_create_jedule(&my_jedule);
46
47   AS_t root_comp = simgrid::s4u::Engine::instance()->rootAs();
48   XBT_DEBUG("root name %s\n", root_comp->name());
49
50   jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name()));
51   my_jedule->root_container = root_container;
52
53   root_container->createHierarchy(root_comp);
54 }
55
56 void jedule_sd_cleanup()
57 {
58   jedule_cleanup_output();
59 }
60
61 void jedule_sd_init()
62 {
63   jedule_init_output();
64 }
65
66 void jedule_sd_exit(void)
67 {
68   if (my_jedule) {
69     jed_free_jedule(my_jedule);
70     my_jedule = nullptr;
71   }
72 }
73
74 void jedule_sd_dump(const char * filename)
75 {
76   if (my_jedule) {
77     char *fname;
78     FILE *fh;
79     if (!filename) {
80       fname = bprintf("%s.jed", xbt_binary_name);
81     } else {
82       fname = xbt_strdup(filename);
83     }
84
85     fh = fopen(fname, "w");
86
87     write_jedule_output(fh, my_jedule, jedule_event_list, nullptr);
88
89     fclose(fh);
90     free(fname);
91   }
92 }
93 #endif