Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2023. 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 #include "src/instr/instr_private.hpp"
7 #include "src/instr/instr_smpi.hpp"
8 #include "src/smpi/include/private.hpp"
9 #include "xbt/ex.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
12
13 namespace simgrid::instr {
14
15 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, PajeEventType eventType)
16     : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
17 {
18   on_creation(*this);
19   insert_into_buffer();
20 }
21
22 PajeEvent::~PajeEvent()
23 {
24   on_destruction(*this);
25 }
26
27 StateEvent::StateEvent(Container* container, Type* type, PajeEventType event_type, EntityValue* value, TIData* extra)
28     : PajeEvent::PajeEvent(container, type, simgrid_get_clock(), event_type), value(value), extra_(extra)
29 {
30 #if HAVE_SMPI
31   if (smpi_cfg_trace_call_location()) {
32     const smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
33     filename                        = loc->filename;
34     linenumber                      = loc->linenumber;
35   }
36 #endif
37 }
38
39 void NewEvent::print()
40 {
41   stream_ << " " << value->get_id();
42 }
43
44 void LinkEvent::print()
45 {
46   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
47
48   if (TRACE_display_sizes() && size_ != static_cast<size_t>(-1))
49     stream_ << " " << size_;
50 }
51
52 void StateEvent::print()
53 {
54   if (trace_format == TraceFormat::Paje) {
55     if (value != nullptr) // PajeEventType::PopState Event does not need to have a value
56       stream_ << " " << value->get_id();
57
58     if (TRACE_display_sizes())
59       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : "");
60
61 #if HAVE_SMPI
62     if (smpi_cfg_trace_call_location())
63       stream_ << " \"" << filename << "\" " << linenumber;
64 #endif
65   } else if (trace_format == TraceFormat::Ti) {
66     if (extra_ == nullptr)
67       return;
68
69     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
70     std::string container_name(get_container()->get_name());
71     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
72     if (get_container()->get_name().find("rank-") == 0) {
73       /* Subtract -1 because this is the process id and we transform it to the rank id */
74       container_name=std::to_string(stoi(container_name.erase(0, 5)) - 1);
75     }
76 #if HAVE_SMPI
77     if (smpi_cfg_trace_call_location())
78       stream_ << container_name << " location " << filename << " " << linenumber << '\n';
79 #endif
80     stream_ << container_name << " " << extra_->print();
81   } else {
82     THROW_IMPOSSIBLE;
83   }
84 }
85 } // namespace simgrid::instr