-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(profile, resource, "Surf profile management");
-
-static std::unordered_map<std::string, simgrid::kernel::profile::Profile*> trace_list;
-
-namespace simgrid {
-namespace kernel {
-namespace profile {
-
-bool DatedValue::operator==(DatedValue const& e2) const
-{
- return (fabs(date_ - e2.date_) < 0.0001) && (fabs(value_ - e2.value_) < 0.0001);
-}
-std::ostream& operator<<(std::ostream& out, const DatedValue& e)
-{
- out << e.date_ << " " << e.value_;
- return out;
-}
-
-Profile::Profile()
-{
- /* Add the first fake event storing the time at which the trace begins */
- DatedValue val(0, -1);
- 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(const std::string& name, const std::string& input, double periodicity)
-{
- int linecount = 0;
- simgrid::kernel::profile::Profile* profile = new simgrid::kernel::profile::Profile();
- simgrid::kernel::profile::DatedValue* last_event = &(profile->event_list.back());
-
- xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name.c_str());
-
- std::vector<std::string> list;
- boost::split(list, input, boost::is_any_of("\n\r"));
- for (auto val : list) {
- simgrid::kernel::profile::DatedValue event;
- linecount++;
- boost::trim(val);
- if (val[0] == '#' || val[0] == '\0' || val[0] == '%') // pass comments
- continue;
- if (sscanf(val.c_str(), "PERIODICITY %lg\n", &periodicity) == 1)
- continue;
- if (sscanf(val.c_str(), "LOOPAFTER %lg\n", &periodicity) == 1)
- continue;
-
- XBT_ATTRIB_UNUSED int res = sscanf(val.c_str(), "%lg %lg\n", &event.date_, &event.value_);
- xbt_assert(res == 2, "%s:%d: Syntax error in trace\n%s", name.c_str(), linecount, input.c_str());