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(double timestamp, container_t container, Type* type, e_event_type event_type, container_t endpoint,
26 std::string value, std::string key)
27 : LinkEvent(timestamp, container, type, event_type, endpoint, value, key, -1)
31 LinkEvent::LinkEvent(double timestamp, 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, timestamp, event_type), endpoint_(endpoint), value_(value), key_(key), size_(size)
35 XBT_DEBUG("%s: event_type=%u, timestamp=%f, value:%s", __FUNCTION__, eventType_, timestamp_, value_.c_str());
39 VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
40 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
42 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
46 StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value)
47 : StateEvent(timestamp, container, type, event_type, value, nullptr)
51 StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value,
53 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value), extra_(extra)
56 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
57 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
58 filename = loc->filename;
59 linenumber = loc->linenumber;
63 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
67 void NewEvent::print()
69 std::stringstream stream;
70 stream << std::fixed << std::setprecision(TRACE_precision());
71 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
72 if (instr_fmt_type != instr_fmt_paje)
75 if (timestamp_ < 1e-12)
76 stream << eventType_ << " " << 0 << " ";
78 stream << eventType_ << " " << timestamp_ << " ";
79 stream << getType()->getId() << " " << getContainer()->getId() << " " << val->getId();
80 XBT_DEBUG("Dump %s", stream.str().c_str());
81 fprintf(tracing_file, "%s\n", stream.str().c_str());
84 void LinkEvent::print()
86 std::stringstream stream;
87 stream << std::fixed << std::setprecision(TRACE_precision());
88 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
89 if (instr_fmt_type != instr_fmt_paje)
91 if (timestamp_ < 1e-12)
92 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
94 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
96 stream << " " << value_ << " " << endpoint_->getId() << " " << key_;
98 if (TRACE_display_sizes()) {
99 stream << " " << size_;
101 XBT_DEBUG("Dump %s", stream.str().c_str());
102 fprintf(tracing_file, "%s\n", stream.str().c_str());
105 void VariableEvent::print()
107 std::stringstream stream;
108 stream << std::fixed << std::setprecision(TRACE_precision());
109 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
110 if (instr_fmt_type != instr_fmt_paje)
113 if (timestamp_ < 1e-12)
114 stream << eventType_ << " " << 0 << " ";
116 stream << eventType_ << " " << timestamp_ << " ";
117 stream << getType()->getId() << " " << getContainer()->getId() << " " << value;
118 XBT_DEBUG("Dump %s", stream.str().c_str());
119 fprintf(tracing_file, "%s\n", stream.str().c_str());
122 void StateEvent::print()
124 std::stringstream stream;
125 stream << std::fixed << std::setprecision(TRACE_precision());
126 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
127 if (instr_fmt_type == instr_fmt_paje) {
128 if (timestamp_ < 1e-12)
129 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
131 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
133 if (value != nullptr) // PAJE_PopState Event does not need to have a value
134 stream << " " << value->getId();
136 if (TRACE_display_sizes()) {
138 if (extra_ != nullptr) {
139 stream << static_cast<instr_extra_data>(extra_)->send_size;
145 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
146 stream << " \"" << filename << "\" " << linenumber;
149 XBT_DEBUG("Dump %s", stream.str().c_str());
150 fprintf(tracing_file, "%s\n", stream.str().c_str());
152 if (extra_ != nullptr) {
153 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
154 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
155 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
156 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
159 } else if (instr_fmt_type == instr_fmt_TI) {
160 if (extra_ == nullptr)
162 instr_extra_data extra = (instr_extra_data)extra_;
164 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
165 if (getContainer()->getName().find("rank-") != 0)
166 stream << getContainer()->getName() << " ";
168 stream << getContainer()->getName().erase(0, 5) << " ";
170 FILE* trace_file = tracing_files.at(getContainer());
172 switch (extra->type) {
176 case TRACING_FINALIZE:
177 stream << "finalize";
180 stream << "send " << extra->dst << " " << extra->send_size << " " << extra->datatype1;
183 stream << "Isend " << extra->dst << " " << extra->send_size << " " << extra->datatype1;
186 stream << "recv " << extra->src << " " << extra->send_size << " " << extra->datatype1;
189 stream << "Irecv " << extra->src << " " << extra->send_size << " " << extra->datatype1;
197 case TRACING_WAITALL:
200 case TRACING_BARRIER:
203 case TRACING_BCAST: // rank bcast size (root) (datatype)
204 stream << "bcast " << extra->send_size;
205 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
206 stream << " " << extra->root << " " << extra->datatype1;
208 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
209 stream << "reduce " << extra->send_size << " " << extra->comp_size;
210 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
211 stream << " " << extra->root << " " << extra->datatype1;
213 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
214 stream << "allReduce " << extra->send_size << " " << extra->comp_size << " " << extra->datatype1;
216 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
217 stream << "allToAll " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
218 stream << extra->datatype2;
220 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
221 stream << "allToAllV " << extra->send_size << " ";
222 for (int i = 0; i < extra->num_processes; i++)
223 stream << extra->sendcounts[i] << " ";
224 stream << extra->recv_size << " ";
225 for (int i = 0; i < extra->num_processes; i++)
226 stream << extra->recvcounts[i] << " ";
227 stream << extra->datatype1 << " " << extra->datatype2;
229 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
230 stream << "gather " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
231 stream << extra->datatype2;
233 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
234 stream << "allGatherV " << extra->send_size;
235 for (int i = 0; i < extra->num_processes; i++)
236 stream << extra->recvcounts[i] << " ";
237 stream << extra->datatype1 << " " << extra->datatype2;
239 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
240 stream << "reduceScatter ";
241 for (int i = 0; i < extra->num_processes; i++)
242 stream << extra->recvcounts[i] << " ";
243 stream << extra->comp_size << " " << extra->datatype1;
245 case TRACING_COMPUTING:
246 stream << "compute " << extra->comp_size;
248 case TRACING_SLEEPING:
249 stream << "sleep " << extra->sleep_duration;
251 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
252 stream << "gatherV " << extra->send_size;
253 for (int i = 0; i < extra->num_processes; i++)
254 stream << extra->recvcounts[i] << " ";
255 stream << extra->root << " " << extra->datatype1 << " " << extra->datatype2;
257 case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
258 stream << "allGather " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
259 stream << extra->datatype2;
262 /* Unimplemented calls are: WAITANY, SENDRECV, SCATTER, SCATTERV, SCAN, EXSCAN, COMM_SIZE, COMM_SPLIT, COMM_DUP,
265 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->getCname());
268 fprintf(trace_file, "%s\n", stream.str().c_str());
270 if (extra->recvcounts != nullptr)
271 xbt_free(extra->recvcounts);
272 if (extra->sendcounts != nullptr)
273 xbt_free(extra->sendcounts);