Logo AND Algorithmique Numérique Distribuée

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