1 /* Copyright (c) 2012-2017. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "src/instr/instr_private.hpp"
8 #include "src/instr/instr_smpi.hpp"
9 #include "src/smpi/include/private.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
12 extern FILE* tracing_file;
13 std::map<container_t, FILE*> tracing_files; // TI specific
18 NewEvent::NewEvent(double timestamp, container_t container, Type* type, EntityValue* val)
19 : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent), val(val)
21 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
25 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
26 std::string value, std::string key)
27 : LinkEvent(container, type, event_type, endpoint, value, key, -1)
31 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
32 std::string value, std::string key, int size)
33 : PajeEvent(container, type, SIMIX_get_clock(), event_type)
39 XBT_DEBUG("%s: event_type=%u, timestamp=%f, value:%s", __FUNCTION__, eventType_, timestamp_, value_.c_str());
43 VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
44 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
46 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
50 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value)
51 : StateEvent(container, type, event_type, value, nullptr)
55 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, void* extra)
56 : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
59 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
60 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
61 filename = loc->filename;
62 linenumber = loc->linenumber;
66 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
70 void NewEvent::print()
72 std::stringstream stream;
73 stream << std::fixed << std::setprecision(TRACE_precision());
74 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
75 if (instr_fmt_type != instr_fmt_paje)
78 if (timestamp_ < 1e-12)
79 stream << eventType_ << " " << 0 << " ";
81 stream << eventType_ << " " << timestamp_ << " ";
82 stream << getType()->getId() << " " << getContainer()->getId() << " " << val->getId();
83 XBT_DEBUG("Dump %s", stream.str().c_str());
84 fprintf(tracing_file, "%s\n", stream.str().c_str());
87 void LinkEvent::print()
89 std::stringstream stream;
90 stream << std::fixed << std::setprecision(TRACE_precision());
91 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
92 if (instr_fmt_type != instr_fmt_paje)
94 if (timestamp_ < 1e-12)
95 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
97 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
99 stream << " " << value_ << " " << endpoint_->getId() << " " << key_;
101 if (TRACE_display_sizes()) {
102 stream << " " << size_;
104 XBT_DEBUG("Dump %s", stream.str().c_str());
105 fprintf(tracing_file, "%s\n", stream.str().c_str());
108 void VariableEvent::print()
110 std::stringstream stream;
111 stream << std::fixed << std::setprecision(TRACE_precision());
112 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
113 if (instr_fmt_type != instr_fmt_paje)
116 if (timestamp_ < 1e-12)
117 stream << eventType_ << " " << 0 << " ";
119 stream << eventType_ << " " << timestamp_ << " ";
120 stream << getType()->getId() << " " << getContainer()->getId() << " " << value;
121 XBT_DEBUG("Dump %s", stream.str().c_str());
122 fprintf(tracing_file, "%s\n", stream.str().c_str());
125 void StateEvent::print()
127 std::stringstream stream;
128 stream << std::fixed << std::setprecision(TRACE_precision());
129 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
130 if (instr_fmt_type == instr_fmt_paje) {
131 if (timestamp_ < 1e-12)
132 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
134 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
136 if (value != nullptr) // PAJE_PopState Event does not need to have a value
137 stream << " " << value->getId();
139 if (TRACE_display_sizes()) {
141 if (extra_ != nullptr) {
142 stream << static_cast<instr_extra_data>(extra_)->send_size;
148 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
149 stream << " \"" << filename << "\" " << linenumber;
152 XBT_DEBUG("Dump %s", stream.str().c_str());
153 fprintf(tracing_file, "%s\n", stream.str().c_str());
155 if (extra_ != nullptr) {
156 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
157 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
158 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
159 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
162 } else if (instr_fmt_type == instr_fmt_TI) {
163 if (extra_ == nullptr)
165 instr_extra_data extra = (instr_extra_data)extra_;
167 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
168 if (getContainer()->getName().find("rank-") != 0)
169 stream << getContainer()->getName() << " ";
171 stream << getContainer()->getName().erase(0, 5) << " ";
173 FILE* trace_file = tracing_files.at(getContainer());
175 switch (extra->type) {
179 case TRACING_FINALIZE:
180 stream << "finalize";
183 stream << "send " << extra->dst << " " << extra->send_size << " " << extra->datatype1;
186 stream << "Isend " << extra->dst << " " << extra->send_size << " " << extra->datatype1;
189 stream << "recv " << extra->src << " " << extra->send_size << " " << extra->datatype1;
192 stream << "Irecv " << extra->src << " " << extra->send_size << " " << extra->datatype1;
200 case TRACING_WAITALL:
203 case TRACING_BARRIER:
206 case TRACING_BCAST: // rank bcast size (root) (datatype)
207 stream << "bcast " << extra->send_size;
208 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
209 stream << " " << extra->root << " " << extra->datatype1;
211 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
212 stream << "reduce " << extra->send_size << " " << extra->comp_size;
213 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
214 stream << " " << extra->root << " " << extra->datatype1;
216 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
217 stream << "allReduce " << extra->send_size << " " << extra->comp_size << " " << extra->datatype1;
219 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
220 stream << "allToAll " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
221 stream << extra->datatype2;
223 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
224 stream << "allToAllV " << extra->send_size << " ";
225 for (int i = 0; i < extra->num_processes; i++)
226 stream << extra->sendcounts[i] << " ";
227 stream << extra->recv_size << " ";
228 for (int i = 0; i < extra->num_processes; i++)
229 stream << extra->recvcounts[i] << " ";
230 stream << extra->datatype1 << " " << extra->datatype2;
232 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
233 stream << "gather " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
234 stream << extra->datatype2;
236 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
237 stream << "allGatherV " << extra->send_size;
238 for (int i = 0; i < extra->num_processes; i++)
239 stream << extra->recvcounts[i] << " ";
240 stream << extra->datatype1 << " " << extra->datatype2;
242 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
243 stream << "reduceScatter ";
244 for (int i = 0; i < extra->num_processes; i++)
245 stream << extra->recvcounts[i] << " ";
246 stream << extra->comp_size << " " << extra->datatype1;
248 case TRACING_COMPUTING:
249 stream << "compute " << extra->comp_size;
251 case TRACING_SLEEPING:
252 stream << "sleep " << extra->sleep_duration;
254 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
255 stream << "gatherV " << extra->send_size;
256 for (int i = 0; i < extra->num_processes; i++)
257 stream << extra->recvcounts[i] << " ";
258 stream << extra->root << " " << extra->datatype1 << " " << extra->datatype2;
260 case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
261 stream << "allGather " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
262 stream << extra->datatype2;
265 /* Unimplemented calls are: WAITANY, SENDRECV, SCATTER, SCATTERV, SCAN, EXSCAN, COMM_SIZE, COMM_SPLIT, COMM_DUP,
268 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->getCname());
271 fprintf(trace_file, "%s\n", stream.str().c_str());
273 if (extra->recvcounts != nullptr)
274 xbt_free(extra->recvcounts);
275 if (extra->sendcounts != nullptr)
276 xbt_free(extra->sendcounts);