Logo AND Algorithmique Numérique Distribuée

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