1 /* Copyright (c) 2010-2022. 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"
20 enum class PajeEventType : unsigned int {
41 inline std::ostream& operator<<(std::ostream& os, PajeEventType event)
43 return os << static_cast<std::underlying_type_t<PajeEventType>>(event);
47 Container* container_;
49 static xbt::signal<void(PajeEvent&)> on_creation;
50 static xbt::signal<void(PajeEvent const&)> on_destruction;
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); }
57 PajeEventType eventType_;
58 std::stringstream stream_;
60 PajeEvent(Container* container, Type* type, double timestamp, PajeEventType eventType);
63 Container* get_container() const { return container_; }
64 Type* get_type() const { return type_; }
66 virtual void print() = 0;
67 void insert_into_buffer();
70 class VariableEvent : public PajeEvent {
74 VariableEvent(double timestamp, Container* container, Type* type, PajeEventType event_type, double value)
75 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value_(value)
78 void print() override { stream_ << " " << value_; }
81 class StateEvent : public PajeEvent {
84 std::string filename = "(null)";
87 std::unique_ptr<TIData> extra_;
89 static xbt::signal<void(StateEvent const&)> on_destruction;
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;
99 class LinkEvent : public PajeEvent {
100 Container* endpoint_;
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)
115 void print() override;
118 class NewEvent : public PajeEvent {
122 NewEvent(double timestamp, Container* container, Type* type, EntityValue* value)
123 : PajeEvent::PajeEvent(container, type, timestamp, PajeEventType::NewEvent), value(value)
126 void print() override;
129 } // namespace simgrid