Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5e19d547ce802ff1783ffdea9378f55bf3565080
[simgrid.git] / src / surf / trace_mgr.hpp
1 /* Copyright (c) 2004-2017. 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/heap.h"
11 #include "xbt/sysdep.h"
12 #include <vector>
13
14 SG_BEGIN_DECL()
15
16 /* Iterator within a trace */
17 typedef struct tmgr_trace_event {
18   tmgr_trace_t trace;
19   unsigned int idx;
20   sg_resource_t resource;
21   int free_me;
22 } s_tmgr_trace_event_t;
23 typedef struct tmgr_trace_event* tmgr_trace_event_t;
24
25 /* Creation functions */
26 XBT_PUBLIC(tmgr_trace_t) tmgr_empty_trace_new(void);
27 XBT_PUBLIC(void) tmgr_trace_free(tmgr_trace_t trace);
28 /**
29  * \brief Free a trace event structure
30  *
31  * This function frees a trace_event if it can be freed, ie, if it has the free_me flag set to 1.
32  * This flag indicates whether the structure is still used somewhere or not.
33  * When the structure is freed, the argument is set to nullptr
34 */
35 XBT_PUBLIC(void) tmgr_trace_event_unref(tmgr_trace_event_t* trace_event);
36
37 XBT_PUBLIC(void) tmgr_finalize(void);
38
39 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_file(const char* filename);
40 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_string(const char* id, std::string input, double periodicity);
41
42 SG_END_DECL()
43
44 #ifdef __cplusplus
45 namespace simgrid {
46 /** @brief Modeling of the availability profile (due to an external load) or the churn
47  *
48  * There is 4 main concepts in this module:
49  * - #DatedValue: a pair <timestamp, value> (both are of type double)
50  * - #trace: a list of dated values
51  * - #trace_event: links a given trace to a given SimGrid resource.
52  *   A Cpu for example has 2 kinds of events: state (ie, is it ON/OFF) and speed,
53  *   while a link has 3 iterators: state, bandwidth and latency.
54  * - #future_evt_set: makes it easy to find the next occuring event of all traces
55  */
56 namespace trace_mgr {
57 XBT_PUBLIC_CLASS DatedValue
58 {
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 !(*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 XBT_PUBLIC_CLASS trace_event{
71
72 };
73
74 /** @brief A trace is a set of timed values, encoding the value that a variable takes at what time *
75  *
76  * It is useful to model dynamic platforms, where an external load that makes the resource availability change over time.
77  * 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).
78  */
79 XBT_PUBLIC_CLASS trace {
80 public:
81   /**  Creates an empty trace */
82   trace();
83   virtual ~trace();
84 //private:
85   std::vector<DatedValue> event_list;
86 };
87
88 /** @brief Future Event Set (collection of iterators over the traces)
89  * That's useful to quickly know which is the next occurring event in a set of traces. */
90 XBT_PUBLIC_CLASS future_evt_set {
91 public:
92   future_evt_set();
93   virtual ~future_evt_set();
94   double next_date() const;
95   tmgr_trace_event_t pop_leq(double date, double* value, simgrid::surf::Resource** resource);
96   tmgr_trace_event_t add_trace(tmgr_trace_t trace, simgrid::surf::Resource * resource);
97
98 private:
99   // TODO: use a boost type for the heap (or a ladder queue)
100   xbt_heap_t p_heap = xbt_heap_new(8, xbt_free_f); /* Content: only trace_events (yep, 8 is an arbitrary value) */
101 };
102
103 }} // namespace simgrid::trace_mgr
104 #endif /* C++ only */
105
106 #endif /* SURF_TMGR_H */