Logo AND Algorithmique Numérique Distribuée

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