Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use const& for the parameters of type std::string not affected by previous commit.
[simgrid.git] / src / kernel / resource / profile / trace_mgr.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 SURF_PMGR_H
7 #define SURF_PMGR_H
8
9 #include "simgrid/forward.h"
10 #include "xbt/sysdep.h"
11
12 #include <queue>
13 #include <vector>
14
15 /* Iterator within a trace */
16 namespace simgrid {
17 namespace kernel {
18 namespace profile {
19 /** @brief Links a profile to a resource */
20 class Event {
21 public:
22   Profile* profile;
23   unsigned int idx;
24   resource::Resource* resource;
25   bool free_me;
26 };
27
28 } // namespace profile
29 } // namespace kernel
30 } // namespace simgrid
31 extern XBT_PRIVATE simgrid::kernel::profile::FutureEvtSet future_evt_set;
32
33 /**
34  * @brief Free a trace event structure
35  *
36  * This function frees a trace_event if it can be freed, ie, if it has the free_me flag set to 1.
37  * This flag indicates whether the structure is still used somewhere or not.
38  * When the structure is freed, the argument is set to nullptr
39  */
40 XBT_PUBLIC void tmgr_trace_event_unref(simgrid::kernel::profile::Event** trace_event);
41
42 XBT_PUBLIC void tmgr_finalize();
43
44 namespace simgrid {
45 namespace kernel {
46 namespace profile {
47
48 /** @brief Modeling of the availability profile (due to an external load) or the churn
49  *
50  * There is 4 main concepts in this module:
51  * - #simgrid::kernel::profile::DatedValue: a pair <timestamp, value> (both are of type double)
52  * - #simgrid::kernel::profile::Profile: a list of dated values
53  * - #simgrid::kernel::profile::Event: links a given trace to a given SimGrid resource.
54  *   A Cpu for example has 2 kinds of events: state (ie, is it ON/OFF) and speed,
55  *   while a link has 3 iterators: state, bandwidth and latency.
56  * - #simgrid::kernel::profile::FutureEvtSet: makes it easy to find the next occuring event of all profiles
57  */
58 class XBT_PUBLIC DatedValue {
59 public:
60   double date_          = 0;
61   double value_         = 0;
62   explicit DatedValue() = default;
63   explicit DatedValue(double d, double v) : date_(d), value_(v) {}
64   bool operator==(DatedValue const& e2) const;
65   bool operator!=(DatedValue const& e2) const { return not(*this == e2); }
66 };
67 std::ostream& operator<<(std::ostream& out, const DatedValue& e);
68
69 /** @brief A profile is a set of timed values, encoding the value that a variable takes at what time
70  *
71  * It is useful to model dynamic platforms, where an external load that makes the resource availability change over
72  * time. To model that, you have to set several profiles per resource: one for the on/off state and one for each
73  * numerical value (computational speed, bandwidth and/or latency).
74  */
75 class XBT_PUBLIC Profile {
76 public:
77   /**  Creates an empty trace */
78   explicit Profile();
79   virtual ~Profile();
80   Event* schedule(FutureEvtSet* fes, resource::Resource* resource);
81   DatedValue next(Event* event);
82
83   static Profile* from_file(const std::string& path);
84   static Profile* from_string(const std::string& name, const std::string& input, double periodicity);
85   // private:
86   std::vector<DatedValue> event_list;
87
88 private:
89   FutureEvtSet* fes_ = nullptr;
90 };
91
92 /** @brief Future Event Set (collection of iterators over the traces)
93  * That's useful to quickly know which is the next occurring event in a set of traces. */
94 class XBT_PUBLIC FutureEvtSet {
95 public:
96   FutureEvtSet();
97   virtual ~FutureEvtSet();
98   double next_date() const;
99   Event* pop_leq(double date, double* value, resource::Resource** resource);
100   void add_event(double date, Event* evt);
101
102 private:
103   typedef std::pair<double, Event*> Qelt;
104   std::priority_queue<Qelt, std::vector<Qelt>, std::greater<Qelt>> heap_;
105 };
106
107 } // namespace profile
108 } // namespace kernel
109 } // namespace simgrid
110
111 #endif /* SURF_PMGR_H */