X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/69659a8281d4aeac3476820299f26a09dd285996..5ed37babb2fa9097abe82df299c0aa259ed84d5a:/src/kernel/resource/profile/Profile.hpp diff --git a/src/kernel/resource/profile/Profile.hpp b/src/kernel/resource/profile/Profile.hpp index 8a25e3bc5a..1876a959d7 100644 --- a/src/kernel/resource/profile/Profile.hpp +++ b/src/kernel/resource/profile/Profile.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -15,9 +15,7 @@ #include #include -namespace simgrid { -namespace kernel { -namespace profile { +namespace simgrid::kernel::profile { /** @brief A profile is a set of timed values, encoding the value that a variable takes at what time * @@ -25,39 +23,45 @@ namespace profile { * time. To model that, you have to set several profiles per resource: one for the on/off state and one for each * numerical value (computational speed, bandwidth and/or latency). * - * There are two behaviours. Either a callback is used to populate the profile when the set has been exhausted, - * or the callback is called only during construction and the initial set is repeated over and over, after a fixed repeating delay. + * There are two behaviours. Either a callback is used to populate the profile when the set has been exhausted, + * or the callback is called only during construction and the initial set is repeated over and over, after a fixed + * repeating delay. */ class XBT_PUBLIC Profile { public: - /** @brief Create a profile. There are two behaviours. Either the callback is - * - * @param name The name of the profile (checked for uniqueness) - * @param cb A callback object/function that populates the profile. - * @param repeat_delay If strictly negative, it is ignored and the callback is called when an event reached the end of the event_list. - * If zero or positive, the initial set repeats after the provided delay. - */ + /** @brief Create a profile. There are two behaviours. Either the callback is + * + * @param name The name of the profile (checked for uniqueness) + * @param cb A callback object/function that populates the profile. + * @param repeat_delay If strictly negative, it is ignored and the callback is called when an event reached the end of + * the event_list. If zero or positive, the initial set repeats after the provided delay. + */ explicit Profile(const std::string& name, const std::function& cb, double repeat_delay); virtual ~Profile()=default; Event* schedule(FutureEvtSet* fes, resource::Resource* resource); DatedValue next(Event* event); const std::vector& get_event_list() const { return event_list; } - const std::string get_name() const { return name; } + const std::string& get_name() const { return name; } bool is_repeating() const { return repeat_delay>=0;} double get_repeat_delay() const { return repeat_delay;} - + private: std::string name; std::function cb; std::vector event_list; FutureEvtSet* fes_ = nullptr; double repeat_delay; + + bool get_enough_events(size_t index) + { + if (index >= event_list.size() && cb) + cb(event_list); + return index < event_list.size(); + } }; -} // namespace profile -} // namespace kernel -} // namespace simgrid +} // namespace simgrid::kernel::profile /** Module finalizer: frees all profiles */ XBT_PUBLIC void tmgr_finalize();