Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert int -> size_t for TRACE_smpi_send (and below).
[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 public:
50   static xbt::signal<void(PajeEvent&)> on_creation;
51   static xbt::signal<void(PajeEvent const&)> on_destruction;
52
53   double timestamp_;
54   PajeEventType eventType_;
55   std::stringstream stream_;
56
57   PajeEvent(Container* container, Type* type, double timestamp, PajeEventType eventType);
58   virtual ~PajeEvent();
59
60   Container* get_container() const { return container_; }
61   Type* get_type() const { return type_; }
62
63   virtual void print() = 0;
64   void insert_into_buffer();
65 };
66
67 class VariableEvent : public PajeEvent {
68   double value_;
69
70 public:
71   VariableEvent(double timestamp, Container* container, Type* type, PajeEventType event_type, double value)
72       : PajeEvent::PajeEvent(container, type, timestamp, event_type), value_(value)
73   {
74   }
75   void print() override { stream_ << " " << value_; }
76 };
77
78 class StateEvent : public PajeEvent {
79   EntityValue* value;
80 #if HAVE_SMPI
81   std::string filename = "(null)";
82   int linenumber       = -1;
83 #endif
84   std::unique_ptr<TIData> extra_;
85
86 public:
87   static xbt::signal<void(StateEvent const&)> on_destruction;
88   StateEvent(Container* container, Type* type, PajeEventType event_type, EntityValue* value, TIData* extra);
89   ~StateEvent() override { on_destruction(*this); }
90   bool has_extra() const { return extra_ != nullptr; }
91   void print() override;
92 };
93
94 class LinkEvent : public PajeEvent {
95   Container* endpoint_;
96   std::string value_;
97   std::string key_;
98   size_t size_;
99
100 public:
101   LinkEvent(Container* container, Type* type, PajeEventType event_type, Container* sourceContainer,
102             const std::string& value, const std::string& key, size_t size = static_cast<size_t>(-1))
103       : PajeEvent(container, type, SIMIX_get_clock(), event_type)
104       , endpoint_(sourceContainer)
105       , value_(value)
106       , key_(key)
107       , size_(size)
108   {
109   }
110   void print() override;
111 };
112
113 class NewEvent : public PajeEvent {
114   EntityValue* value;
115
116 public:
117   NewEvent(double timestamp, Container* container, Type* type, EntityValue* value)
118       : PajeEvent::PajeEvent(container, type, timestamp, PajeEventType::NewEvent), value(value)
119   {
120   }
121   void print() override;
122 };
123 } // namespace instr
124 } // namespace simgrid
125 #endif