Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stop trying to build on native WIN32, it's broken anyway
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2023. 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::instr {
15 class ContainerType;
16 class EventType;
17
18 long long int new_paje_id();
19
20 class Type {
21   long long int id_ = new_paje_id();
22   std::string name_;
23   std::string color_;
24   Type* parent_;
25   std::map<std::string, std::unique_ptr<Type>, std::less<>> children_;
26   Container* issuer_ = nullptr;
27
28   static xbt::signal<void(Type const&, PajeEventType event_type)> on_creation;
29
30 protected:
31   Container* get_issuer() const { return issuer_; }
32
33 public:
34   static void on_creation_cb(const std::function<void(Type const&, PajeEventType event_type)>& cb)
35   {
36     on_creation.connect(cb);
37   }
38
39   Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color,
40        Type* parent);
41   virtual ~Type() = default;
42
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(); }
50
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);
54
55   template <class T> T* by_name_or_create(const std::string& name)
56   {
57     auto cont = children_.find(name);
58     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
59   }
60
61   Type* set_calling_container(Container* container)
62   {
63     issuer_ = container;
64     return this;
65   }
66 };
67
68 class ContainerType : public Type {
69 public:
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){};
73 };
74
75 class VariableType : public Type {
76   std::vector<VariableEvent*> events_;
77 public:
78   VariableType(const std::string& name, const std::string& color, Type* parent)
79       : Type(PajeEventType::DefineVariableType, name, name, color, parent)
80   {
81   }
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);
86 };
87
88 class ValueType : public Type {
89 public:
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);
98 };
99
100 class LinkType : public ValueType {
101   static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
102
103 public:
104   static void on_creation_cb(const std::function<void(LinkType const&, Type const&, Type const&)>& cb)
105   {
106     on_creation.connect(cb);
107   }
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)
110   {
111     on_creation(*this, *source, *dest);
112   }
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);
116 };
117
118 class EventType : public ValueType {
119 public:
120   EventType(const std::string& name, Type* parent) : ValueType(PajeEventType::DefineEventType, name, parent) {}
121 };
122
123 class StateType : public ValueType {
124   std::vector<StateEvent*> events_;
125 public:
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);
130   void pop_event();
131   void pop_event(TIData* extra);
132 };
133 } // namespace simgrid::instr
134 #endif