event_list.push_back(val);
}
Profile::~Profile() = default;
+
+/** @brief Register this profile for that resource onto that FES,
+ * and get an iterator over the integrated trace */
+Event* Profile::schedule(FutureEvtSet* fes, resource::Resource* resource)
+{
+ Event* event = new Event();
+ event->profile = this;
+ event->idx = 0;
+ event->resource = resource;
+ event->free_me = false;
+
+ xbt_assert((event->idx < event_list.size()), "Your profile should have at least one event!");
+
+ fes_ = fes;
+ fes_->add_event(0.0 /* start time */, event);
+
+ return event;
+}
+
+/** @brief Gets the next event from a profile */
+DatedValue Profile::next(Event* event)
+{
+ double event_date = fes_->next_date();
+ DatedValue dateVal = event_list.at(event->idx);
+
+ if (event->idx < event_list.size() - 1) {
+ fes_->add_event(event_date + dateVal.date_, event);
+ event->idx++;
+ } else if (dateVal.date_ > 0) { /* Last element. Shall we loop? */
+ fes_->add_event(event_date + dateVal.date_, event);
+ event->idx = 1; /* idx=0 is a placeholder to store when events really start */
+ } else { /* If we don't loop, we don't need this event anymore */
+ event->free_me = true;
+ }
+
+ return dateVal;
+}
+
Profile* Profile::from_string(std::string name, std::string input, double periodicity)
{
int linecount = 0;
}
}
-/** @brief Registers a new trace into the future event set, and get an iterator over the integrated trace */
-Event* FutureEvtSet::add_trace(Profile* profile, resource::Resource* resource)
+/** @brief Schedules an event to a future date */
+void FutureEvtSet::add_event(double date, Event* evt)
{
- Event* event = new Event();
- event->profile = profile;
- event->idx = 0;
- event->resource = resource;
- event->free_me = false;
-
- xbt_assert((event->idx < profile->event_list.size()), "Your profile should have at least one event!");
-
- heap_.emplace(0.0 /* start time */, event);
-
- return event;
+ heap_.emplace(date, evt);
}
-/** @brief returns the date of the next occurring event */
+/** @brief returns the date of the next occurring event (or -1 if empty) */
double FutureEvtSet::next_date() const
{
return heap_.empty() ? -1.0 : heap_.top().first;
Event* FutureEvtSet::pop_leq(double date, double* value, resource::Resource** resource)
{
double event_date = next_date();
- if (event_date > date)
+ if (event_date > date || heap_.empty())
return nullptr;
- if (heap_.empty())
- return nullptr;
Event* event = heap_.top().second;
- heap_.pop();
-
Profile* profile = event->profile;
- *resource = event->resource;
-
- DatedValue dateVal = profile->event_list.at(event->idx);
+ DatedValue dateVal = profile->next(event);
+ *resource = event->resource;
*value = dateVal.value_;
- if (event->idx < profile->event_list.size() - 1) {
- heap_.emplace(event_date + dateVal.date_, event);
- event->idx++;
- } else if (dateVal.date_ > 0) { /* Last element. Shall we loop? */
- heap_.emplace(event_date + dateVal.date_, event);
- event->idx = 1; /* idx=0 is a placeholder to store when events really start */
- } else { /* If we don't loop, we don't need this event anymore */
- event->free_me = true;
- }
+ heap_.pop();
return event;
}
/** Creates an empty trace */
explicit Profile();
virtual ~Profile();
+ Event* schedule(FutureEvtSet* fes, resource::Resource* resource);
+ DatedValue next(Event* event);
static Profile* from_file(std::string path);
static Profile* from_string(std::string name, std::string input, double periodicity);
// private:
std::vector<DatedValue> event_list;
+
+private:
+ FutureEvtSet* fes_ = nullptr;
};
/** @brief Future Event Set (collection of iterators over the traces)
virtual ~FutureEvtSet();
double next_date() const;
Event* pop_leq(double date, double* value, resource::Resource** resource);
- Event* add_trace(Profile* profile, resource::Resource* resource);
+ void add_event(double date, Event* evt);
private:
typedef std::pair<double, Event*> Qelt;
static std::vector<simgrid::kernel::profile::DatedValue> trace2vector(const char* str)
{
std::vector<simgrid::kernel::profile::DatedValue> res;
-
simgrid::kernel::profile::Profile* trace = simgrid::kernel::profile::Profile::from_string("TheName", str, 0);
XBT_VERB("---------------------------------------------------------");
XBT_VERB("data>>\n%s<<data\n", str);
MockedResource daResource;
simgrid::kernel::profile::FutureEvtSet fes;
- simgrid::kernel::profile::Event* insertedIt = fes.add_trace(trace, &daResource);
+ simgrid::kernel::profile::Event* insertedIt = trace->schedule(&fes, &daResource);
while (fes.next_date() <= 20.0 && fes.next_date() >= 0) {
thedate = fes.next_date();
return res;
}
-/* Fails in a way that is difficult to test: xbt_assert should become throw
-BOOST_AUTO_TEST_CASE(no_evt_noloop) {
-}*/
TEST_CASE("kernel::profile: Resource profiles, defining the external load", "kernel::profile")
{
void LinkImpl::set_bandwidth_profile(profile::Profile* profile)
{
xbt_assert(bandwidth_.event == nullptr, "Cannot set a second bandwidth profile to Link %s", get_cname());
- bandwidth_.event = future_evt_set.add_trace(profile, this);
+ bandwidth_.event = profile->schedule(&future_evt_set, this);
}
void LinkImpl::set_latency_profile(profile::Profile* profile)
{
xbt_assert(latency_.event == nullptr, "Cannot set a second latency profile to Link %s", get_cname());
- latency_.event = future_evt_set.add_trace(profile, this);
+ latency_.event = profile->schedule(&future_evt_set, this);
}
/**********