X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d72bc00352d78cb2d037eeff71ef743e13b28c54..8e579781408282aaead93a271b6bb8855ba87603:/src/instr/instr_paje_types.hpp diff --git a/src/instr/instr_paje_types.hpp b/src/instr/instr_paje_types.hpp index 10916d912a..a5e31d40c7 100644 --- a/src/instr/instr_paje_types.hpp +++ b/src/instr/instr_paje_types.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2021. 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. */ @@ -7,112 +7,120 @@ #define INSTR_PAJE_TYPES_HPP #include "src/instr/instr_private.hpp" +#include #include #include namespace simgrid { namespace instr { -enum e_event_type : unsigned int; -class EntityValue; class ContainerType; class EventType; -class LinkType; -class StateType; -class VariableType; -class StateEvent; -class VariableEvent; + +long long int new_paje_id(); class Type { - long long int id_; + long long int id_ = new_paje_id(); std::string name_; std::string color_; Type* father_; + std::map, std::less<>> children_; + Container* issuer_ = nullptr; -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); - StateType* getState(std::string name); - - VariableType* getOrCreateVariableType(std::string name, std::string color); - - void logDefinition(e_event_type event_type); - void logDefinition(Type* source, Type* dest); +protected: + Container* get_issuer() const { return issuer_; } - static ContainerType* createRootType(); - static ContainerType* getRootType(); +public: + static xbt::signal on_creation; + + Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color, + Type* father); + virtual ~Type() = default; + + long long int get_id() const { return id_; } + const std::string& get_name() const { return name_; } + const char* get_cname() const { return name_.c_str(); } + const std::string& get_color() const { return color_; } + Type* get_father() const { return father_; } + const std::map, std::less<>>& get_children() const { return children_; } + bool is_colored() const { return not color_.empty(); } + + Type* by_name(const std::string& name); + LinkType* by_name_or_create(const std::string& name, const Type* source, const Type* dest); + VariableType* by_name_or_create(const std::string& name, const std::string& color); + + template T* by_name_or_create(const std::string& name) + { + auto cont = children_.find(name); + return cont == children_.end() ? new T(name, this) : static_cast(cont->second.get()); + } + + Type* set_calling_container(Container* container) + { + issuer_ = container; + return this; + } }; class ContainerType : public Type { public: - explicit ContainerType(std::string name) : Type(name, name, "", nullptr){}; - ContainerType(std::string name, Type* father); + explicit ContainerType(const std::string& name) : Type(PajeEventType::DefineContainerType, name, name, "", nullptr){}; + ContainerType(const std::string& name, Type* father) + : Type(PajeEventType::DefineContainerType, name, name, "", father){}; }; class VariableType : public Type { std::vector 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); + VariableType(const std::string& name, const std::string& color, Type* father) + : Type(PajeEventType::DefineVariableType, name, name, color, father) + { + } + void instr_event(double now, double delta, const char* resource, double value); + void set_event(double timestamp, double value); + void add_event(double timestamp, double value); + void sub_event(double timestamp, double value); }; 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); + std::map> values_; + ValueType(PajeEventType event_type, const std::string& name, const std::string& alias, Type* father) + : Type(event_type, name, alias, "", father){}; + ValueType(PajeEventType event_type, const std::string& name, Type* father) + : Type(event_type, name, name, "", father){}; + void add_entity_value(const std::string& name, const std::string& color); + void add_entity_value(const std::string& name); + EntityValue* get_entity_value(const std::string& name); }; class LinkType : public ValueType { public: - LinkType(std::string name, std::string alias, Type* father); - void startEvent(double timestamp, Container* source_container, Container* sourceContainer, std::string value, - std::string key); - void startEvent(double timestamp, Container* source_container, Container* sourceContainer, std::string value, - std::string key, int size); - void endEvent(double timestamp, Container* source_container, Container* destContainer, std::string value, - std::string key); + static xbt::signal on_creation; + LinkType(const std::string& name, const Type* source, const Type* dest, const std::string& alias, Type* father) + : ValueType(PajeEventType::DefineLinkType, name, alias, father) + { + on_creation(*this, *source, *dest); + } + void start_event(Container* startContainer, const std::string& value, const std::string& key, + size_t size = static_cast(-1)); + void end_event(Container* endContainer, const std::string& value, const std::string& key); }; class EventType : public ValueType { public: - EventType(std::string name, Type* father); + EventType(const std::string& name, Type* father) : ValueType(PajeEventType::DefineEventType, name, father) {} }; class StateType : public ValueType { std::vector events_; - Container* issuer_ = nullptr; - public: - StateType(std::string name, Type* father); - ~StateType(); - void setCallingContainer(Container* container) { issuer_ = container; } - void setEvent(std::string value_name); - void pushEvent(std::string value_name); - void pushEvent(std::string value_name, void* extra); - void popEvent(); + StateType(const std::string& name, Type* father) : ValueType(PajeEventType::DefineStateType, name, father) {} + void set_event(const std::string& value_name); + void push_event(const std::string& value_name); + void push_event(const std::string& value_name, TIData* extra); + void pop_event(); + void pop_event(TIData* extra); }; -} -} +} // namespace instr +} // namespace simgrid #endif