Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move some storage-related content out of routing into storage area
[simgrid.git] / src / instr / jedule / jedule_sd_binding.cpp
1 /* Copyright (c) 2010-2016. 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 "simgrid/jedule/jedule_sd_binding.h"
9 #include "simgrid/forward.h"
10
11 #include "simgrid/s4u/As.hpp"
12 #include "simgrid/s4u/engine.hpp"
13 #include "simgrid/jedule/jedule.hpp"
14 #include "../../simdag/simdag_private.hpp"
15
16 #if HAVE_JEDULE
17
18 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule, "Logging specific to Jedule SD binding");
20
21 jedule_t my_jedule;
22
23 void jedule_log_sd_event(SD_task_t task)
24 {
25   xbt_assert(task != nullptr);
26
27   jed_event_t event = new simgrid::jedule::Event(std::string(SD_task_get_name(task)),
28                                                  SD_task_get_start_time(task), SD_task_get_finish_time(task), "SD");
29   event->addResources(task->allocation);
30   my_jedule->event_set.push_back(event);
31 }
32
33 void jedule_sd_init()
34 {
35   AS_t root_comp = simgrid::s4u::Engine::instance()->rootAs();
36   XBT_DEBUG("root name %s\n", root_comp->name());
37
38   my_jedule = new simgrid::jedule::Jedule();
39
40   jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name()));
41   root_container->createHierarchy(root_comp);
42   my_jedule->root_container = root_container;
43 }
44
45 void jedule_sd_exit(void)
46 {
47   delete my_jedule;
48 }
49
50 void jedule_sd_dump(const char * filename)
51 {
52   if (my_jedule) {
53     char *fname;
54     if (!filename) {
55       fname = bprintf("%s.jed", xbt_binary_name);
56     } else {
57       fname = xbt_strdup(filename);
58     }
59
60     FILE *fh = fopen(fname, "w");
61
62     my_jedule->writeOutput(fh);
63
64     fclose(fh);
65     xbt_free(fname);
66   }
67 }
68 #endif