Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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 void Event::deleteEvent(){
20   while (!this->resource_subsets.empty()){
21     xbt_free(this->resource_subsets.back());
22     this->resource_subsets.pop_back();
23   }
24   delete this;
25 }
26
27 void Event::addResources(std::vector<sg_host_t> *host_selection) {
28   xbt_dynar_t resource_subset_list;
29   jed_res_subset_t res_set;
30   unsigned int i;
31
32   resource_subset_list = xbt_dynar_new(sizeof(jed_res_subset_t), nullptr);
33
34   jed_simgrid_get_resource_selection_by_hosts(resource_subset_list, host_selection);
35   xbt_dynar_foreach(resource_subset_list, i, res_set)  {
36     this->resource_subsets.push_back(res_set);
37   }
38
39   xbt_dynar_free_container(&resource_subset_list);
40 }
41
42 void Event::addCharacteristic(char *characteristic) {
43   xbt_assert( characteristic != nullptr );
44   this->characteristics_list.push_back(characteristic);
45 }
46
47 void Event::addInfo(char* key, char *value) {
48   xbt_assert((key != nullptr) && value != nullptr);
49   this->info_map.insert({key, value});
50 }
51
52 void Event::print(FILE *jed_file){
53   fprintf(jed_file, "    <event>\n");
54   fprintf(jed_file, "      <prop key=\"name\" value=\"%s\" />\n", this->name.c_str());
55   fprintf(jed_file, "      <prop key=\"start\" value=\"%g\" />\n", this->start_time);
56   fprintf(jed_file, "      <prop key=\"end\" value=\"%g\" />\n", this->end_time);
57   fprintf(jed_file, "      <prop key=\"type\" value=\"%s\" />\n", this->type.c_str());
58   fprintf(jed_file, "      <res_util>\n");
59
60   xbt_assert(!this->resource_subsets.empty());
61   for (auto subset: this->resource_subsets) {
62     int start = subset->start_idx;
63     int end   = subset->start_idx + subset->nres - 1;
64
65     std::string resid = subset->parent->getHierarchyAsString();
66     fprintf(jed_file, "        <select resources=\"");
67     fprintf(jed_file, "%s", resid.c_str());
68     fprintf(jed_file, ".[%d-%d]", start, end);
69     fprintf(jed_file, "\" />\n");
70   }
71
72   fprintf(jed_file, "      </res_util>\n");
73   if (!this->characteristics_list.empty()){
74     fprintf(jed_file, "      <characteristics>\n");
75     for (auto ch: this->characteristics_list)
76       fprintf(jed_file, "          <characteristic name=\"%s\" />\n", ch);
77     fprintf(jed_file, "      </characteristics>\n");
78   }
79
80   if (!this->info_map.empty()){
81     fprintf(jed_file, "      <info>\n");
82     print_key_value_dict(jed_file, this->info_map);
83     fprintf(jed_file, "      </info>\n");
84   }
85
86   fprintf(jed_file, "    </event>\n");
87 }
88
89 }
90 }
91 #endif