1 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */
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. */
9 #include "simgrid/forward.h"
10 #include "xbt/sysdep.h"
15 /* Iterator within a trace */
19 /** @brief Links a profile to a resource */
24 resource::Resource* resource;
28 } // namespace profile
30 } // namespace simgrid
31 extern XBT_PRIVATE simgrid::kernel::profile::FutureEvtSet future_evt_set;
34 * @brief Free a trace event structure
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
40 XBT_PUBLIC void tmgr_trace_event_unref(simgrid::kernel::profile::Event** trace_event);
42 XBT_PUBLIC void tmgr_finalize();
48 /** @brief Modeling of the availability profile (due to an external load) or the churn
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
58 class XBT_PUBLIC DatedValue {
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); }
67 std::ostream& operator<<(std::ostream& out, const DatedValue& e);
69 /** @brief A profile is a set of timed values, encoding the value that a variable takes at what time
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).
75 class XBT_PUBLIC Profile {
77 /** Creates an empty trace */
80 Event* schedule(FutureEvtSet* fes, resource::Resource* resource);
81 DatedValue next(Event* event);
83 static Profile* from_file(const std::string& path);
84 static Profile* from_string(const std::string& name, const std::string& input, double periodicity);
86 std::vector<DatedValue> event_list;
89 FutureEvtSet* fes_ = nullptr;
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 {
97 FutureEvtSet(const FutureEvtSet&) = delete;
98 FutureEvtSet& operator=(const FutureEvtSet&) = delete;
99 virtual ~FutureEvtSet();
100 double next_date() const;
101 Event* pop_leq(double date, double* value, resource::Resource** resource);
102 void add_event(double date, Event* evt);
105 typedef std::pair<double, Event*> Qelt;
106 std::priority_queue<Qelt, std::vector<Qelt>, std::greater<Qelt>> heap_;
109 } // namespace profile
110 } // namespace kernel
111 } // namespace simgrid
113 #endif /* SURF_PMGR_H */