Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c456e9d41e4673619d80b544fdae7aa2e10eca49
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "src/instr/instr_private.hpp"
8 #include "src/instr/instr_smpi.hpp"
9 #include "src/smpi/include/private.hpp"
10
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
14
15 namespace simgrid {
16 namespace instr {
17
18 PajeEvent::~PajeEvent()
19 {
20   XBT_DEBUG("%s not implemented for %p: event_type=%u, timestamp=%f", __FUNCTION__, this, eventType_, timestamp_);
21 }
22
23 LinkEvent::LinkEvent(double timestamp, container_t container, Type* type, e_event_type event_type, container_t endpoint,
24                      std::string value, std::string key)
25     : LinkEvent(timestamp, container, type, event_type, endpoint, value, key, -1)
26 {
27 }
28
29 LinkEvent::LinkEvent(double timestamp, container_t container, Type* type, e_event_type event_type, container_t endpoint,
30                      std::string value, std::string key, int size)
31     : PajeEvent(container, type, timestamp, event_type), endpoint_(endpoint), value_(value), key_(key), size_(size)
32 {
33   XBT_DEBUG("%s: event_type=%u, timestamp=%f, value:%s", __FUNCTION__, eventType_, timestamp_, value_.c_str());
34   insertIntoBuffer();
35 }
36
37 VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
38     : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
39 {
40   XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, this->timestamp_);
41   insertIntoBuffer();
42 }
43
44 StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value)
45     : StateEvent(timestamp, container, type, event_type, value, nullptr)
46 {
47 }
48
49 StateEvent::StateEvent(double timestamp, Container* container, Type* type, e_event_type event_type, EntityValue* value,
50                        void* extra)
51     : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value), extra_(extra)
52 {
53 #if HAVE_SMPI
54   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
55     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
56     filename                        = loc->filename;
57     linenumber                      = loc->linenumber;
58   }
59 #endif
60
61   XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
62   insertIntoBuffer();
63 };
64
65 void LinkEvent::print()
66 {
67   std::stringstream stream;
68   stream << std::fixed << std::setprecision(TRACE_precision());
69   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
70   if (instr_fmt_type != instr_fmt_paje)
71     return;
72   if (timestamp_ < 1e-12)
73     stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId() << " " << value_;
74   else
75     stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value_;
76
77   stream << " " << endpoint_->getId() << " " << key_;
78
79   if (TRACE_display_sizes()) {
80     stream << " " << size_;
81   }
82   XBT_DEBUG("Dump %s", stream.str().c_str());
83   fprintf(tracing_file, "%s\n", stream.str().c_str());
84 }
85
86 void VariableEvent::print()
87 {
88   std::stringstream stream;
89   stream << std::fixed << std::setprecision(TRACE_precision());
90   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
91   if (instr_fmt_type != instr_fmt_paje)
92     return;
93
94   if (timestamp_ < 1e-12)
95     stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId() << " " << value;
96   else
97     stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value;
98   XBT_DEBUG("Dump %s", stream.str().c_str());
99   fprintf(tracing_file, "%s\n", stream.str().c_str());
100 }
101
102 void StateEvent::print()
103 {
104   std::stringstream stream;
105   stream << std::fixed << std::setprecision(TRACE_precision());
106   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
107   if (instr_fmt_type == instr_fmt_paje) {
108     if (timestamp_ < 1e-12)
109       stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId();
110     else
111       stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId();
112
113     if (value != nullptr) // PAJE_PopState Event does not need to have a value
114       stream << " " << value->getId();
115
116     if (TRACE_display_sizes()) {
117       stream << " ";
118       if (extra_ != nullptr) {
119         stream << static_cast<instr_extra_data>(extra_)->send_size;
120       } else {
121         stream << 0;
122       }
123     }
124 #if HAVE_SMPI
125     if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
126       stream << " \"" << filename << "\" " << linenumber;
127     }
128 #endif
129     XBT_DEBUG("Dump %s", stream.str().c_str());
130     fprintf(tracing_file, "%s\n", stream.str().c_str());
131
132     if (extra_ != nullptr) {
133       if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
134         xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
135       if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
136         xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
137       xbt_free(extra_);
138     }
139   } else if (instr_fmt_type == instr_fmt_TI) {
140     if (extra_ == nullptr)
141       return;
142     instr_extra_data extra = (instr_extra_data)extra_;
143
144     char* process_id = nullptr;
145     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
146     if (container->getName().find("rank-") != 0)
147       process_id = xbt_strdup(container->getCname());
148     else
149       process_id = xbt_strdup(container->getCname() + 5);
150
151     FILE* trace_file = tracing_files.at(container);
152
153     switch (extra->type) {
154       case TRACING_INIT:
155         fprintf(trace_file, "%s init\n", process_id);
156         break;
157       case TRACING_FINALIZE:
158         fprintf(trace_file, "%s finalize\n", process_id);
159         break;
160       case TRACING_SEND:
161         fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
162         break;
163       case TRACING_ISEND:
164         fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
165         break;
166       case TRACING_RECV:
167         fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
168         break;
169       case TRACING_IRECV:
170         fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
171         break;
172       case TRACING_TEST:
173         fprintf(trace_file, "%s test\n", process_id);
174         break;
175       case TRACING_WAIT:
176         fprintf(trace_file, "%s wait\n", process_id);
177         break;
178       case TRACING_WAITALL:
179         fprintf(trace_file, "%s waitAll\n", process_id);
180         break;
181       case TRACING_BARRIER:
182         fprintf(trace_file, "%s barrier\n", process_id);
183         break;
184       case TRACING_BCAST: // rank bcast size (root) (datatype)
185         fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
186         if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
187           fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
188         fprintf(trace_file, "\n");
189         break;
190       case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
191         fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
192         if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
193           fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
194         fprintf(trace_file, "\n");
195         break;
196       case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
197         fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
198                 extra->datatype1);
199         break;
200       case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
201         fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
202                 extra->datatype1, extra->datatype2);
203         break;
204       case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
205         fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
206         for (int i = 0; i < extra->num_processes; i++)
207           fprintf(trace_file, "%d ", extra->sendcounts[i]);
208         fprintf(trace_file, "%d ", extra->recv_size);
209         for (int i = 0; i < extra->num_processes; i++)
210           fprintf(trace_file, "%d ", extra->recvcounts[i]);
211         fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
212         break;
213       case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
214         fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
215                 extra->datatype1, extra->datatype2);
216         break;
217       case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
218         fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
219         for (int i = 0; i < extra->num_processes; i++)
220           fprintf(trace_file, "%d ", extra->recvcounts[i]);
221         fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
222         break;
223       case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
224         fprintf(trace_file, "%s reduceScatter ", process_id);
225         for (int i = 0; i < extra->num_processes; i++)
226           fprintf(trace_file, "%d ", extra->recvcounts[i]);
227         fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
228         break;
229       case TRACING_COMPUTING:
230         fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
231         break;
232       case TRACING_SLEEPING:
233         fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
234         break;
235       case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
236         fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
237         for (int i = 0; i < extra->num_processes; i++)
238           fprintf(trace_file, "%d ", extra->recvcounts[i]);
239         fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
240         break;
241       case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
242         fprintf(trace_file, "%s allGather %d %d %s %s", process_id, extra->send_size, extra->recv_size,
243                 extra->datatype1, extra->datatype2);
244         break;
245       case TRACING_WAITANY:
246       case TRACING_SENDRECV:
247       case TRACING_SCATTER:
248       case TRACING_SCATTERV:
249       case TRACING_SCAN:
250       case TRACING_EXSCAN:
251       case TRACING_COMM_SIZE:
252       case TRACING_COMM_SPLIT:
253       case TRACING_COMM_DUP:
254       case TRACING_SSEND:
255       case TRACING_ISSEND:
256       default:
257         XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->getCname());
258         break;
259     }
260
261     if (extra->recvcounts != nullptr)
262       xbt_free(extra->recvcounts);
263     if (extra->sendcounts != nullptr)
264       xbt_free(extra->sendcounts);
265     xbt_free(process_id);
266     xbt_free(extra);
267
268   } else {
269     THROW_IMPOSSIBLE;
270   }
271 }
272 }
273 }