From af45246075b3fc6bc43782309f9320974d5e222d Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 27 Oct 2017 10:21:40 +0200 Subject: [PATCH] split instr_private in several header files --- src/instr/instr_paje_containers.cpp | 5 +- src/instr/instr_paje_containers.hpp | 55 +++++++++++ src/instr/instr_paje_header.cpp | 36 +++---- src/instr/instr_paje_trace.cpp | 63 +++++-------- src/instr/instr_paje_types.cpp | 12 +-- src/instr/instr_paje_types.hpp | 89 ++++++++++++++++++ src/instr/instr_paje_values.cpp | 23 +++-- src/instr/instr_private.hpp | 141 ++++------------------------ src/msg/instr_msg_process.cpp | 4 +- src/msg/instr_msg_task.cpp | 6 +- src/surf/instr_routing.cpp | 4 +- tools/cmake/DefinePackages.cmake | 2 + 12 files changed, 233 insertions(+), 207 deletions(-) create mode 100644 src/instr/instr_paje_containers.hpp create mode 100644 src/instr/instr_paje_types.hpp diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index efb6238293..26b51e8001 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -26,7 +26,6 @@ long long int instr_new_paje_id () return type_id++; } - namespace simgrid { namespace instr { @@ -149,7 +148,7 @@ void Container::logCreation() double timestamp = SIMIX_get_clock(); std::stringstream stream; - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, simgrid::instr::PAJE_CreateContainer, timestamp); + XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, simgrid::instr::PAJE_CreateContainer, timestamp); if (instr_fmt_type == instr_fmt_paje) { stream << std::fixed << std::setprecision(TRACE_precision()); @@ -201,7 +200,7 @@ void Container::logDestruction() std::stringstream stream; double timestamp = SIMIX_get_clock(); - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, simgrid::instr::PAJE_DestroyContainer, timestamp); + XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, simgrid::instr::PAJE_DestroyContainer, timestamp); if (instr_fmt_type == instr_fmt_paje) { stream << std::fixed << std::setprecision(TRACE_precision()); diff --git a/src/instr/instr_paje_containers.hpp b/src/instr/instr_paje_containers.hpp new file mode 100644 index 0000000000..688abeb2fa --- /dev/null +++ b/src/instr/instr_paje_containers.hpp @@ -0,0 +1,55 @@ +/* Copyright (c) 2010-2017. 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. */ + +#ifndef INSTR_PAJE_CONTAINERS_HPP +#define INSTR_PAJE_CONTAINERS_HPP + +#include "src/instr/instr_private.hpp" + +namespace simgrid { +namespace instr { +class Type; + +class Container { + long long int id_; + std::string name_; /* Unique name of this container */ +public: + Container(std::string name, std::string type_name, Container* father); + virtual ~Container(); + + Type* type_; /* Type of this container */ + Container* father_; + std::map children_; + sg_netpoint_t netpoint_ = nullptr; + + static Container* byNameOrNull(std::string name); + static Container* byName(std::string name); + std::string getName() { return name_; } + const char* getCname() { return name_.c_str(); } + long long int getId() { return id_; } + void removeFromParent(); + void logCreation(); + void logDestruction(); + + static Container* getRootContainer(); +}; + +class NetZoneContainer : public Container { +public: + NetZoneContainer(std::string name, unsigned int level, NetZoneContainer* father); +}; + +class RouterContainer : public Container { +public: + RouterContainer(std::string name, Container* father); +}; + +class HostContainer : public Container { +public: + HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father); +}; +} +} +#endif diff --git a/src/instr/instr_paje_header.cpp b/src/instr/instr_paje_header.cpp index 76d7967580..8e293adbb8 100644 --- a/src/instr/instr_paje_header.cpp +++ b/src/instr/instr_paje_header.cpp @@ -13,7 +13,7 @@ extern FILE *tracing_file; static void TRACE_header_PajeDefineContainerType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineContainerType %d\n", simgrid::instr::PAJE_DefineContainerType); + fprintf(tracing_file, "%%EventDef PajeDefineContainerType %u\n", simgrid::instr::PAJE_DefineContainerType); fprintf(tracing_file, "%% Alias string\n"); if (basic){ fprintf(tracing_file, "%% ContainerType string\n"); @@ -26,7 +26,7 @@ static void TRACE_header_PajeDefineContainerType(bool basic) static void TRACE_header_PajeDefineVariableType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineVariableType %d\n", simgrid::instr::PAJE_DefineVariableType); + fprintf(tracing_file, "%%EventDef PajeDefineVariableType %u\n", simgrid::instr::PAJE_DefineVariableType); fprintf(tracing_file, "%% Alias string\n"); if (basic){ fprintf(tracing_file, "%% ContainerType string\n"); @@ -40,7 +40,7 @@ static void TRACE_header_PajeDefineVariableType(bool basic) static void TRACE_header_PajeDefineStateType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineStateType %d\n", simgrid::instr::PAJE_DefineStateType); + fprintf(tracing_file, "%%EventDef PajeDefineStateType %u\n", simgrid::instr::PAJE_DefineStateType); fprintf(tracing_file, "%% Alias string\n"); if (basic){ fprintf(tracing_file, "%% ContainerType string\n"); @@ -53,7 +53,7 @@ static void TRACE_header_PajeDefineStateType(bool basic) static void TRACE_header_PajeDefineEventType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineEventType %d\n", simgrid::instr::PAJE_DefineEventType); + fprintf(tracing_file, "%%EventDef PajeDefineEventType %u\n", simgrid::instr::PAJE_DefineEventType); fprintf(tracing_file, "%% Alias string\n"); if (basic){ fprintf(tracing_file, "%% ContainerType string\n"); @@ -66,7 +66,7 @@ static void TRACE_header_PajeDefineEventType(bool basic) static void TRACE_header_PajeDefineLinkType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineLinkType %d\n", simgrid::instr::PAJE_DefineLinkType); + fprintf(tracing_file, "%%EventDef PajeDefineLinkType %u\n", simgrid::instr::PAJE_DefineLinkType); fprintf(tracing_file, "%% Alias string\n"); if (basic){ fprintf(tracing_file, "%% ContainerType string\n"); @@ -83,7 +83,7 @@ static void TRACE_header_PajeDefineLinkType(bool basic) static void TRACE_header_PajeDefineEntityValue(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineEntityValue %d\n", simgrid::instr::PAJE_DefineEntityValue); + fprintf(tracing_file, "%%EventDef PajeDefineEntityValue %u\n", simgrid::instr::PAJE_DefineEntityValue); fprintf(tracing_file, "%% Alias string\n"); if (basic){ fprintf(tracing_file, "%% EntityType string\n"); @@ -97,7 +97,7 @@ static void TRACE_header_PajeDefineEntityValue(bool basic) static void TRACE_header_PajeCreateContainer() { - fprintf(tracing_file, "%%EventDef PajeCreateContainer %d\n", simgrid::instr::PAJE_CreateContainer); + fprintf(tracing_file, "%%EventDef PajeCreateContainer %u\n", simgrid::instr::PAJE_CreateContainer); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Alias string\n"); fprintf(tracing_file, "%% Type string\n"); @@ -108,7 +108,7 @@ static void TRACE_header_PajeCreateContainer() static void TRACE_header_PajeDestroyContainer() { - fprintf(tracing_file, "%%EventDef PajeDestroyContainer %d\n", simgrid::instr::PAJE_DestroyContainer); + fprintf(tracing_file, "%%EventDef PajeDestroyContainer %u\n", simgrid::instr::PAJE_DestroyContainer); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Name string\n"); @@ -117,7 +117,7 @@ static void TRACE_header_PajeDestroyContainer() static void TRACE_header_PajeSetVariable() { - fprintf(tracing_file, "%%EventDef PajeSetVariable %d\n", simgrid::instr::PAJE_SetVariable); + fprintf(tracing_file, "%%EventDef PajeSetVariable %u\n", simgrid::instr::PAJE_SetVariable); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -127,7 +127,7 @@ static void TRACE_header_PajeSetVariable() static void TRACE_header_PajeAddVariable() { - fprintf(tracing_file, "%%EventDef PajeAddVariable %d\n", simgrid::instr::PAJE_AddVariable); + fprintf(tracing_file, "%%EventDef PajeAddVariable %u\n", simgrid::instr::PAJE_AddVariable); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -137,7 +137,7 @@ static void TRACE_header_PajeAddVariable() static void TRACE_header_PajeSubVariable() { - fprintf(tracing_file, "%%EventDef PajeSubVariable %d\n", simgrid::instr::PAJE_SubVariable); + fprintf(tracing_file, "%%EventDef PajeSubVariable %u\n", simgrid::instr::PAJE_SubVariable); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -147,7 +147,7 @@ static void TRACE_header_PajeSubVariable() static void TRACE_header_PajeSetState() { - fprintf(tracing_file, "%%EventDef PajeSetState %d\n", simgrid::instr::PAJE_SetState); + fprintf(tracing_file, "%%EventDef PajeSetState %u\n", simgrid::instr::PAJE_SetState); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -157,7 +157,7 @@ static void TRACE_header_PajeSetState() static void TRACE_header_PajePushState(int size) { - fprintf(tracing_file, "%%EventDef PajePushState %d\n", simgrid::instr::PAJE_PushState); + fprintf(tracing_file, "%%EventDef PajePushState %u\n", simgrid::instr::PAJE_PushState); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -178,7 +178,7 @@ static void TRACE_header_PajePushState(int size) static void TRACE_header_PajePopState() { - fprintf(tracing_file, "%%EventDef PajePopState %d\n", simgrid::instr::PAJE_PopState); + fprintf(tracing_file, "%%EventDef PajePopState %u\n", simgrid::instr::PAJE_PopState); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -190,7 +190,7 @@ static void TRACE_header_PajeResetState(bool basic) if (basic) return; - fprintf(tracing_file, "%%EventDef PajeResetState %d\n", simgrid::instr::PAJE_ResetState); + fprintf(tracing_file, "%%EventDef PajeResetState %u\n", simgrid::instr::PAJE_ResetState); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -199,7 +199,7 @@ static void TRACE_header_PajeResetState(bool basic) static void TRACE_header_PajeStartLink(bool basic, int size) { - fprintf(tracing_file, "%%EventDef PajeStartLink %d\n", simgrid::instr::PAJE_StartLink); + fprintf(tracing_file, "%%EventDef PajeStartLink %u\n", simgrid::instr::PAJE_StartLink); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -216,7 +216,7 @@ static void TRACE_header_PajeStartLink(bool basic, int size) static void TRACE_header_PajeEndLink(bool basic) { - fprintf(tracing_file, "%%EventDef PajeEndLink %d\n", simgrid::instr::PAJE_EndLink); + fprintf(tracing_file, "%%EventDef PajeEndLink %u\n", simgrid::instr::PAJE_EndLink); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); @@ -232,7 +232,7 @@ static void TRACE_header_PajeEndLink(bool basic) static void TRACE_header_PajeNewEvent() { - fprintf(tracing_file, "%%EventDef PajeNewEvent %d\n", simgrid::instr::PAJE_NewEvent); + fprintf(tracing_file, "%%EventDef PajeNewEvent %u\n", simgrid::instr::PAJE_NewEvent); fprintf(tracing_file, "%% Time date\n"); fprintf(tracing_file, "%% Type string\n"); fprintf(tracing_file, "%% Container string\n"); diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index 24d64506a5..56e18643c9 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -117,12 +117,12 @@ void simgrid::instr::PajeEvent::insertIntoBuffer() } buffer_debug(&buffer); - XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)", __FUNCTION__, static_cast(eventType_), - timestamp_, buffer.size()); + XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __FUNCTION__, eventType_, timestamp_, + buffer.size()); std::vector::reverse_iterator i; for (i = buffer.rbegin(); i != buffer.rend(); ++i) { simgrid::instr::PajeEvent* e1 = *i; - XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1, static_cast(e1->eventType_), e1->timestamp_); + XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_); if (e1->timestamp_ <= timestamp_) break; } @@ -139,7 +139,7 @@ void simgrid::instr::PajeEvent::insertIntoBuffer() simgrid::instr::PajeEvent::~PajeEvent() { - XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__, this, (int)eventType_, timestamp_); + XBT_DEBUG("%s not implemented for %p: event_type=%u, timestamp=%f", __FUNCTION__, this, eventType_, timestamp_); } void TRACE_paje_start() { @@ -178,37 +178,18 @@ void TRACE_paje_end() { XBT_DEBUG("Filename %s is closed", filename); } -void simgrid::instr::Value::print() -{ - XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineEntityValue); - //print it - if (instr_fmt_type == instr_fmt_paje) { - stream << std::fixed << std::setprecision(TRACE_precision()); - stream << simgrid::instr::PAJE_DefineEntityValue; - stream << " " << id_ << " " << father_->getId() << " " << name_; - if (isColored()) - stream << " \"" << color_ << "\""; - print_row(); - } else if (instr_fmt_type == instr_fmt_TI) { - /* Nothing to do */ - } else { - THROW_IMPOSSIBLE; - } -} - 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=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + 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=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_); - stream << std::fixed << std::setprecision(TRACE_precision()); - stream << (int)this->eventType_; + 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(); @@ -223,14 +204,14 @@ simgrid::instr::AddVariableEvent::AddVariableEvent(double timestamp, container_t double value) : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_AddVariable), value(value) { - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + 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=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_); stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); @@ -246,16 +227,16 @@ void simgrid::instr::AddVariableEvent::print() 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=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + 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=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_); stream << std::fixed << std::setprecision(TRACE_precision()); - stream << (int)this->eventType_; + stream << this->eventType_; print_timestamp(this); stream << " " << type->getId() << " " << container->getId() << " " << value; print_row(); @@ -266,7 +247,7 @@ void simgrid::instr::SubVariableEvent::print() } } -simgrid::instr::SetStateEvent::SetStateEvent(double timestamp, container_t container, Type* type, Value* value) +simgrid::instr::SetStateEvent::SetStateEvent(double timestamp, container_t container, Type* type, EntityValue* value) : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SetState), value(value) { #if HAVE_SMPI @@ -277,14 +258,14 @@ simgrid::instr::SetStateEvent::SetStateEvent(double timestamp, container_t conta } #endif - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_); insertIntoBuffer(); } void simgrid::instr::SetStateEvent::print() { if (instr_fmt_type == instr_fmt_paje) { - XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_); stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); @@ -303,7 +284,7 @@ void simgrid::instr::SetStateEvent::print() } } -simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* value, +simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, EntityValue* value, void* extra) : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_PushState), value(value), extra_(extra) { @@ -315,12 +296,12 @@ simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t con } #endif - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_); insertIntoBuffer(); } -simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* val) +simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, EntityValue* val) : PushStateEvent(timestamp, container, type, val, nullptr) {} @@ -493,14 +474,14 @@ void simgrid::instr::PushStateEvent::print() simgrid::instr::PopStateEvent::PopStateEvent(double timestamp, container_t container, Type* type) : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_PopState) { - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_); insertIntoBuffer(); } void simgrid::instr::PopStateEvent::print() { if (instr_fmt_type == instr_fmt_paje) { - XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_); stream << std::fixed << std::setprecision(TRACE_precision()); stream << (int)this->eventType_; print_timestamp(this); @@ -516,7 +497,7 @@ void simgrid::instr::PopStateEvent::print() simgrid::instr::ResetStateEvent::ResetStateEvent(double timestamp, container_t container, Type* type) : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_ResetState) { - XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_); + XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_); insertIntoBuffer(); delete[] this; } @@ -604,7 +585,7 @@ void simgrid::instr::EndLinkEvent::print() } } -simgrid::instr::NewEvent::NewEvent(double timestamp, container_t container, Type* type, Value* val) +simgrid::instr::NewEvent::NewEvent(double timestamp, container_t container, Type* type, EntityValue* val) : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent) { this->val = val; diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 2cbd8d8dfb..91ab9374ce 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -71,7 +71,7 @@ void Type::logDefinition(e_event_type event_type) if (instr_fmt_type != instr_fmt_paje) return; std::stringstream stream; - XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, event_type, TRACE_precision(), 0.); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, event_type, TRACE_precision(), 0.); stream << std::fixed << std::setprecision(TRACE_precision()) << event_type << " " << getId(); stream << " " << father_->getId() << " " << getName(); if (isColored()) @@ -86,7 +86,7 @@ void Type::logDefinition(simgrid::instr::Type* source, simgrid::instr::Type* des if (instr_fmt_type != instr_fmt_paje) return; std::stringstream stream; - XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.); + XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.); stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_DefineLinkType << " " << getId(); stream << " " << father_->getId() << " " << source->getId() << " " << dest->getId() << " " << getName(); XBT_DEBUG("Dump %s", stream.str().c_str()); @@ -123,14 +123,14 @@ void ValueType::addEntityValue(std::string name, std::string color) auto it = values_.find(name); if (it == values_.end()) { - Value* new_val = new Value(name, color, this); + EntityValue* new_val = new EntityValue(name, color, this); values_.insert({name, new_val}); XBT_DEBUG("new value %s, child of %s", name.c_str(), getCname()); new_val->print(); } } -Value* ValueType::getEntityValue(std::string name) +EntityValue* ValueType::getEntityValue(std::string name) { auto ret = values_.find(name); if (ret == values_.end()) { @@ -171,8 +171,8 @@ StateType* Type::getOrCreateStateType(std::string name) VariableType* Type::getOrCreateVariableType(std::string name, std::string color) { auto cont = children_.find(name); - return cont == children_.end() ? new VariableType(name, color.empty() ? "1 1 1" : color, this) - : static_cast(cont->second); + std::string mycolor = color.empty() ? "1 1 1" : color; + return cont == children_.end() ? new VariableType(name, mycolor, this) : static_cast(cont->second); } LinkType* Type::getOrCreateLinkType(std::string name, Type* source, Type* dest) diff --git a/src/instr/instr_paje_types.hpp b/src/instr/instr_paje_types.hpp new file mode 100644 index 0000000000..f1d24c24bd --- /dev/null +++ b/src/instr/instr_paje_types.hpp @@ -0,0 +1,89 @@ +/* Copyright (c) 2010-2017. 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. */ + +#ifndef INSTR_PAJE_TYPES_HPP +#define INSTR_PAJE_TYPES_HPP + +#include "src/instr/instr_private.hpp" +namespace simgrid { +namespace instr { +enum e_event_type : unsigned int; +class EntityValue; +class ContainerType; +class EventType; +class LinkType; +class StateType; +class VariableType; + +class Type { + long long int id_; + std::string name_; + std::string color_; + Type* father_; + +public: + std::map children_; + + Type(std::string name, std::string alias, std::string color, Type* father); + virtual ~Type(); + + std::string getName() { return name_; } + const char* getCname() { return name_.c_str(); } + long long int getId() { return id_; } + bool isColored() { return not color_.empty(); } + + Type* byName(std::string name); + + ContainerType* getOrCreateContainerType(std::string name); + EventType* getOrCreateEventType(std::string name); + LinkType* getOrCreateLinkType(std::string name, Type* source, Type* dest); + StateType* getOrCreateStateType(std::string name); + VariableType* getOrCreateVariableType(std::string name, std::string color); + + void logDefinition(e_event_type event_type); + void logDefinition(Type* source, Type* dest); + + static ContainerType* createRootType(); + static ContainerType* getRootType(); +}; + +class ContainerType : public Type { +public: + ContainerType(std::string name, Type* father); +}; + +class VariableType : public Type { +public: + VariableType(std::string name, std::string color, Type* father); +}; + +class ValueType : public Type { +public: + std::map values_; + ValueType(std::string name, std::string alias, Type* father) : Type(name, alias, "", father){}; + ValueType(std::string name, Type* father) : Type(name, name, "", father){}; + virtual ~ValueType(); + void addEntityValue(std::string name, std::string color); + void addEntityValue(std::string name); + EntityValue* getEntityValue(std::string name); +}; + +class LinkType : public ValueType { +public: + LinkType(std::string name, std::string alias, Type* father); +}; + +class EventType : public ValueType { +public: + EventType(std::string name, Type* father); +}; + +class StateType : public ValueType { +public: + StateType(std::string name, Type* father); +}; +} +} +#endif diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index b49b3fec1c..5f5045596a 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -4,22 +4,31 @@ /* 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. */ -#include #include "src/instr/instr_private.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)"); +extern FILE* tracing_file; namespace simgrid { namespace instr { -Value::Value(std::string name, std::string color, Type* father) : name_(name), color_(color), father_(father) -{ - this->id_ = std::to_string(instr_new_paje_id()); -}; +EntityValue::EntityValue(std::string name, std::string color, Type* father) + : id_(instr_new_paje_id()), name_(name), color_(color), father_(father){}; -Value::~Value() +void EntityValue::print() { - XBT_DEBUG("free value %s, child of %s", getCname(), father_->getCname()); + if (instr_fmt_type != instr_fmt_paje) + return; + std::stringstream stream; + XBT_DEBUG("%s: event_type=%u", __FUNCTION__, simgrid::instr::PAJE_DefineEntityValue); + stream << std::fixed << std::setprecision(TRACE_precision()); + stream << simgrid::instr::PAJE_DefineEntityValue; + stream << " " << id_ << " " << father_->getId() << " " << name_; + if (not color_.empty()) + stream << " \"" << color_ << "\""; + XBT_DEBUG("Dump %s", stream.str().c_str()); + stream << std::endl; + fprintf(tracing_file, "%s", stream.str().c_str()); } } diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index 1de5b6f850..4e6dee8ac4 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -11,6 +11,8 @@ #include "instr/instr_interface.h" #include "simgrid/instr.h" #include "simgrid_config.h" +#include "src/instr/instr_paje_containers.hpp" +#include "src/instr/instr_paje_types.hpp" #include "src/internal_config.h" #include "xbt/graph.h" #include /** std::setprecision **/ @@ -29,14 +31,16 @@ namespace simgrid { namespace instr { -class Value; +class Container; +class Type; +class EntityValue; class ContainerType; class EventType; class LinkType; class StateType; class VariableType; -enum e_event_type { +enum e_event_type : unsigned int { PAJE_DefineContainerType, PAJE_DefineVariableType, PAJE_DefineStateType, @@ -57,130 +61,20 @@ enum e_event_type { PAJE_NewEvent }; -class Type { +class EntityValue { long long int id_; std::string name_; std::string color_; - -protected: Type* father_; public: - std::map children_; - - Type(std::string name, std::string alias, std::string color, Type* father); - virtual ~Type(); - - std::string getName() { return name_; } + explicit EntityValue(std::string name, std::string color, Type* father); + ~EntityValue() = default; const char* getCname() { return name_.c_str(); } long long int getId() { return id_; } - bool isColored() { return not color_.empty(); } - - Type* byName(std::string name); - - ContainerType* getOrCreateContainerType(std::string name); - EventType* getOrCreateEventType(std::string name); - LinkType* getOrCreateLinkType(std::string name, Type* source, Type* dest); - StateType* getOrCreateStateType(std::string name); - VariableType* getOrCreateVariableType(std::string name, std::string color); - - void logDefinition(e_event_type event_type); - void logDefinition(Type* source, Type* dest); - - static ContainerType* createRootType(); - static ContainerType* getRootType(); -}; - -class ContainerType : public Type { -public: - ContainerType(std::string name, Type* father); -}; - -class VariableType : public Type { -public: - VariableType(std::string name, std::string color, Type* father); -}; - -class ValueType : public Type { -public: - std::map values_; - ValueType(std::string name, std::string alias, Type* father) : Type(name, alias, "", father){}; - ValueType(std::string name, Type* father) : Type(name, name, "", father){}; - virtual ~ValueType(); - void addEntityValue(std::string name, std::string color); - void addEntityValue(std::string name); - Value* getEntityValue(std::string name); -}; - -class LinkType : public ValueType { -public: - LinkType(std::string name, std::string alias, Type* father); -}; - -class EventType : public ValueType { -public: - EventType(std::string name, Type* father); -}; - -class StateType : public ValueType { -public: - StateType(std::string name, Type* father); -}; - -class Value { - std::string name_; - std::string id_; - std::string color_; - Type* father_; - -public: - explicit Value(std::string name, std::string color, Type* father); - ~Value(); - const char* getCname() { return name_.c_str(); } - const char* getId() { return id_.c_str(); } - bool isColored() { return not color_.empty(); } void print(); }; -class Container { - long long int id_; - std::string name_; /* Unique name of this container */ -public: - Container(std::string name, std::string type_name, Container* father); - virtual ~Container(); - - Type* type_; /* Type of this container */ - Container* father_; - std::map children_; - sg_netpoint_t netpoint_ = nullptr; - - static Container* byNameOrNull(std::string name); - static Container* byName(std::string name); - std::string getName() { return name_; } - const char* getCname() { return name_.c_str(); } - long long int getId() { return id_; } - void removeFromParent(); - void logCreation(); - void logDestruction(); - - static Container* getRootContainer(); -}; - -class NetZoneContainer : public Container { -public: - NetZoneContainer(std::string name, unsigned int level, NetZoneContainer* father); -}; - -class RouterContainer : public Container { -public: - RouterContainer(std::string name, Container* father); -}; - -class HostContainer : public Container { -public: - HostContainer(simgrid::s4u::Host& host, NetZoneContainer* father); -}; - class PajeEvent { protected: Container* container; @@ -196,7 +90,6 @@ public: void insertIntoBuffer(); }; -//-------------------------------------------------- class SetVariableEvent : public PajeEvent { double value; @@ -212,7 +105,6 @@ public: AddVariableEvent(double timestamp, Container* container, Type* type, double value); void print() override; }; -//-------------------------------------------------- class SubVariableEvent : public PajeEvent { double value; @@ -221,27 +113,26 @@ public: SubVariableEvent(double timestamp, Container* container, Type* type, double value); void print() override; }; -//-------------------------------------------------- class SetStateEvent : public PajeEvent { - Value* value; + EntityValue* value; const char* filename; int linenumber; public: - SetStateEvent(double timestamp, Container* container, Type* type, Value* val); + SetStateEvent(double timestamp, Container* container, Type* type, EntityValue* val); void print() override; }; class PushStateEvent : public PajeEvent { - Value* value; + EntityValue* value; const char* filename; int linenumber; void* extra_; public: - PushStateEvent(double timestamp, Container* container, Type* type, Value* val); - PushStateEvent(double timestamp, Container* container, Type* type, Value* val, void* extra); + PushStateEvent(double timestamp, Container* container, Type* type, EntityValue* val); + PushStateEvent(double timestamp, Container* container, Type* type, EntityValue* val, void* extra); void print() override; }; @@ -284,10 +175,10 @@ public: }; class NewEvent : public PajeEvent { - Value* val; + EntityValue* val; public: - NewEvent(double timestamp, Container* container, Type* type, Value* val); + NewEvent(double timestamp, Container* container, Type* type, EntityValue* val); void print() override; }; } diff --git a/src/msg/instr_msg_process.cpp b/src/msg/instr_msg_process.cpp index bdda78afa2..5e621ae13a 100644 --- a/src/msg/instr_msg_process.cpp +++ b/src/msg/instr_msg_process.cpp @@ -77,7 +77,7 @@ void TRACE_msg_process_suspend(msg_process_t process) container_t process_container = simgrid::instr::Container::byName(instr_process_id(process)); simgrid::instr::StateType* state = static_cast(process_container->type_->byName("MSG_PROCESS_STATE")); - simgrid::instr::Value* val = state->getEntityValue("suspend"); + simgrid::instr::EntityValue* val = state->getEntityValue("suspend"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } @@ -97,7 +97,7 @@ void TRACE_msg_process_sleep_in(msg_process_t process) container_t process_container = simgrid::instr::Container::byName(instr_process_id(process)); simgrid::instr::StateType* state = static_cast(process_container->type_->byName("MSG_PROCESS_STATE")); - simgrid::instr::Value* val = state->getEntityValue("sleep"); + simgrid::instr::EntityValue* val = state->getEntityValue("sleep"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } diff --git a/src/msg/instr_msg_task.cpp b/src/msg/instr_msg_task.cpp index 2b2b425a58..10214709c8 100644 --- a/src/msg/instr_msg_task.cpp +++ b/src/msg/instr_msg_task.cpp @@ -52,7 +52,7 @@ void TRACE_msg_task_execute_start(msg_task_t task) container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self())); simgrid::instr::StateType* state = static_cast(process_container->type_->byName("MSG_PROCESS_STATE")); - simgrid::instr::Value* val = state->getEntityValue("task_execute"); + simgrid::instr::EntityValue* val = state->getEntityValue("task_execute"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } @@ -87,7 +87,7 @@ void TRACE_msg_task_get_start() container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self())); simgrid::instr::StateType* state = static_cast(process_container->type_->byName("MSG_PROCESS_STATE")); - simgrid::instr::Value* val = state->getEntityValue("receive"); + simgrid::instr::EntityValue* val = state->getEntityValue("receive"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); } } @@ -117,7 +117,7 @@ int TRACE_msg_task_put_start(msg_task_t task) container_t process_container = simgrid::instr::Container::byName(instr_process_id(MSG_process_self())); simgrid::instr::StateType* state = static_cast(process_container->type_->byName("MSG_PROCESS_STATE")); - simgrid::instr::Value* val = state->getEntityValue("send"); + simgrid::instr::EntityValue* val = state->getEntityValue("send"); new simgrid::instr::PushStateEvent(MSG_get_clock(), process_container, state, val); std::string key = std::string("p") + std::to_string(task->counter); diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 32a7294a77..95015428d1 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -314,9 +314,9 @@ void instr_new_user_variable_type(std::string father_type, std::string new_typen static void recursiveNewUserStateType(std::string father_type, std::string new_typename, simgrid::instr::Type* root) { - if (root->getName() == father_type) { + if (root->getName() == father_type) root->getOrCreateStateType(new_typename); - } + for (auto elm : root->children_) recursiveNewUserStateType(father_type, new_typename, elm.second); } diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index cae9f7347a..8a4b47f532 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -548,9 +548,11 @@ set(LUA_SRC set(TRACING_SRC src/instr/instr_config.cpp src/instr/instr_interface.cpp + src/instr/instr_paje_containers.hpp src/instr/instr_paje_containers.cpp src/instr/instr_paje_header.cpp src/instr/instr_paje_trace.cpp + src/instr/instr_paje_types.hpp src/instr/instr_paje_types.cpp src/instr/instr_paje_values.cpp src/instr/instr_private.hpp -- 2.20.1