Logo AND Algorithmique Numérique Distribuée

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