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"
14 namespace simgrid::instr {
18 long long int new_paje_id();
21 long long int id_ = new_paje_id();
25 std::map<std::string, std::unique_ptr<Type>, std::less<>> children_;
26 Container* issuer_ = nullptr;
28 static xbt::signal<void(Type const&, PajeEventType event_type)> on_creation;
31 Container* get_issuer() const { return issuer_; }
34 static void on_creation_cb(const std::function<void(Type const&, PajeEventType event_type)>& cb)
36 on_creation.connect(cb);
39 Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color,
41 virtual ~Type() = default;
43 long long int get_id() const { return id_; }
44 const std::string& get_name() const { return name_; }
45 const char* get_cname() const { return name_.c_str(); }
46 const std::string& get_color() const { return color_; }
47 Type* get_parent() const { return parent_; }
48 const std::map<std::string, std::unique_ptr<Type>, std::less<>>& get_children() const { return children_; }
49 bool is_colored() const { return not color_.empty(); }
51 Type* by_name(const std::string& name);
52 LinkType* by_name_or_create(const std::string& name, const Type* source, const Type* dest);
53 VariableType* by_name_or_create(const std::string& name, const std::string& color);
55 template <class T> T* by_name_or_create(const std::string& name)
57 auto cont = children_.find(name);
58 return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
61 Type* set_calling_container(Container* container)
68 class ContainerType : public Type {
70 explicit ContainerType(const std::string& name) : Type(PajeEventType::DefineContainerType, name, name, "", nullptr){};
71 ContainerType(const std::string& name, Type* parent)
72 : Type(PajeEventType::DefineContainerType, name, name, "", parent){};
75 class VariableType : public Type {
76 std::vector<VariableEvent*> events_;
78 VariableType(const std::string& name, const std::string& color, Type* parent)
79 : Type(PajeEventType::DefineVariableType, name, name, color, parent)
82 void instr_event(double now, double delta, const char* resource, double value);
83 void set_event(double timestamp, double value);
84 void add_event(double timestamp, double value);
85 void sub_event(double timestamp, double value);
88 class ValueType : public Type {
90 std::map<std::string, EntityValue, std::less<>> values_;
91 ValueType(PajeEventType event_type, const std::string& name, const std::string& alias, Type* parent)
92 : Type(event_type, name, alias, "", parent){};
93 ValueType(PajeEventType event_type, const std::string& name, Type* parent)
94 : Type(event_type, name, name, "", parent){};
95 void add_entity_value(const std::string& name, const std::string& color);
96 void add_entity_value(const std::string& name);
97 EntityValue* get_entity_value(const std::string& name);
100 class LinkType : public ValueType {
101 static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
104 static void on_creation_cb(const std::function<void(LinkType const&, Type const&, Type const&)>& cb)
106 on_creation.connect(cb);
108 LinkType(const std::string& name, const Type* source, const Type* dest, const std::string& alias, Type* parent)
109 : ValueType(PajeEventType::DefineLinkType, name, alias, parent)
111 on_creation(*this, *source, *dest);
113 void start_event(Container* startContainer, const std::string& value, const std::string& key,
114 size_t size = static_cast<size_t>(-1));
115 void end_event(Container* endContainer, const std::string& value, const std::string& key);
118 class EventType : public ValueType {
120 EventType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineEventType, name, parent) {}
123 class StateType : public ValueType {
124 std::vector<StateEvent*> events_;
126 StateType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineStateType, name, parent) {}
127 void set_event(const std::string& value_name);
128 void push_event(const std::string& value_name);
129 void push_event(const std::string& value_name, TIData* extra);
131 void pop_event(TIData* extra);
133 } // namespace simgrid::instr