Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / instr / jedule / jedule_events.cpp
1 /* Copyright (c) 2010-2019. 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::add_resources(std::vector<sg_host_t>* host_selection)
31 {
32   get_resource_selection_by_hosts(this->resource_subsets_, host_selection);
33 }
34
35 void Event::add_characteristic(char* characteristic)
36 {
37   xbt_assert( characteristic != nullptr );
38   this->characteristics_list_.push_back(characteristic);
39 }
40
41 void Event::add_info(char* key, char* value)
42 {
43   xbt_assert((key != nullptr) && value != nullptr);
44   this->info_map_.insert({key, value});
45 }
46
47 void Event::print(FILE *jed_file)
48 {
49   fprintf(jed_file, "    <event>\n");
50   fprintf(jed_file, "      <prop key=\"name\" value=\"%s\" />\n", this->name_.c_str());
51   fprintf(jed_file, "      <prop key=\"start\" value=\"%g\" />\n", this->start_time_);
52   fprintf(jed_file, "      <prop key=\"end\" value=\"%g\" />\n", this->end_time_);
53   fprintf(jed_file, "      <prop key=\"type\" value=\"%s\" />\n", this->type_.c_str());
54
55   xbt_assert(not this->resource_subsets_->empty());
56   fprintf(jed_file, "      <res_util>\n");
57   for (auto const& subset : *this->resource_subsets_) {
58     fprintf(jed_file, "        <select resources=\"");
59     fprintf(jed_file, "%s", subset->parent->get_hierarchy_as_string().c_str());
60     fprintf(jed_file, ".[%d-%d]", subset->start_idx, subset->start_idx + subset->nres-1);
61     fprintf(jed_file, "\" />\n");
62   }
63   fprintf(jed_file, "      </res_util>\n");
64
65   if (not this->characteristics_list_.empty()) {
66     fprintf(jed_file, "      <characteristics>\n");
67     for (auto const& ch : this->characteristics_list_)
68       fprintf(jed_file, "          <characteristic name=\"%s\" />\n", ch);
69     fprintf(jed_file, "      </characteristics>\n");
70   }
71
72   if (not this->info_map_.empty()) {
73     fprintf(jed_file, "      <info>\n");
74     for (auto const& elm : this->info_map_)
75       fprintf(jed_file, "        <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
76     fprintf(jed_file, "      </info>\n");
77   }
78
79   fprintf(jed_file, "    </event>\n");
80 }
81
82 }
83 }
84 #endif