return instr_set_to_dynar(&declared_marks);
}
-static void instr_user_variable(double time, const char* resource, const char* variable, const char* father_type,
+static void instr_user_variable(double time, const char* resource, const char* variable_name, const char* father_type,
double value, InstrUserVariable what, const char* color, std::set<std::string>* filter)
{
/* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
return;
//check if variable is already declared
- auto created = filter->find(variable);
+ auto created = filter->find(variable_name);
if (what == INSTR_US_DECLARE){
if (created == filter->end()) { // not declared yet
- filter->insert(variable);
- instr_new_user_variable_type(father_type, variable, color == nullptr ? "" : color);
+ filter->insert(variable_name);
+ instr_new_user_variable_type(father_type, variable_name, color == nullptr ? "" : color);
}
}else{
if (created != filter->end()) { // declared, let's work
char valuestr[100];
snprintf(valuestr, 100, "%g", value);
container_t container = simgrid::instr::Container::byName(resource);
- simgrid::instr::Type* type = container->type_->byName(variable);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName(variable_name));
switch (what){
case INSTR_US_SET:
- new simgrid::instr::SetVariableEvent(time, container, type, value);
+ variable->setEvent(time, container, value);
break;
case INSTR_US_ADD:
- new simgrid::instr::AddVariableEvent(time, container, type, value);
+ variable->addEvent(time, container, value);
break;
case INSTR_US_SUB:
- new simgrid::instr::SubVariableEvent(time, container, type, value);
+ variable->subEvent(time, container, value);
break;
default:
THROW_IMPOSSIBLE;
namespace simgrid {
namespace instr {
+VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
+ : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
+{
+ XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
+ insertIntoBuffer();
+}
+
StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value)
: StateEvent(timestamp, container, type, event_type, value, nullptr)
{
insertIntoBuffer();
};
+void VariableEvent::print()
+{
+ std::stringstream stream;
+ stream << std::fixed << std::setprecision(TRACE_precision());
+ XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
+ if (instr_fmt_type != instr_fmt_paje)
+ return;
+
+ if (timestamp_ < 1e-12)
+ stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId() << " " << value;
+ else
+ stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value;
+ XBT_DEBUG("Dump %s", stream.str().c_str());
+ fprintf(tracing_file, "%s\n", stream.str().c_str());
+}
+
void StateEvent::print()
{
std::stringstream stream;
XBT_DEBUG("Filename %s is closed", filename);
}
-simgrid::instr::SetVariableEvent::SetVariableEvent(double timestamp, container_t container, Type* type, double value)
- : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SetVariable), value(value)
-{
- XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
- insertIntoBuffer();
-}
-
-void simgrid::instr::SetVariableEvent::print()
-{
- if (instr_fmt_type == instr_fmt_paje) {
- XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
- stream << std::fixed << std::setprecision(TRACE_precision()) << this->eventType_;
- print_timestamp(this);
- stream << " " << type->getId() << " " << container->getId() << " " << value;
- print_row();
- } else if (instr_fmt_type == instr_fmt_TI) {
- /* Nothing to do */
- } else {
- THROW_IMPOSSIBLE;
- }
-}
-
-simgrid::instr::AddVariableEvent::AddVariableEvent(double timestamp, container_t container, simgrid::instr::Type* type,
- double value)
- : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_AddVariable), value(value)
-{
- XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
- insertIntoBuffer();
-}
-
-void simgrid::instr::AddVariableEvent::print()
-{
- if (instr_fmt_type == instr_fmt_paje) {
- XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
- stream << std::fixed << std::setprecision(TRACE_precision());
- stream << eventType_;
- print_timestamp(this);
- stream << " " << type->getId() << " " << container->getId() << " " << value;
- print_row();
- } else if (instr_fmt_type == instr_fmt_TI) {
- /* Nothing to do */
- } else {
- THROW_IMPOSSIBLE;
- }
-}
-
-simgrid::instr::SubVariableEvent::SubVariableEvent(double timestamp, container_t container, Type* type, double value)
- : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SubVariable), value(value)
-{
- XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
- insertIntoBuffer();
-}
-
-void simgrid::instr::SubVariableEvent::print()
-{
- if (instr_fmt_type == instr_fmt_paje) {
- XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
- stream << std::fixed << std::setprecision(TRACE_precision());
- stream << eventType_;
- print_timestamp(this);
- stream << " " << type->getId() << " " << container->getId() << " " << value;
- print_row();
- } else if (instr_fmt_type == instr_fmt_TI) {
- /* Nothing to do */
- } else {
- THROW_IMPOSSIBLE;
- }
-}
-
simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type,
container_t sourceContainer, std::string value, std::string key)
: StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
logDefinition(PAJE_DefineVariableType);
}
+VariableType::~VariableType()
+{
+ events_.clear();
+}
+
+void VariableType::setEvent(double timestamp, Container* container, double value)
+{
+ events_.push_back(new VariableEvent(timestamp, container, this, PAJE_SetVariable, value));
+}
+
+void VariableType::addEvent(double timestamp, Container* container, double value)
+{
+ events_.push_back(new VariableEvent(timestamp, container, this, PAJE_AddVariable, value));
+}
+
+void VariableType::subEvent(double timestamp, Container* container, double value)
+{
+ events_.push_back(new VariableEvent(timestamp, container, this, PAJE_SubVariable, value));
+}
+
LinkType::LinkType(std::string name, std::string alias, Type* father) : ValueType(name, alias, father)
{
}
class StateType;
class VariableType;
class StateEvent;
+class VariableEvent;
class Type {
long long int id_;
};
class VariableType : public Type {
+ std::vector<VariableEvent*> events_;
+
public:
VariableType(std::string name, std::string color, Type* father);
+ ~VariableType();
+ void setEvent(double timestamp, Container* container, double value);
+ void addEvent(double timestamp, Container* container, double value);
+ void subEvent(double timestamp, Container* container, double value);
};
class ValueType : public Type {
void insertIntoBuffer();
};
-class SetVariableEvent : public PajeEvent {
+class VariableEvent : public PajeEvent {
double value;
public:
- SetVariableEvent(double timestamp, Container* container, Type* type, double value);
- void print() override;
-};
-
-class AddVariableEvent : public PajeEvent {
- double value;
-
-public:
- AddVariableEvent(double timestamp, Container* container, Type* type, double value);
- void print() override;
-};
-
-class SubVariableEvent : public PajeEvent {
- double value;
-
-public:
- SubVariableEvent(double timestamp, Container* container, Type* type, double value);
+ VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value);
void print() override;
};
//to check if variables were previously set to 0, otherwise paje won't simulate them
static std::set<std::string> platform_variables;
-static void instr_event(double now, double delta, simgrid::instr::Type* variable, container_t resource, double value)
+static void instr_event(double now, double delta, simgrid::instr::VariableType* variable, container_t resource,
+ double value)
{
- /* To trace resource utilization, we use AddVariableEvent and SubVariableEvent only. This implies to add a
- * SetVariableEvent first to set the initial value of all variables for subsequent adds/subs. If we don't do so,
- * the first AddVariableEvent would be added to a non-determined value, hence causing analysis problems.
+ /* To trace resource utilization, we use AddEvent and SubEvent only. This implies to add a SetEvent first to set the
+ * initial value of all variables for subsequent adds/subs. If we don't do so, the first AddEvent would be added to a
+ * non-determined value, hence causing analysis problems.
*/
// create a key considering the resource and variable
// check if key exists: if it doesn't, set the variable to zero and mark this in the global map.
if (platform_variables.find(key) == platform_variables.end()) {
- new simgrid::instr::SetVariableEvent(now, resource, variable, 0);
+ variable->setEvent(now, resource, 0);
platform_variables.insert(key);
}
- new simgrid::instr::AddVariableEvent(now, resource, variable, value);
- new simgrid::instr::SubVariableEvent(now + delta, resource, variable, value);
+ variable->addEvent(now, resource, value);
+ variable->subEvent(now + delta, resource, value);
}
/* TRACE_surf_link_set_utilization: entry point from SimGrid */
//trace uncategorized link utilization
if (TRACE_uncategorized()){
XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now + delta, resource, value);
- simgrid::instr::Type* type = container->type_->byName("bandwidth_used");
- instr_event (now, delta, type, container, value);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName("bandwidth_used"));
+ instr_event(now, delta, variable, container, value);
}
//trace categorized utilization
//variable of this category starts by 'b', because we have a link here
std::string category_type = std::string("b") + category;
XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
- simgrid::instr::Type* type = container->type_->byName(category_type);
- instr_event (now, delta, type, container, value);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName(category_type));
+ instr_event(now, delta, variable, container, value);
}
}
//trace uncategorized host utilization
if (TRACE_uncategorized()){
XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
- simgrid::instr::Type* type = container->type_->byName("power_used");
- instr_event (now, delta, type, container, value);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName("power_used"));
+ instr_event(now, delta, variable, container, value);
}
//trace categorized utilization
//variable of this category starts by 'p', because we have a host here
std::string category_type = std::string("p") + category;
XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
- simgrid::instr::Type* type = container->type_->byName(category_type);
- instr_event (now, delta, type, container, value);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName(category_type));
+ instr_event(now, delta, variable, container, value);
}
}
container_t container = new simgrid::instr::Container(link.getName(), "LINK", father);
if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_link())) {
- simgrid::instr::Type* bandwidth = container->type_->getOrCreateVariableType("bandwidth", "");
- simgrid::instr::Type* latency = container->type_->getOrCreateVariableType("latency", "");
- new simgrid::instr::SetVariableEvent(0, container, bandwidth, link.bandwidth());
- new simgrid::instr::SetVariableEvent(0, container, latency, link.latency());
+ container->type_->getOrCreateVariableType("bandwidth", "")->setEvent(0, container, link.bandwidth());
+ container->type_->getOrCreateVariableType("latency", "")->setEvent(0, container, link.latency());
}
if (TRACE_uncategorized()) {
container->type_->getOrCreateVariableType("bandwidth_used", "0.5 0.5 0.5");
container_t container = new simgrid::instr::HostContainer(host, currentContainer.back());
if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_speed())) {
- simgrid::instr::Type* speed = container->type_->getOrCreateVariableType("power", "");
- new simgrid::instr::SetVariableEvent(0, container, speed, host.getSpeed());
+ container->type_->getOrCreateVariableType("power", "")->setEvent(0, container, host.getSpeed());
}
if (TRACE_uncategorized())
{
if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
container_t container = simgrid::instr::Container::byName(resource);
- simgrid::instr::Type* type = container->type_->byName("power");
- new simgrid::instr::SetVariableEvent(date, container, type, speed);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName("power"));
+ variable->setEvent(date, container, speed);
}
}
{
if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
container_t container = simgrid::instr::Container::byName(resource);
- simgrid::instr::Type* type = container->type_->byName("bandwidth");
- new simgrid::instr::SetVariableEvent(date, container, type, bandwidth);
+ simgrid::instr::VariableType* variable =
+ static_cast<simgrid::instr::VariableType*>(container->type_->byName("bandwidth"));
+ variable->setEvent(date, container, bandwidth);
}
}