Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
quickly review the code of Fred, as requested. Nice job, pal
[simgrid.git] / src / instr / jedule / jedule_events.cpp
1 /* Copyright (c) 2010-2014. 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 #include "simgrid/jedule/jedule_output.hpp"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string>
12
13 #include "xbt/asserts.h"
14
15 #if HAVE_JEDULE
16 namespace simgrid{
17 namespace jedule{
18
19   /* FIXME: this should could maybe be merged into the destructor? */
20 void Event::deleteEvent(){
21   while (!this->resource_subsets.empty()){
22     xbt_free(this->resource_subsets.back());
23     this->resource_subsets.pop_back();
24   }
25   delete this;
26 }
27
28 void Event::addResources(std::vector<sg_host_t> *host_selection) {
29   xbt_dynar_t resource_subset_list;
30   jed_res_subset_t res_set;
31   unsigned int i;
32
33   resource_subset_list = xbt_dynar_new(sizeof(jed_res_subset_t), nullptr);
34
35   jed_simgrid_get_resource_selection_by_hosts(resource_subset_list, host_selection);
36   xbt_dynar_foreach(resource_subset_list, i, res_set)  {
37     this->resource_subsets.push_back(res_set);
38   }
39
40   xbt_dynar_free_container(&resource_subset_list);
41 }
42
43 void Event::addCharacteristic(char *characteristic) {
44   xbt_assert( characteristic != nullptr );
45   this->characteristics_list.push_back(characteristic);
46 }
47
48 void Event::addInfo(char* key, char *value) {
49   xbt_assert((key != nullptr) && value != nullptr);
50   this->info_map.insert({key, value});
51 }
52
53 void Event::print(FILE *jed_file){
54   fprintf(jed_file, "    <event>\n");
55   fprintf(jed_file, "      <prop key=\"name\" value=\"%s\" />\n", this->name.c_str());
56   fprintf(jed_file, "      <prop key=\"start\" value=\"%g\" />\n", this->start_time);
57   fprintf(jed_file, "      <prop key=\"end\" value=\"%g\" />\n", this->end_time);
58   fprintf(jed_file, "      <prop key=\"type\" value=\"%s\" />\n", this->type.c_str());
59
60   xbt_assert(!this->resource_subsets.empty());
61   fprintf(jed_file, "      <res_util>\n");
62   for (auto subset: this->resource_subsets) {
63     fprintf(jed_file, "        <select resources=\"");
64     fprintf(jed_file, "%s", subset->parent->getHierarchyAsString().c_str());
65     fprintf(jed_file, ".[%d-%d]", subset->start_idx, subset->start_idx + subset->nres - 1);
66     fprintf(jed_file, "\" />\n");
67   }
68   fprintf(jed_file, "      </res_util>\n");
69
70   if (!this->characteristics_list.empty()){
71     fprintf(jed_file, "      <characteristics>\n");
72     for (auto ch: this->characteristics_list)
73       fprintf(jed_file, "          <characteristic name=\"%s\" />\n", ch);
74     fprintf(jed_file, "      </characteristics>\n");
75   }
76
77   if (!this->info_map.empty()){
78     fprintf(jed_file, "      <info>\n");
79     for (auto elm: this->info_map)
80       fprintf(jed_file, "        <prop key=\"%s\" value=\"%s\" />\n",elm.first,elm.second);
81     fprintf(jed_file, "      </info>\n");
82   }
83
84   fprintf(jed_file, "    </event>\n");
85 }
86
87 }
88 }
89 #endif