1 /* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef INSTR_PAJE_EVENTS_HPP
7 #define INSTR_PAJE_EVENTS_HPP
9 #include "src/instr/instr_private.hpp"
10 #include "src/internal_config.h"
15 namespace simgrid::instr {
19 enum class PajeEventType : unsigned int {
40 inline std::ostream& operator<<(std::ostream& os, PajeEventType event)
42 return os << static_cast<std::underlying_type_t<PajeEventType>>(event);
46 Container* container_;
48 static xbt::signal<void(PajeEvent&)> on_creation;
49 static xbt::signal<void(PajeEvent const&)> on_destruction;
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); }
56 PajeEventType eventType_;
57 std::stringstream stream_;
59 PajeEvent(Container* container, Type* type, double timestamp, PajeEventType eventType);
62 Container* get_container() const { return container_; }
63 Type* get_type() const { return type_; }
65 virtual void print() = 0;
66 void insert_into_buffer();
69 class VariableEvent : public PajeEvent {
73 VariableEvent(double timestamp, Container* container, Type* type, PajeEventType event_type, double value)
74 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value_(value)
77 void print() override { stream_ << " " << value_; }
80 class StateEvent : public PajeEvent {
83 std::string filename = "(null)";
86 std::unique_ptr<TIData> extra_;
88 static xbt::signal<void(StateEvent const&)> on_destruction;
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;
98 class LinkEvent : public PajeEvent {
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)
114 void print() override;
117 class NewEvent : public PajeEvent {
121 NewEvent(double timestamp, Container* container, Type* type, EntityValue* value)
122 : PajeEvent::PajeEvent(container, type, timestamp, PajeEventType::NewEvent), value(value)
125 void print() override;
127 } // namespace simgrid::instr