Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Concatenate nested namespaces (sonar).
[simgrid.git] / src / instr / instr_paje_events.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_EVENTS_HPP
7 #define INSTR_PAJE_EVENTS_HPP
8
9 #include "src/instr/instr_private.hpp"
10 #include "src/internal_config.h"
11 #include <memory>
12 #include <sstream>
13 #include <string>
14
15 namespace simgrid::instr {
16 class EntityValue;
17 class TIData;
18
19 enum class PajeEventType : unsigned int {
20   DefineContainerType,
21   DefineVariableType,
22   DefineStateType,
23   DefineEventType,
24   DefineLinkType,
25   DefineEntityValue,
26   CreateContainer,
27   DestroyContainer,
28   SetVariable,
29   AddVariable,
30   SubVariable,
31   SetState,
32   PushState,
33   PopState,
34   ResetState,
35   StartLink,
36   EndLink,
37   NewEvent
38 };
39
40 inline std::ostream& operator<<(std::ostream& os, PajeEventType event)
41 {
42   return os << static_cast<std::underlying_type_t<PajeEventType>>(event);
43 }
44
45 class PajeEvent {
46   Container* container_;
47   Type* type_;
48   static xbt::signal<void(PajeEvent&)> on_creation;
49   static xbt::signal<void(PajeEvent const&)> on_destruction;
50
51 public:
52   static void on_creation_cb(const std::function<void(PajeEvent&)>& cb) { on_creation.connect(cb); }
53   static void on_destruction_cb(const std::function<void(PajeEvent const&)>& cb) { on_destruction.connect(cb); }
54
55   double timestamp_;
56   PajeEventType eventType_;
57   std::stringstream stream_;
58
59   PajeEvent(Container* container, Type* type, double timestamp, PajeEventType eventType);
60   virtual ~PajeEvent();
61
62   Container* get_container() const { return container_; }
63   Type* get_type() const { return type_; }
64
65   virtual void print() = 0;
66   void insert_into_buffer();
67 };
68
69 class VariableEvent : public PajeEvent {
70   double value_;
71
72 public:
73   VariableEvent(double timestamp, Container* container, Type* type, PajeEventType event_type, double value)
74       : PajeEvent::PajeEvent(container, type, timestamp, event_type), value_(value)
75   {
76   }
77   void print() override { stream_ << " " << value_; }
78 };
79
80 class StateEvent : public PajeEvent {
81   EntityValue* value;
82 #if HAVE_SMPI
83   std::string filename = "(null)";
84   int linenumber       = -1;
85 #endif
86   std::unique_ptr<TIData> extra_;
87
88   static xbt::signal<void(StateEvent const&)> on_destruction;
89
90 public:
91   static void on_destruction_cb(const std::function<void(StateEvent const&)>& cb) { on_destruction.connect(cb); }
92   StateEvent(Container* container, Type* type, PajeEventType event_type, EntityValue* value, TIData* extra);
93   ~StateEvent() override { on_destruction(*this); }
94   bool has_extra() const { return extra_ != nullptr; }
95   void print() override;
96 };
97
98 class LinkEvent : public PajeEvent {
99   Container* endpoint_;
100   std::string value_;
101   std::string key_;
102   size_t size_;
103
104 public:
105   LinkEvent(Container* container, Type* type, PajeEventType event_type, Container* sourceContainer,
106             const std::string& value, const std::string& key, size_t size = static_cast<size_t>(-1))
107       : PajeEvent(container, type, simgrid_get_clock(), event_type)
108       , endpoint_(sourceContainer)
109       , value_(value)
110       , key_(key)
111       , size_(size)
112   {
113   }
114   void print() override;
115 };
116
117 class NewEvent : public PajeEvent {
118   EntityValue* value;
119
120 public:
121   NewEvent(double timestamp, Container* container, Type* type, EntityValue* value)
122       : PajeEvent::PajeEvent(container, type, timestamp, PajeEventType::NewEvent), value(value)
123   {
124   }
125   void print() override;
126 };
127 } // namespace simgrid::instr
128 #endif