Logo AND Algorithmique Numérique Distribuée

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