Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define and throw simgrid::TracingError.
[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 void Event::add_resources(const std::vector<sg_host_t>& host_selection)
16 {
17   get_resource_selection_by_hosts(this->resource_subsets_, host_selection);
18 }
19
20 void Event::add_characteristic(char* characteristic)
21 {
22   xbt_assert( characteristic != nullptr );
23   this->characteristics_list_.push_back(characteristic);
24 }
25
26 void Event::add_info(char* key, char* value)
27 {
28   xbt_assert((key != nullptr) && value != nullptr);
29   this->info_map_.insert({key, value});
30 }
31
32 void Event::print(FILE* jed_file) const
33 {
34   fprintf(jed_file, "    <event>\n");
35   fprintf(jed_file, "      <prop key=\"name\" value=\"%s\" />\n", this->name_.c_str());
36   fprintf(jed_file, "      <prop key=\"start\" value=\"%g\" />\n", this->start_time_);
37   fprintf(jed_file, "      <prop key=\"end\" value=\"%g\" />\n", this->end_time_);
38   fprintf(jed_file, "      <prop key=\"type\" value=\"%s\" />\n", this->type_.c_str());
39
40   xbt_assert(not this->resource_subsets_.empty());
41   fprintf(jed_file, "      <res_util>\n");
42   for (auto const& subset : this->resource_subsets_) {
43     fprintf(jed_file, "        <select resources=\"");
44     fprintf(jed_file, "%s", subset.parent->get_hierarchy_as_string().c_str());
45     fprintf(jed_file, ".[%d-%d]", subset.start_idx, subset.start_idx + subset.nres - 1);
46     fprintf(jed_file, "\" />\n");
47   }
48   fprintf(jed_file, "      </res_util>\n");
49
50   if (not this->characteristics_list_.empty()) {
51     fprintf(jed_file, "      <characteristics>\n");
52     for (auto const& ch : this->characteristics_list_)
53       fprintf(jed_file, "          <characteristic name=\"%s\" />\n", ch.c_str());
54     fprintf(jed_file, "      </characteristics>\n");
55   }
56
57   if (not this->info_map_.empty()) {
58     fprintf(jed_file, "      <info>\n");
59     for (auto const& elm : this->info_map_)
60       fprintf(jed_file, "        <prop key=\"%s\" value=\"%s\" />\n", elm.first.c_str(), elm.second.c_str());
61     fprintf(jed_file, "      </info>\n");
62   }
63
64   fprintf(jed_file, "    </event>\n");
65 }
66
67 }
68 }
69 #endif