Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move declarations for xbt_abort and xbt_die to xbt/asserts.h.
[simgrid.git] / src / instr / jedule / jedule_events.cpp
1 /* Copyright (c) 2010-2021. 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/config.h"
9 #include "simgrid/s4u/NetZone.hpp"
10 #include "xbt/asserts.h"
11
12 #if SIMGRID_HAVE_JEDULE
13 namespace simgrid{
14 namespace jedule{
15
16 void Event::add_resources(const std::vector<sg_host_t>& host_selection)
17 {
18   get_resource_selection_by_hosts(this->resource_subsets_, host_selection);
19 }
20
21 void Event::add_characteristic(const char* characteristic)
22 {
23   xbt_assert( characteristic != nullptr );
24   this->characteristics_list_.emplace_back(characteristic);
25 }
26
27 void Event::add_info(char* key, char* value)
28 {
29   xbt_assert((key != nullptr) && value != nullptr);
30   this->info_map_.insert({key, value});
31 }
32
33 void Event::print(FILE* jed_file) const
34 {
35   fprintf(jed_file, "    <event>\n");
36   fprintf(jed_file, "      <prop key=\"name\" value=\"%s\" />\n", this->name_.c_str());
37   fprintf(jed_file, "      <prop key=\"start\" value=\"%g\" />\n", this->start_time_);
38   fprintf(jed_file, "      <prop key=\"end\" value=\"%g\" />\n", this->end_time_);
39   fprintf(jed_file, "      <prop key=\"type\" value=\"%s\" />\n", this->type_.c_str());
40
41   xbt_assert(not this->resource_subsets_.empty());
42   fprintf(jed_file, "      <res_util>\n");
43   for (auto const& subset : this->resource_subsets_) {
44     fprintf(jed_file, "        <select resources=\"");
45     fprintf(jed_file, "%s", subset.parent->get_hierarchy_as_string().c_str());
46     fprintf(jed_file, ".[%d-%d]", subset.start_idx, subset.start_idx + subset.nres - 1);
47     fprintf(jed_file, "\" />\n");
48   }
49   fprintf(jed_file, "      </res_util>\n");
50
51   if (not this->characteristics_list_.empty()) {
52     fprintf(jed_file, "      <characteristics>\n");
53     for (auto const& ch : this->characteristics_list_)
54       fprintf(jed_file, "          <characteristic name=\"%s\" />\n", ch.c_str());
55     fprintf(jed_file, "      </characteristics>\n");
56   }
57
58   if (not this->info_map_.empty()) {
59     fprintf(jed_file, "      <info>\n");
60     for (auto const& elm : this->info_map_)
61       fprintf(jed_file, "        <prop key=\"%s\" value=\"%s\" />\n", elm.first.c_str(), elm.second.c_str());
62     fprintf(jed_file, "      </info>\n");
63   }
64
65   fprintf(jed_file, "    </event>\n");
66 }
67
68 }
69 }
70 #endif