Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef INSTR_PAJE_TYPES_HPP
7 #define INSTR_PAJE_TYPES_HPP
8
9 #include "src/instr/instr_private.hpp"
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 namespace simgrid {
15 namespace instr {
16 class ContainerType;
17 class EventType;
18
19 long long int new_paje_id();
20
21 class Type {
22   long long int id_ = new_paje_id();
23   std::string name_;
24   std::string color_;
25   Type* parent_;
26   std::map<std::string, std::unique_ptr<Type>, std::less<>> children_;
27   Container* issuer_ = nullptr;
28
29   static xbt::signal<void(Type const&, PajeEventType event_type)> on_creation;
30
31 protected:
32   Container* get_issuer() const { return issuer_; }
33
34 public:
35   static void on_creation_cb(const std::function<void(Type const&, PajeEventType event_type)>& cb)
36   {
37     on_creation.connect(cb);
38   }
39
40   Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color,
41        Type* parent);
42   virtual ~Type() = default;
43
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(); }
51
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);
55
56   template <class T> T* by_name_or_create(const std::string& name)
57   {
58     auto cont = children_.find(name);
59     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
60   }
61
62   Type* set_calling_container(Container* container)
63   {
64     issuer_ = container;
65     return this;
66   }
67 };
68
69 class ContainerType : public Type {
70 public:
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){};
74 };
75
76 class VariableType : public Type {
77   std::vector<VariableEvent*> events_;
78 public:
79   VariableType(const std::string& name, const std::string& color, Type* parent)
80       : Type(PajeEventType::DefineVariableType, name, name, color, parent)
81   {
82   }
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);
87 };
88
89 class ValueType : public Type {
90 public:
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);
99 };
100
101 class LinkType : public ValueType {
102   static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
103
104 public:
105   static void on_creation_cb(const std::function<void(LinkType const&, Type const&, Type const&)>& cb)
106   {
107     on_creation.connect(cb);
108   }
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)
111   {
112     on_creation(*this, *source, *dest);
113   }
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);
117 };
118
119 class EventType : public ValueType {
120 public:
121   EventType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineEventType, name, parent) {}
122 };
123
124 class StateType : public ValueType {
125   std::vector<StateEvent*> events_;
126 public:
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);
131   void pop_event();
132   void pop_event(TIData* extra);
133 };
134 } // namespace instr
135 } // namespace simgrid
136 #endif