Logo AND Algorithmique Numérique Distribuée

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