Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
uppercase the s4u header files (+cleanups)
[simgrid.git] / src / instr / jedule / jedule_sd_binding.cpp
1 /* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/jedule/jedule_sd_binding.h"
7
8 #include "simgrid/jedule/jedule.hpp"
9 #include "src/simdag/simdag_private.hpp"
10
11 #include "simgrid/s4u/Engine.hpp"
12 #include "simgrid/s4u/NetZone.hpp"
13
14 #if HAVE_JEDULE
15
16 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule, "Logging specific to Jedule SD binding");
18
19 jedule_t my_jedule;
20
21 void jedule_log_sd_event(SD_task_t task)
22 {
23   xbt_assert(task != nullptr);
24
25   jed_event_t event = new simgrid::jedule::Event(std::string(SD_task_get_name(task)),
26                                                  SD_task_get_start_time(task), SD_task_get_finish_time(task), "SD");
27   event->addResources(task->allocation);
28   my_jedule->event_set.push_back(event);
29 }
30
31 void jedule_sd_init()
32 {
33   sg_netzone_t root_comp = simgrid::s4u::Engine::instance()->netRoot();
34   XBT_DEBUG("root name %s\n", root_comp->name());
35
36   my_jedule = new simgrid::jedule::Jedule();
37
38   jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name()));
39   root_container->createHierarchy(root_comp);
40   my_jedule->root_container = root_container;
41 }
42
43 void jedule_sd_exit(void)
44 {
45   delete my_jedule;
46 }
47
48 void jedule_sd_dump(const char * filename)
49 {
50   if (my_jedule) {
51     char *fname;
52     if (!filename) {
53       fname = bprintf("%s.jed", xbt_binary_name);
54     } else {
55       fname = xbt_strdup(filename);
56     }
57
58     FILE *fh = fopen(fname, "w");
59
60     my_jedule->writeOutput(fh);
61
62     fclose(fh);
63     xbt_free(fname);
64   }
65 }
66 #endif