-
- std::vector<std::string> list;
- boost::split(list, input, boost::is_any_of("\n\r"));
- for (auto val : list) {
- simgrid::kernel::profile::DatedValue event;
- simgrid::kernel::profile::StochasticDatedValue stochevent;
- 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;
- if (val == "STOCHASTIC LOOP") {
- profile->stochastic = true;
- profile->stochasticloop = true;
- continue;
- }
- if (val == "STOCHASTIC") {
- profile->stochastic = true;
- continue;
- }
-
- if (profile->stochastic) {
- unsigned int i;
- unsigned int j;
- std::istringstream iss(val);
- std::vector<std::string> splittedval((std::istream_iterator<std::string>(iss)),
- std::istream_iterator<std::string>());
-
- xbt_assert(splittedval.size() > 0, "Invalid profile line");
-
- if (splittedval[0] == "DET") {
- stochevent.date_law = Distribution::DET;
- i = 2;
- } else if (splittedval[0] == "NORM" || splittedval[0] == "NORMAL" || splittedval[0] == "GAUSS" ||
- splittedval[0] == "GAUSSIAN") {
- stochevent.date_law = Distribution::NORM;
- i = 3;
- } else if (splittedval[0] == "EXP" || splittedval[0] == "EXPONENTIAL") {
- stochevent.date_law = Distribution::EXP;
- i = 2;
- } else if (splittedval[0] == "UNIF" || splittedval[0] == "UNIFORM") {
- stochevent.date_law = Distribution::UNIF;
- i = 3;
- } else {
- xbt_die("Unknown law %s", splittedval[0].c_str());
- }
-
- xbt_assert(splittedval.size() > i, "Invalid profile line");
- if (i == 2) {
- stochevent.date_params = {std::stod(splittedval[1])};
- } else if (i == 3) {
- stochevent.date_params = {std::stod(splittedval[1]), std::stod(splittedval[2])};
- }
-
- if (splittedval[i] == "DET") {
- stochevent.value_law = Distribution::DET;
- j = 1;
- } else if (splittedval[i] == "NORM" || splittedval[i] == "NORMAL" || splittedval[i] == "GAUSS" ||
- splittedval[i] == "GAUSSIAN") {
- stochevent.value_law = Distribution::NORM;
- j = 2;
- } else if (splittedval[i] == "EXP" || splittedval[i] == "EXPONENTIAL") {
- stochevent.value_law = Distribution::EXP;
- j = 1;
- } else if (splittedval[i] == "UNIF" || splittedval[i] == "UNIFORM") {
- stochevent.value_law = Distribution::UNIF;
- j = 2;
- } else {
- xbt_die("Unknown law %s", splittedval[i].c_str());
- }
-
- xbt_assert(splittedval.size() > i + j, "Invalid profile line");
- if (j == 1) {
- stochevent.value_params = {std::stod(splittedval[i + 1])};
- } else if (j == 2) {
- stochevent.value_params = {std::stod(splittedval[i + 1]), std::stod(splittedval[i + 2])};
- }
-
- profile->stochastic_event_list.emplace_back(stochevent);
- } else {
- 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());
-
- xbt_assert(last_event->date_ <= event.date_,
- "%s:%d: Invalid trace: Events must be sorted, but time %g > time %g.\n%s", name.c_str(), linecount,
- last_event->date_, event.date_, input.c_str());
- last_event->date_ = event.date_ - last_event->date_;
-
- profile->event_list.emplace_back(event);
- last_event = &(profile->event_list.back());
- }
- }
- if (last_event) {
- if (periodicity > 0) {
- last_event->date_ = periodicity + profile->event_list.at(0).date_;
- } else {
- last_event->date_ = -1;
- }
- }
-
- trace_list.insert({name, profile});
-
- return profile;
-}
-Profile* Profile::from_file(const std::string& path)
-{
- xbt_assert(not path.empty(), "Cannot parse a trace from an empty filename");
- xbt_assert(trace_list.find(path) == trace_list.end(), "Refusing to define trace %s twice", path.c_str());
-
- auto f = std::unique_ptr<std::ifstream>(surf_ifsopen(path));
- xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", path.c_str(), (boost::join(surf_path, ":")).c_str());
-
- std::stringstream buffer;
- buffer << f->rdbuf();
-
- return Profile::from_string(path, buffer.str(), -1);