Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
start renaming tmgr trace into profile
[simgrid.git] / include / simgrid / kernel / resource / Resource.hpp
1 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
7 #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
8
9 #include <simgrid/forward.h>
10 #include <xbt/signal.hpp>
11 #include <xbt/str.h>
12 #include <xbt/utility.hpp>
13
14 #include <string>
15
16 namespace simgrid {
17 namespace kernel {
18 namespace resource {
19
20 /** @ingroup SURF_interface
21  * @brief SURF resource interface class
22  * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage
23  */
24 class XBT_PUBLIC Resource {
25 public:
26   /**
27    * @brief Constructor of LMM Resources
28    *
29    * @param model Model associated to this Resource
30    * @param name The name of the Resource
31    * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
32    */
33   Resource(Model* model, const std::string& name, lmm::Constraint* constraint);
34
35   virtual ~Resource();
36
37   /** @brief Get the Model of the current Resource */
38   Model* get_model() const;
39
40   /** @brief Get the name of the current Resource */
41   const std::string& get_name() const;
42   /** @brief Get the name of the current Resource */
43   const char* get_cname() const;
44
45   bool operator==(const Resource& other) const;
46
47   /** @brief Apply an event of external load event to that resource */
48   virtual void apply_event(profile::Event* event, double value) = 0;
49
50   /** @brief Check if the current Resource is used (if it currently serves an action) */
51   virtual bool is_used() = 0;
52
53   /** @brief returns the current load due to activities (in flops per second, byte per second or similar)
54    *
55    * The load due to external usages modeled by trace files is ignored.*/
56   virtual double get_load();
57
58   /** @brief Check if the current Resource is active */
59   virtual bool is_on() const;
60   /** @brief Check if the current Resource is shut down */
61   virtual bool is_off() const;
62   /** @brief Turn on the current Resource */
63   virtual void turn_on();
64   /** @brief Turn off the current Resource */
65   virtual void turn_off();
66   /** @brief setup the trace file with states events (ON or OFF). Trace must contain boolean values. */
67   virtual void set_state_trace(profile::Profile* trace);
68
69 private:
70   std::string name_;
71   Model* model_;
72   bool is_on_ = true;
73
74 public: /* LMM */
75   /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
76   lmm::Constraint* get_constraint() const;
77
78 private:
79   kernel::lmm::Constraint* const constraint_ = nullptr;
80
81 public:
82   profile::Event* state_event_ = nullptr;
83
84 protected:
85   struct Metric {
86     double peak;       /**< The peak of the metric, ie its max value */
87     double scale;      /**< Current availability of the metric according to the traces, in [0,1] */
88     profile::Event* event; /**< The associated trace event associated to the metric */
89   };
90 };
91 } // namespace resource
92 } // namespace kernel
93 } // namespace simgrid
94
95 namespace std {
96 template <> class hash<simgrid::kernel::resource::Resource> {
97 public:
98   std::size_t operator()(const simgrid::kernel::resource::Resource& r) const
99   {
100     return (std::size_t)xbt_str_hash(r.get_cname());
101   }
102 };
103 } // namespace std
104
105 #endif