Logo AND Algorithmique Numérique Distribuée

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