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_PROFILE_HPP
7 #define SIMGRID_KERNEL_PROFILE_HPP
9 #include "simgrid/forward.h"
10 #include "simgrid/kernel/ProfileBuilder.hpp"
11 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
12 #include "src/kernel/resource/profile/StochasticDatedValue.hpp"
18 namespace simgrid::kernel::profile {
20 /** @brief A profile is a set of timed values, encoding the value that a variable takes at what time
22 * It is useful to model dynamic platforms, where an external load that makes the resource availability change over
23 * time. To model that, you have to set several profiles per resource: one for the on/off state and one for each
24 * numerical value (computational speed, bandwidth and/or latency).
26 * There are two behaviours. Either a callback is used to populate the profile when the set has been exhausted,
27 * or the callback is called only during construction and the initial set is repeated over and over, after a fixed
30 class XBT_PUBLIC Profile {
32 /** @brief Create a profile. There are two behaviours. Either the callback is
34 * @param name The name of the profile (checked for uniqueness)
35 * @param cb A callback object/function that populates the profile.
36 * @param repeat_delay If strictly negative, it is ignored and the callback is called when an event reached the end of
37 * the event_list. If zero or positive, the initial set repeats after the provided delay.
39 explicit Profile(const std::string& name, const std::function<ProfileBuilder::UpdateCb>& cb, double repeat_delay);
40 virtual ~Profile()=default;
41 Event* schedule(FutureEvtSet* fes, resource::Resource* resource);
42 DatedValue next(Event* event);
44 const std::vector<DatedValue>& get_event_list() const { return event_list; }
45 const std::string& get_name() const { return name; }
46 bool is_repeating() const { return repeat_delay>=0;}
47 double get_repeat_delay() const { return repeat_delay;}
51 std::function<ProfileBuilder::UpdateCb> cb;
52 std::vector<DatedValue> event_list;
53 FutureEvtSet* fes_ = nullptr;
56 bool get_enough_events(size_t index)
58 if (index >= event_list.size() && cb)
60 return index < event_list.size();
64 } // namespace simgrid::kernel::profile
66 /** Module finalizer: frees all profiles */
67 XBT_PUBLIC void tmgr_finalize();