Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further objectification of jedule bindings
[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
9 #include "src/surf/surf_private.h"
10 #include "surf/surf.h"
11
12 #include "simgrid/jedule/jedule_sd_binding.h"
13 #include "simgrid/simdag.h"
14 #include "simgrid/s4u/As.hpp"
15 #include "simgrid/s4u/engine.hpp"
16
17 #include <stdio.h>
18 #include "simgrid/forward.h"
19
20 #include "simgrid/jedule/jedule.hpp"
21 #include "simgrid/jedule/jedule_events.hpp"
22 #include "simgrid/jedule/jedule_platform.hpp"
23 #include "../../simdag/simdag_private.hpp"
24
25 #if HAVE_JEDULE
26
27 XBT_LOG_NEW_CATEGORY(jedule, "Logging specific to Jedule");
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_sd, jedule, "Logging specific to Jedule SD binding");
29
30 jedule_t my_jedule;
31
32 void jedule_log_sd_event(SD_task_t task)
33 {
34   xbt_assert(task != nullptr);
35
36   jed_event_t event =
37       new simgrid::jedule::Event(std::string(SD_task_get_name(task)), task->start_time, task->finish_time,"SD");
38   event->addResources(task->allocation);
39   my_jedule->event_set.push_back(event);
40 }
41
42 void jedule_setup_platform()
43 {
44   AS_t root_comp = simgrid::s4u::Engine::instance()->rootAs();
45   XBT_DEBUG("root name %s\n", root_comp->name());
46
47   my_jedule = new simgrid::jedule::Jedule();
48
49   jed_container_t root_container = new simgrid::jedule::Container(std::string(root_comp->name()));
50   root_container->createHierarchy(root_comp);
51   my_jedule->root_container = root_container;
52 }
53
54 void jedule_sd_cleanup()
55 {
56   my_jedule->cleanupOutput();
57 }
58
59 void jedule_sd_init()
60 {
61 }
62
63 void jedule_sd_exit(void)
64 {
65   delete my_jedule;
66 }
67
68 void jedule_sd_dump(const char * filename)
69 {
70   if (my_jedule) {
71     char *fname;
72     if (!filename) {
73       fname = bprintf("%s.jed", xbt_binary_name);
74     } else {
75       fname = xbt_strdup(filename);
76     }
77
78     FILE *fh = fopen(fname, "w");
79
80     my_jedule->writeOutput(fh);
81
82     fclose(fh);
83     xbt_free(fname);
84   }
85 }
86 #endif