Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert int -> size_t for TRACE_smpi_send (and below).
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2021. 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* father_;
26   std::map<std::string, std::unique_ptr<Type>, std::less<>> children_;
27   Container* issuer_ = nullptr;
28
29 protected:
30   Container* get_issuer() const { return issuer_; }
31
32 public:
33   static xbt::signal<void(Type const&, PajeEventType event_type)> on_creation;
34
35   Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color,
36        Type* father);
37   virtual ~Type() = default;
38
39   long long int get_id() const { return id_; }
40   const std::string& get_name() const { return name_; }
41   const char* get_cname() const { return name_.c_str(); }
42   const std::string& get_color() const { return color_; }
43   Type* get_father() const { return father_; }
44   const std::map<std::string, std::unique_ptr<Type>, std::less<>>& get_children() const { return children_; }
45   bool is_colored() const { return not color_.empty(); }
46
47   Type* by_name(const std::string& name);
48   LinkType* by_name_or_create(const std::string& name, const Type* source, const Type* dest);
49   VariableType* by_name_or_create(const std::string& name, const std::string& color);
50
51   template <class T> T* by_name_or_create(const std::string& name)
52   {
53     auto cont = children_.find(name);
54     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
55   }
56
57   Type* set_calling_container(Container* container)
58   {
59     issuer_ = container;
60     return this;
61   }
62 };
63
64 class ContainerType : public Type {
65 public:
66   explicit ContainerType(const std::string& name) : Type(PajeEventType::DefineContainerType, name, name, "", nullptr){};
67   ContainerType(const std::string& name, Type* father)
68       : Type(PajeEventType::DefineContainerType, name, name, "", father){};
69 };
70
71 class VariableType : public Type {
72   std::vector<VariableEvent*> events_;
73 public:
74   VariableType(const std::string& name, const std::string& color, Type* father)
75       : Type(PajeEventType::DefineVariableType, name, name, color, father)
76   {
77   }
78   void instr_event(double now, double delta, const char* resource, double value);
79   void set_event(double timestamp, double value);
80   void add_event(double timestamp, double value);
81   void sub_event(double timestamp, double value);
82 };
83
84 class ValueType : public Type {
85 public:
86   std::map<std::string, EntityValue, std::less<>> values_;
87   ValueType(PajeEventType event_type, const std::string& name, const std::string& alias, Type* father)
88       : Type(event_type, name, alias, "", father){};
89   ValueType(PajeEventType event_type, const std::string& name, Type* father)
90       : Type(event_type, name, name, "", father){};
91   void add_entity_value(const std::string& name, const std::string& color);
92   void add_entity_value(const std::string& name);
93   EntityValue* get_entity_value(const std::string& name);
94 };
95
96 class LinkType : public ValueType {
97 public:
98   static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
99   LinkType(const std::string& name, const Type* source, const Type* dest, const std::string& alias, Type* father)
100       : ValueType(PajeEventType::DefineLinkType, name, alias, father)
101   {
102     on_creation(*this, *source, *dest);
103   }
104   void start_event(Container* startContainer, const std::string& value, const std::string& key,
105                    size_t size = static_cast<size_t>(-1));
106   void end_event(Container* endContainer, const std::string& value, const std::string& key);
107 };
108
109 class EventType : public ValueType {
110 public:
111   EventType(const std::string& name, Type* father) : ValueType(PajeEventType::DefineEventType, name, father) {}
112 };
113
114 class StateType : public ValueType {
115   std::vector<StateEvent*> events_;
116 public:
117   StateType(const std::string& name, Type* father) : ValueType(PajeEventType::DefineStateType, name, father) {}
118   void set_event(const std::string& value_name);
119   void push_event(const std::string& value_name);
120   void push_event(const std::string& value_name, TIData* extra);
121   void pop_event();
122   void pop_event(TIData* extra);
123 };
124 } // namespace instr
125 } // namespace simgrid
126 #endif