Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
properly split init/start for Exec activities
[simgrid.git] / src / surf / 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 resource
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 XBT_PUBLIC simgrid::kernel::profile::Profile* tmgr_trace_new_from_file(std::string filename);
45 XBT_PUBLIC simgrid::kernel::profile::Profile* tmgr_trace_new_from_string(std::string id, std::string input,
46                                                                          double periodicity);
47
48 namespace simgrid {
49 namespace kernel {
50 namespace profile {
51
52 /** @brief Modeling of the availability profile (due to an external load) or the churn
53  *
54  * There is 4 main concepts in this module:
55  * - #simgrid::kernel::profile::DatedValue: a pair <timestamp, value> (both are of type double)
56  * - #simgrid::kernel::profile::Profile: a list of dated values
57  * - #simgrid::kernel::profile::Event: links a given trace to a given SimGrid resource.
58  *   A Cpu for example has 2 kinds of events: state (ie, is it ON/OFF) and speed,
59  *   while a link has 3 iterators: state, bandwidth and latency.
60  * - #simgrid::kernel::profile::FutureEvtSet: makes it easy to find the next occuring event of all profiles
61  */
62 class XBT_PUBLIC DatedValue {
63 public:
64   double date_          = 0;
65   double value_         = 0;
66   explicit DatedValue() = default;
67   explicit DatedValue(double d, double v) : date_(d), value_(v) {}
68   bool operator==(DatedValue const& e2) const;
69   bool operator!=(DatedValue const& e2) const { return not(*this == e2); }
70 };
71 std::ostream& operator<<(std::ostream& out, const DatedValue& e);
72
73 /** @brief A profile 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
76  * time. To model that, you have to set several profiles per resource: one for the on/off state and one for each
77  * numerical value (computational speed, bandwidth and/or latency).
78  */
79 class XBT_PUBLIC Profile {
80 public:
81   /**  Creates an empty trace */
82   explicit Profile();
83   virtual ~Profile();
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 class XBT_PUBLIC FutureEvtSet {
91 public:
92   FutureEvtSet();
93   virtual ~FutureEvtSet();
94   double next_date() const;
95   Event* pop_leq(double date, double* value, resource::Resource** resource);
96   Event* add_trace(Profile* profile, resource::Resource* resource);
97
98 private:
99   typedef std::pair<double, Event*> Qelt;
100   std::priority_queue<Qelt, std::vector<Qelt>, std::greater<Qelt>> heap_;
101 };
102
103 } // namespace profile
104 } // namespace kernel
105 } // namespace simgrid
106
107 #endif /* SURF_PMGR_H */