Logo AND Algorithmique Numérique Distribuée

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