Logo AND Algorithmique Numérique Distribuée

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