Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference local variables in src/instr/.
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2019. 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
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
12 extern std::ofstream tracing_file;
13 extern std::map<container_t, std::ofstream*> tracing_files; // TI specific
14
15 namespace simgrid {
16 namespace instr {
17
18 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
19     : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
20 {
21   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
22   if (trace_format == TraceFormat::Paje) {
23     stream_ << std::fixed << std::setprecision(TRACE_precision());
24     stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
25   }
26   insert_into_buffer();
27 }
28
29 void PajeEvent::print()
30 {
31   if (trace_format != TraceFormat::Paje)
32     return;
33
34   XBT_DEBUG("Dump %s", stream_.str().c_str());
35   tracing_file << stream_.str() << std::endl;
36 }
37
38 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
39     : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
40 {
41 #if HAVE_SMPI
42   if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
43     const smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
44     filename                        = loc->filename;
45     linenumber                      = loc->linenumber;
46   }
47 #endif
48 }
49
50 void NewEvent::print()
51 {
52   if (trace_format != TraceFormat::Paje)
53     return;
54
55   stream_ << " " << value->get_id();
56
57   XBT_DEBUG("Dump %s", stream_.str().c_str());
58   tracing_file << stream_.str() << std::endl;
59 }
60
61 void LinkEvent::print()
62 {
63   if (trace_format != TraceFormat::Paje)
64     return;
65
66   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
67
68   if (TRACE_display_sizes() && size_ != -1)
69     stream_ << " " << size_;
70
71   XBT_DEBUG("Dump %s", stream_.str().c_str());
72   tracing_file << stream_.str() << std::endl;
73 }
74
75 void VariableEvent::print()
76 {
77   if (trace_format != TraceFormat::Paje)
78     return;
79
80   stream_ << " " << value_;
81
82   XBT_DEBUG("Dump %s", stream_.str().c_str());
83   tracing_file << stream_.str() << std::endl;
84 }
85
86 void StateEvent::print()
87 {
88   if (trace_format == TraceFormat::Paje) {
89     if (value != nullptr) // PAJE_PopState Event does not need to have a value
90       stream_ << " " << value->get_id();
91
92     if (TRACE_display_sizes())
93       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : "");
94
95 #if HAVE_SMPI
96     if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
97       stream_ << " \"" << filename << "\" " << linenumber;
98     }
99 #endif
100     XBT_DEBUG("Dump %s", stream_.str().c_str());
101     tracing_file << stream_.str() << std::endl;
102   } else if (trace_format == TraceFormat::Ti) {
103     if (extra_ == nullptr)
104       return;
105
106     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
107     std::string container_name(get_container()->get_name());
108     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
109     if (get_container()->get_name().find("rank-") == 0) {
110       /* Subtract -1 because this is the process id and we transform it to the rank id */
111       container_name=std::to_string(stoi(container_name.erase(0, 5)) - 1);
112     }
113 #if HAVE_SMPI
114     if (config::get_value<bool>("smpi/trace-call-location")) {
115       stream_ << container_name << " location " << filename << " " << linenumber << std::endl ;
116     }
117 #endif
118     stream_ << container_name << " " << extra_->print();
119     *tracing_files.at(get_container()) << stream_.str() << std::endl;
120   } else {
121     THROW_IMPOSSIBLE;
122   }
123 }
124 } // namespace instr
125 } // namespace simgrid