GreenCloud Simulator
dcresource.cc
Go to the documentation of this file.
1 /*
2  * dcresource.cc
3  *
4  * @date Feb 27, 2013
5  * @author Guzek:Mateusz
6  */
7 
8 #include "dcresource.h"
9 
10 static class DcResourceClass : public TclClass {
11 public:
12  DcResourceClass() : TclClass("DcResource") {}
13  TclObject* create(int argc, const char*const*argv) {
14  return (new DcResource());
15  }
17 
18 
20 
21 }
22 
24 
25 }
26 
27 /*Set specification, initialize usage as vector of 0.*/
29  if(resspec==NULL){
30  std::cerr << "ERROR: Null pointer passed as ResourceSpec.";
31  return 1;
32  }
33  specification=resspec;
34  capacity = resspec->capacity;
35  used_power_state_ = specification->power_states.at(0);
36  type=resspec->type;
37  arch=resspec->arch;
38  total_cap = 0;
39  std::vector<Capacity>::iterator iter;
40  for(iter = resspec->capacity.begin();iter!= resspec->capacity.end();iter++){
41  total_cap += iter->value;
42  }
43  return 0;
44 }
45 
47  double free = 0;
48 
49  std::vector<Capacity>::iterator iter;
50  for(iter=capacity.begin(); iter!= capacity.end();iter++){
51  free += iter->getValueRecursive();
52 
53  }
54  return 1-(free/total_cap);
55 }
56 
57 
59  int n = 1;
60  double* utilization = new double[n];
61  utilization[0] = getUtilization();
62  double result = specification->getPowerModel()->estimate(n,utilization);
63  delete utilization;
64  return result;
65 }
66 
67 
69  int n = 1;
70  double* utilization = new double[n];
71  utilization[0] = 1;
72  double result = specification->getPowerModel()->estimate(n,utilization);
73  delete utilization;
74  return result;
75 }
76 
77 
78 
79 
80 
82  std::cout << "DcResource";
83  std::cout << "\n";
84  specification->print();
85  std::cout << "Available capacities:\t";
86  std::vector <Capacity>::iterator iter;
87  for (iter = capacity.begin(); iter!=capacity.end(); iter++)
88  {
89  std::cout << (*iter) << ",";
90  }
91  std::cout << "\n";
92  std::cout << "Used power state:\t" << used_power_state_;
93 
94  std::cout << "\n";
95 }
96 
97 
98 int DcResource::command(int argc, const char*const* argv){
99 
100 
101  if (argc == 2) {
102  if (strcmp(argv[1], "print") == 0) {
103  this->print();
104  return (TCL_OK);
105  }
106  }
107  return (DcResource::command(argc, argv));
108 }
109 
110 
111 
TclObject * create(int argc, const char *const *argv)
Definition: dcresource.cc:13
std::vector< Capacity > capacity
Definition: resource.h:87
DcResourceClass class_dcresource
res_type type
Definition: resource.h:95
virtual double getPower()
Definition: dcresource.cc:58
virtual int command(int argc, const char *const *argv)
Definition: dcresource.cc:98
virtual void print()
Definition: dcresource.cc:81
double arch
Definition: resource.h:99
virtual double getUtilization()
Definition: dcresource.cc:46
virtual ~DcResource()
Definition: dcresource.cc:23
virtual double getMaxPower()
Definition: dcresource.cc:68
virtual int setSpecification(ResourceSpec *resspec)
Definition: dcresource.cc:28