Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't include <xbt/functional.hpp> when it's not needed.
[simgrid.git] / src / instr / instr_paje_events.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_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 e_event_type : unsigned int {
21   PAJE_DefineContainerType,
22   PAJE_DefineVariableType,
23   PAJE_DefineStateType,
24   PAJE_DefineEventType,
25   PAJE_DefineLinkType,
26   PAJE_DefineEntityValue,
27   PAJE_CreateContainer,
28   PAJE_DestroyContainer,
29   PAJE_SetVariable,
30   PAJE_AddVariable,
31   PAJE_SubVariable,
32   PAJE_SetState,
33   PAJE_PushState,
34   PAJE_PopState,
35   PAJE_ResetState,
36   PAJE_StartLink,
37   PAJE_EndLink,
38   PAJE_NewEvent
39 };
40
41 class PajeEvent {
42   Container* container_;
43   Type* type_;
44 public:
45   static xbt::signal<void(PajeEvent&)> on_creation;
46   static xbt::signal<void(PajeEvent const&)> on_destruction;
47
48   double timestamp_;
49   e_event_type eventType_;
50   std::stringstream stream_;
51
52   PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType);
53   virtual ~PajeEvent();
54
55   Container* get_container() const { return container_; }
56   Type* get_type() const { return type_; }
57
58   virtual void print() = 0;
59   void insert_into_buffer();
60 };
61
62 class VariableEvent : public PajeEvent {
63   double value_;
64
65 public:
66   VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
67       : PajeEvent::PajeEvent(container, type, timestamp, event_type), value_(value)
68   {
69   }
70   void print() override { stream_ << " " << value_; }
71 };
72
73 class StateEvent : public PajeEvent {
74   EntityValue* value;
75 #if HAVE_SMPI
76   std::string filename = "(null)";
77   int linenumber       = -1;
78 #endif
79   std::unique_ptr<TIData> extra_;
80
81 public:
82   static xbt::signal<void(StateEvent const&)> on_destruction;
83   StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra);
84   ~StateEvent() override { on_destruction(*this); }
85   bool has_extra() const { return extra_ != nullptr; }
86   void print() override;
87 };
88
89 class LinkEvent : public PajeEvent {
90   Container* endpoint_;
91   std::string value_;
92   std::string key_;
93   int size_ = -1;
94
95 public:
96   LinkEvent(Container* container, Type* type, e_event_type event_type, Container* sourceContainer,
97             const std::string& value, const std::string& key, int size)
98       : PajeEvent(container, type, SIMIX_get_clock(), event_type)
99       , endpoint_(sourceContainer)
100       , value_(value)
101       , key_(key)
102       , size_(size)
103   {
104   }
105   void print() override;
106 };
107
108 class NewEvent : public PajeEvent {
109   EntityValue* value;
110
111 public:
112   NewEvent(double timestamp, Container* container, Type* type, EntityValue* value)
113       : PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent), value(value)
114   {
115   }
116   void print() override;
117 };
118 } // namespace instr
119 } // namespace simgrid
120 #endif