1 /* Copyright (c) 2004-2022. 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. */
6 #ifndef SIMGRID_KERNEL_PROFILEBUILDER_HPP
7 #define SIMGRID_KERNEL_PROFILEBUILDER_HPP
9 #include <simgrid/forward.h>
17 /** @brief Modeling of the availability profile (due to an external load) or the churn
19 * There is 4 main concepts in this module:
20 * - #simgrid::kernel::profile::DatedValue: a pair <timestamp, value> (both are of type double)
21 * - #simgrid::kernel::profile::Profile: a list of dated values
22 * - #simgrid::kernel::profile::Event: links a given trace to a given SimGrid resource.
23 * A Cpu for example has 2 kinds of events: state (ie, is it ON/OFF) and speed,
24 * while a link has 3 iterators: state, bandwidth and latency.
25 * - #simgrid::kernel::profile::FutureEvtSet: makes it easy to find the next occurring event of all profiles
27 class XBT_PUBLIC DatedValue {
31 explicit DatedValue() = default;
32 explicit DatedValue(double d, double v) : date_(d), value_(v) {}
33 bool operator==(DatedValue const& e2) const;
34 bool operator!=(DatedValue const& e2) const { return not(*this == e2); }
37 std::ostream& operator << (std::ostream& out, const DatedValue& dv);
39 * @brief Simple builder for Profile classes.
41 * It can be used to create profiles for links, hosts or disks.
43 class XBT_PUBLIC ProfileBuilder {
46 /** @brief A function called to populate the set of timed-values of a profile.
48 * When the profile is repeating, the callback is called only once upon Profile construction.
49 * Then the timed values are repeated after a fixed repeat_delay.
51 * When the profile is not repeating, the callback is called each time the profile data has been exhausted.
52 * More precisely, each time an FutureEvtSet reached the end of the vector of timed values of the profile.
54 * Note that the callback is only supposed to append values to the values vector, not modify or remove existing ones,
55 * because other FutureEvtSet may still need previous values.
57 * @param values The vector of the profile values, where new data can be appended.
60 using UpdateCb = void(std::vector<DatedValue>& values);
62 static Profile* from_file(const std::string& path);
63 static Profile* from_string(const std::string& name, const std::string& input, double periodicity);
65 static Profile* from_void();
67 /** Create a profile from a callback
69 * @param name: The *unique* name of the profile
70 * @param cb: A callback object/function to populate the profile
71 * @param repeat_delay: Ignored if strictly negative. Otherwise, profile is repeating and repeat_delay is inserted between two iterations.
73 * @return the newly created profile
75 static Profile* from_callback(const std::string& name, const std::function<UpdateCb>& cb, double repeat_delay);
79 } // namespace profile
81 } // namespace simgrid
83 #endif /* SIMGRID_KERNEL_PROFILEBUILDER_HPP */