1 /* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef INSTR_PAJE_TYPES_HPP
7 #define INSTR_PAJE_TYPES_HPP
9 #include "src/instr/instr_private.hpp"
19 long long int new_paje_id();
22 long long int id_ = new_paje_id();
26 std::map<std::string, std::unique_ptr<Type>, std::less<>> children_;
27 Container* issuer_ = nullptr;
29 static xbt::signal<void(Type const&, PajeEventType event_type)> on_creation;
32 Container* get_issuer() const { return issuer_; }
35 static void on_creation_cb(const std::function<void(Type const&, PajeEventType event_type)>& cb)
37 on_creation.connect(cb);
40 Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color,
42 virtual ~Type() = default;
44 long long int get_id() const { return id_; }
45 const std::string& get_name() const { return name_; }
46 const char* get_cname() const { return name_.c_str(); }
47 const std::string& get_color() const { return color_; }
48 Type* get_parent() const { return parent_; }
49 const std::map<std::string, std::unique_ptr<Type>, std::less<>>& get_children() const { return children_; }
50 bool is_colored() const { return not color_.empty(); }
52 Type* by_name(const std::string& name);
53 LinkType* by_name_or_create(const std::string& name, const Type* source, const Type* dest);
54 VariableType* by_name_or_create(const std::string& name, const std::string& color);
56 template <class T> T* by_name_or_create(const std::string& name)
58 auto cont = children_.find(name);
59 return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
62 Type* set_calling_container(Container* container)
69 class ContainerType : public Type {
71 explicit ContainerType(const std::string& name) : Type(PajeEventType::DefineContainerType, name, name, "", nullptr){};
72 ContainerType(const std::string& name, Type* parent)
73 : Type(PajeEventType::DefineContainerType, name, name, "", parent){};
76 class VariableType : public Type {
77 std::vector<VariableEvent*> events_;
79 VariableType(const std::string& name, const std::string& color, Type* parent)
80 : Type(PajeEventType::DefineVariableType, name, name, color, parent)
83 void instr_event(double now, double delta, const char* resource, double value);
84 void set_event(double timestamp, double value);
85 void add_event(double timestamp, double value);
86 void sub_event(double timestamp, double value);
89 class ValueType : public Type {
91 std::map<std::string, EntityValue, std::less<>> values_;
92 ValueType(PajeEventType event_type, const std::string& name, const std::string& alias, Type* parent)
93 : Type(event_type, name, alias, "", parent){};
94 ValueType(PajeEventType event_type, const std::string& name, Type* parent)
95 : Type(event_type, name, name, "", parent){};
96 void add_entity_value(const std::string& name, const std::string& color);
97 void add_entity_value(const std::string& name);
98 EntityValue* get_entity_value(const std::string& name);
101 class LinkType : public ValueType {
102 static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
105 static void on_creation_cb(const std::function<void(LinkType const&, Type const&, Type const&)>& cb)
107 on_creation.connect(cb);
109 LinkType(const std::string& name, const Type* source, const Type* dest, const std::string& alias, Type* parent)
110 : ValueType(PajeEventType::DefineLinkType, name, alias, parent)
112 on_creation(*this, *source, *dest);
114 void start_event(Container* startContainer, const std::string& value, const std::string& key,
115 size_t size = static_cast<size_t>(-1));
116 void end_event(Container* endContainer, const std::string& value, const std::string& key);
119 class EventType : public ValueType {
121 EventType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineEventType, name, parent) {}
124 class StateType : public ValueType {
125 std::vector<StateEvent*> events_;
127 StateType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineStateType, name, parent) {}
128 void set_event(const std::string& value_name);
129 void push_event(const std::string& value_name);
130 void push_event(const std::string& value_name, TIData* extra);
132 void pop_event(TIData* extra);
135 } // namespace simgrid