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_, this->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_, this->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 << " " << type->getId() << " " << container->getId();
78 stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId();
79 stream << " " << 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 << " " << type->getId() << " " << container->getId() << " " << value_;
94 stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value_;
96 stream << " " << 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 << " " << type->getId() << " " << container->getId() << " " << value;
116 stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value;
117 XBT_DEBUG("Dump %s", stream.str().c_str());
118 fprintf(tracing_file, "%s\n", stream.str().c_str());
121 void StateEvent::print()
123 std::stringstream stream;
124 stream << std::fixed << std::setprecision(TRACE_precision());
125 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
126 if (instr_fmt_type == instr_fmt_paje) {
127 if (timestamp_ < 1e-12)
128 stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId();
130 stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId();
132 if (value != nullptr) // PAJE_PopState Event does not need to have a value
133 stream << " " << value->getId();
135 if (TRACE_display_sizes()) {
137 if (extra_ != nullptr) {
138 stream << static_cast<instr_extra_data>(extra_)->send_size;
144 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
145 stream << " \"" << filename << "\" " << linenumber;
148 XBT_DEBUG("Dump %s", stream.str().c_str());
149 fprintf(tracing_file, "%s\n", stream.str().c_str());
151 if (extra_ != nullptr) {
152 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
153 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
154 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
155 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
158 } else if (instr_fmt_type == instr_fmt_TI) {
159 if (extra_ == nullptr)
161 instr_extra_data extra = (instr_extra_data)extra_;
163 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
164 if (container->getName().find("rank-") != 0)
165 stream << container->getName() << " ";
167 stream << container->getName().erase(0, 5) << " ";
169 FILE* trace_file = tracing_files.at(container);
171 switch (extra->type) {
175 case TRACING_FINALIZE:
176 stream << "finalize";
179 stream << "send " << extra->dst << " " << extra->send_size << " " << extra->datatype1;
182 stream << "Isend " << extra->dst << " " << extra->send_size << " " << extra->datatype1;
185 stream << "recv " << extra->src << " " << extra->send_size << " " << extra->datatype1;
188 stream << "Irecv " << extra->src << " " << extra->send_size << " " << extra->datatype1;
196 case TRACING_WAITALL:
199 case TRACING_BARRIER:
202 case TRACING_BCAST: // rank bcast size (root) (datatype)
203 stream << "bcast " << extra->send_size;
204 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
205 stream << " " << extra->root << " " << extra->datatype1;
207 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
208 stream << "reduce " << extra->send_size << " " << extra->comp_size;
209 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
210 stream << " " << extra->root << " " << extra->datatype1;
212 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
213 stream << "allReduce " << extra->send_size << " " << extra->comp_size << " " << extra->datatype1;
215 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
216 stream << "allToAll " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
217 stream << extra->datatype2;
219 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
220 stream << "allToAllV " << extra->send_size << " ";
221 for (int i = 0; i < extra->num_processes; i++)
222 stream << extra->sendcounts[i] << " ";
223 stream << extra->recv_size << " ";
224 for (int i = 0; i < extra->num_processes; i++)
225 stream << extra->recvcounts[i] << " ";
226 stream << extra->datatype1 << " " << extra->datatype2;
228 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
229 stream << "gather " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
230 stream << extra->datatype2;
232 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
233 stream << "allGatherV " << extra->send_size;
234 for (int i = 0; i < extra->num_processes; i++)
235 stream << extra->recvcounts[i] << " ";
236 stream << extra->datatype1 << " " << extra->datatype2;
238 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
239 stream << "reduceScatter ";
240 for (int i = 0; i < extra->num_processes; i++)
241 stream << extra->recvcounts[i] << " ";
242 stream << extra->comp_size << " " << extra->datatype1;
244 case TRACING_COMPUTING:
245 stream << "compute " << extra->comp_size;
247 case TRACING_SLEEPING:
248 stream << "sleep " << extra->sleep_duration;
250 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
251 stream << "gatherV " << extra->send_size;
252 for (int i = 0; i < extra->num_processes; i++)
253 stream << extra->recvcounts[i] << " ";
254 stream << extra->root << " " << extra->datatype1 << " " << extra->datatype2;
256 case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
257 stream << "allGather " << extra->send_size << " " << extra->recv_size << " " << extra->datatype1 << " ";
258 stream << extra->datatype2;
261 /* Unimplemented calls are: WAITANY, SENDRECV, SCATTER, SCATTERV, SCAN, EXSCAN, COMM_SIZE, COMM_SPLIT, COMM_DUP,
264 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->getCname());
267 fprintf(trace_file, "%s\n", stream.str().c_str());
269 if (extra->recvcounts != nullptr)
270 xbt_free(extra->recvcounts);
271 if (extra->sendcounts != nullptr)
272 xbt_free(extra->sendcounts);