Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename the plugins from the command line, and document it
[simgrid.git] / src / instr / jedule / jedule_events.cpp
1 /* Copyright (c) 2010-2018. 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 "simgrid/jedule/jedule.hpp"
8 #include "simgrid/s4u/NetZone.hpp"
9 #include "xbt/asserts.h"
10
11 #if SIMGRID_HAVE_JEDULE
12 namespace simgrid{
13 namespace jedule{
14
15 Event::Event(std::string name, double start_time, double end_time, std::string type)
16   : name(name), start_time(start_time), end_time(end_time), type(type)
17 {
18   this->resource_subsets = new std::vector<jed_subset_t>();
19 }
20
21 Event::~Event()
22 {
23   if (not this->resource_subsets->empty()) {
24     for (auto const& subset : *this->resource_subsets)
25       delete subset;
26     delete this->resource_subsets;
27   }
28 }
29
30 void Event::addResources(std::vector<sg_host_t> *host_selection)
31 {
32   get_resource_selection_by_hosts(this->resource_subsets, host_selection);
33 }
34
35 void Event::addCharacteristic(char *characteristic)
36 {
37   xbt_assert( characteristic != nullptr );
38   this->characteristics_list.push_back(characteristic);
39 }
40
41 void Event::addInfo(char* key, char *value) {
42   xbt_assert((key != nullptr) && value != nullptr);
43   this->info_map.insert({key, value});
44 }
45
46 void Event::print(FILE *jed_file)
47 {
48   fprintf(jed_file, "    <event>\n");
49   fprintf(jed_file, "      <prop key=\"name\" value=\"%s\" />\n", this->name.c_str());
50   fprintf(jed_file, "      <prop key=\"start\" value=\"%g\" />\n", this->start_time);
51   fprintf(jed_file, "      <prop key=\"end\" value=\"%g\" />\n", this->end_time);
52   fprintf(jed_file, "      <prop key=\"type\" value=\"%s\" />\n", this->type.c_str());
53
54   xbt_assert(not this->resource_subsets->empty());
55   fprintf(jed_file, "      <res_util>\n");
56   for (auto const& subset : *this->resource_subsets) {
57     fprintf(jed_file, "        <select resources=\"");
58     fprintf(jed_file, "%s", subset->parent->getHierarchyAsString().c_str());
59     fprintf(jed_file, ".[%d-%d]", subset->start_idx, subset->start_idx + subset->nres-1);
60     fprintf(jed_file, "\" />\n");
61   }
62   fprintf(jed_file, "      </res_util>\n");
63
64   if (not this->characteristics_list.empty()) {
65     fprintf(jed_file, "      <characteristics>\n");
66     for (auto const& ch : this->characteristics_list)
67       fprintf(jed_file, "          <characteristic name=\"%s\" />\n", ch);
68     fprintf(jed_file, "      </characteristics>\n");
69   }
70
71   if (not this->info_map.empty()) {
72     fprintf(jed_file, "      <info>\n");
73     for (auto const& elm : this->info_map)
74       fprintf(jed_file, "        <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
75     fprintf(jed_file, "      </info>\n");
76   }
77
78   fprintf(jed_file, "    </event>\n");
79 }
80
81 }
82 }
83 #endif