Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into actor-priority
[simgrid.git] / src / instr / instr_paje_trace.cpp
1 /* Copyright (c) 2010-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 "simgrid/sg_config.h"
8 #include "src/instr/instr_private.hpp"
9 #include "src/instr/instr_smpi.hpp"
10 #include "src/smpi/include/private.hpp"
11 #include "typeinfo"
12 #include "xbt/virtu.h" /* sg_cmdline */
13 #include <fstream>
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
16
17 static std::stringstream stream;
18 FILE *tracing_file = nullptr;
19
20 std::map<container_t, FILE*> tracing_files; // TI specific
21
22 std::vector<simgrid::instr::PajeEvent*> buffer;
23 void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf);
24
25 void dump_comment(std::string comment)
26 {
27   if (comment.empty())
28     return;
29   fprintf(tracing_file, "# %s\n", comment.c_str());
30 }
31
32 void dump_comment_file(std::string filename)
33 {
34   if (filename.empty())
35     return;
36   std::ifstream* fs = new std::ifstream();
37   fs->open(filename.c_str(), std::ifstream::in);
38
39   if (fs->fail()) {
40     THROWF(system_error, 1, "Comment file %s could not be opened for reading.", filename.c_str());
41   }
42   while (not fs->eof()) {
43     std::string line;
44     fprintf (tracing_file, "# ");
45     std::getline(*fs, line);
46     fprintf(tracing_file, "%s", line.c_str());
47   }
48   fs->close();
49 }
50
51 double TRACE_last_timestamp_to_dump = 0;
52 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
53 void TRACE_paje_dump_buffer(bool force)
54 {
55   if (not TRACE_is_enabled())
56     return;
57   XBT_DEBUG("%s: dump until %f. starts", __FUNCTION__, TRACE_last_timestamp_to_dump);
58   if (force){
59     for (auto const& event : buffer) {
60       event->print();
61       delete event;
62     }
63     buffer.clear();
64   }else{
65     std::vector<simgrid::instr::PajeEvent*>::iterator i = buffer.begin();
66     for (auto const& event : buffer) {
67       double head_timestamp = event->timestamp_;
68       if (head_timestamp > TRACE_last_timestamp_to_dump)
69         break;
70       event->print();
71       delete event;
72       ++i;
73     }
74     buffer.erase(buffer.begin(), i);
75   }
76   XBT_DEBUG("%s: ends", __FUNCTION__);
77 }
78
79 void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf)
80 {
81   return;
82   XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
83   for (auto const& event : *buf) {
84     event->print();
85     XBT_DEBUG("%p %s", event, stream.str().c_str());
86     stream.str("");
87     stream.clear();
88   }
89   XBT_DEBUG("<<<<<<");
90 }
91
92 static void print_row() {
93   stream << std::endl;
94   fprintf(tracing_file, "%s", stream.str().c_str());
95   XBT_DEBUG("Dump %s", stream.str().c_str());
96   stream.str("");
97   stream.clear();
98 }
99
100 static void print_timestamp(simgrid::instr::PajeEvent* event)
101 {
102   stream << " ";
103   /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
104   if (event->timestamp_ < 1e-12)
105     stream << 0;
106   else
107     stream << event->timestamp_;
108 }
109
110 /* internal do the instrumentation module */
111 void simgrid::instr::PajeEvent::insertIntoBuffer()
112 {
113   if (not TRACE_buffer()) {
114     print();
115     delete this;
116     return;
117   }
118   buffer_debug(&buffer);
119
120   XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)", __FUNCTION__, static_cast<int>(eventType_),
121             timestamp_, buffer.size());
122   std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
123   for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
124     simgrid::instr::PajeEvent* e1 = *i;
125     XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1, static_cast<int>(e1->eventType_), e1->timestamp_);
126     if (e1->timestamp_ <= timestamp_)
127       break;
128   }
129   if (i == buffer.rend())
130     XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
131   else if (i == buffer.rbegin())
132     XBT_DEBUG("%s: inserted at end", __FUNCTION__);
133   else
134     XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__, std::distance(buffer.rbegin(), i));
135   buffer.insert(i.base(), this);
136
137   buffer_debug(&buffer);
138 }
139
140 simgrid::instr::PajeEvent::~PajeEvent()
141 {
142   XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__, this, (int)eventType_, timestamp_);
143 }
144
145 void TRACE_paje_start() {
146   char *filename = TRACE_get_filename();
147   tracing_file = fopen(filename, "w");
148   if (tracing_file == nullptr){
149     THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
150   }
151
152   XBT_DEBUG("Filename %s is open for writing", filename);
153
154   /* output generator version */
155   fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
156            SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
157   fprintf (tracing_file, "#[");
158   unsigned int cpt;
159   char *str;
160   xbt_dynar_foreach (xbt_cmdline, cpt, str){
161     fprintf(tracing_file, "%s ",str);
162   }
163   fprintf (tracing_file, "]\n");
164
165   /* output one line comment */
166   dump_comment (TRACE_get_comment());
167
168   /* output comment file */
169   dump_comment_file (TRACE_get_comment_file());
170
171   /* output header */
172   TRACE_header(TRACE_basic(),TRACE_display_sizes());
173 }
174
175 void TRACE_paje_end() {
176   fclose(tracing_file);
177   char *filename = TRACE_get_filename();
178   XBT_DEBUG("Filename %s is closed", filename);
179 }
180
181 void simgrid::instr::Type::logContainerTypeDefinition()
182 {
183   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineContainerType);
184   //print it
185   if (instr_fmt_type == instr_fmt_paje) {
186     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineContainerType,
187               TRACE_precision(), 0.);
188     stream << std::fixed << std::setprecision(TRACE_precision());
189     stream << simgrid::instr::PAJE_DefineContainerType;
190     stream << " " << id_ << " " << father_->getId() << " " << name_;
191     print_row();
192   } else if (instr_fmt_type == instr_fmt_TI) {
193     /* Nothing to do */
194   } else {
195     THROW_IMPOSSIBLE;
196   }
197 }
198
199 void simgrid::instr::Type::logVariableTypeDefinition()
200 {
201   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineVariableType);
202
203   //print it
204   if (instr_fmt_type == instr_fmt_paje) {
205     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineVariableType,
206               TRACE_precision(), 0.);
207     stream << std::fixed << std::setprecision(TRACE_precision());
208     stream << simgrid::instr::PAJE_DefineVariableType;
209     stream << " " << id_ << " " << father_->getId() << " " << name_;
210     if (isColored())
211       stream << " \"" << color_ << "\"";
212     print_row();
213   } else if (instr_fmt_type == instr_fmt_TI) {
214     /* Nothing to do */
215   } else {
216     THROW_IMPOSSIBLE;
217   }
218 }
219
220 void simgrid::instr::Type::logStateTypeDefinition()
221 {
222   //print it
223   if (instr_fmt_type == instr_fmt_paje) {
224     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineStateType,
225               TRACE_precision(), 0.);
226     stream << std::fixed << std::setprecision(TRACE_precision());
227     stream << simgrid::instr::PAJE_DefineStateType;
228     stream << " " << id_ << " " << father_->getId() << " " << name_;
229     print_row();
230   } else if (instr_fmt_type == instr_fmt_TI) {
231     /* Nothing to do */
232   } else {
233     THROW_IMPOSSIBLE;
234   }
235 }
236
237 void simgrid::instr::Type::logDefineEventType()
238 {
239   //print it
240   if (instr_fmt_type == instr_fmt_paje) {
241     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineEventType,
242               TRACE_precision(), 0.);
243     stream << std::fixed << std::setprecision(TRACE_precision());
244     stream << simgrid::instr::PAJE_DefineEventType;
245     stream << " " << id_ << " " << father_->getId() << " " << name_;
246     print_row();
247   } else if (instr_fmt_type == instr_fmt_TI) {
248     /* Nothing to do */
249   } else {
250     THROW_IMPOSSIBLE;
251   }
252 }
253
254 void simgrid::instr::Type::logLinkTypeDefinition(simgrid::instr::Type* source, simgrid::instr::Type* dest)
255 {
256   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineLinkType);
257   //print it
258   if (instr_fmt_type == instr_fmt_paje) {
259     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineLinkType, TRACE_precision(),
260               0.);
261     stream << std::fixed << std::setprecision(TRACE_precision());
262     stream << simgrid::instr::PAJE_DefineLinkType;
263     stream << " " << id_ << " " << father_->getId() << " " << source->getId() << " " << dest->getId() << " " << name_;
264     print_row();
265   } else if (instr_fmt_type == instr_fmt_TI) {
266     /* Nothing to do */
267   } else {
268     THROW_IMPOSSIBLE;
269   }
270 }
271
272 void simgrid::instr::Value::print()
273 {
274   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineEntityValue);
275   //print it
276   if (instr_fmt_type == instr_fmt_paje) {
277     stream << std::fixed << std::setprecision(TRACE_precision());
278     stream << simgrid::instr::PAJE_DefineEntityValue;
279     stream << " " << id_ << " " << father_->getId() << " " << name_;
280     if (isColored())
281       stream << " \"" << color_ << "\"";
282     print_row();
283   } else if (instr_fmt_type == instr_fmt_TI) {
284     /* Nothing to do */
285   } else {
286     THROW_IMPOSSIBLE;
287   }
288 }
289
290 simgrid::instr::SetVariableEvent::SetVariableEvent(double timestamp, container_t container, Type* type, double value)
291     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SetVariable), value(value)
292 {
293   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
294   insertIntoBuffer();
295 }
296
297 void simgrid::instr::SetVariableEvent::print()
298 {
299   if (instr_fmt_type == instr_fmt_paje) {
300     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
301     stream << std::fixed << std::setprecision(TRACE_precision());
302     stream << (int)this->eventType_;
303     print_timestamp(this);
304     stream << " " << type->getId() << " " << container->id_ << " " << value;
305     print_row();
306   } else if (instr_fmt_type == instr_fmt_TI) {
307     /* Nothing to do */
308   } else {
309     THROW_IMPOSSIBLE;
310   }
311 }
312
313 simgrid::instr::AddVariableEvent::AddVariableEvent(double timestamp, container_t container, simgrid::instr::Type* type,
314                                                    double value)
315     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_AddVariable), value(value)
316 {
317   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
318   insertIntoBuffer();
319 }
320
321 void simgrid::instr::AddVariableEvent::print()
322 {
323   if (instr_fmt_type == instr_fmt_paje) {
324     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
325     stream << std::fixed << std::setprecision(TRACE_precision());
326     stream << (int)this->eventType_;
327     print_timestamp(this);
328     stream << " " << type->getId() << " " << container->id_ << " " << value;
329     print_row();
330   } else if (instr_fmt_type == instr_fmt_TI) {
331     /* Nothing to do */
332   } else {
333     THROW_IMPOSSIBLE;
334   }
335 }
336
337 simgrid::instr::SubVariableEvent::SubVariableEvent(double timestamp, container_t container, Type* type, double value)
338     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SubVariable), value(value)
339 {
340   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
341   insertIntoBuffer();
342 }
343
344 void simgrid::instr::SubVariableEvent::print()
345 {
346   if (instr_fmt_type == instr_fmt_paje) {
347     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
348     stream << std::fixed << std::setprecision(TRACE_precision());
349     stream << (int)this->eventType_;
350     print_timestamp(this);
351     stream << " " << type->getId() << " " << container->id_ << " " << value;
352     print_row();
353   } else if (instr_fmt_type == instr_fmt_TI) {
354     /* Nothing to do */
355   } else {
356     THROW_IMPOSSIBLE;
357   }
358 }
359
360 simgrid::instr::SetStateEvent::SetStateEvent(double timestamp, container_t container, Type* type, Value* value)
361     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_SetState), value(value)
362 {
363 #if HAVE_SMPI
364   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
365     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
366     filename   = loc->filename;
367     linenumber = loc->linenumber;
368   }
369 #endif
370
371   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
372   insertIntoBuffer();
373 }
374
375 void simgrid::instr::SetStateEvent::print()
376 {
377   if (instr_fmt_type == instr_fmt_paje) {
378     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
379     stream << std::fixed << std::setprecision(TRACE_precision());
380     stream << (int)this->eventType_;
381     print_timestamp(this);
382     stream << " " << type->getId() << " " << container->id_;
383     stream << " " << value->getId();
384 #if HAVE_SMPI
385     if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
386       stream << " \"" << filename << "\" " << linenumber;
387     }
388 #endif
389     print_row();
390   } else if (instr_fmt_type == instr_fmt_TI) {
391     /* Nothing to do */
392   } else {
393     THROW_IMPOSSIBLE;
394   }
395 }
396
397 simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* value,
398                                                void* extra)
399     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_PushState), value(value), extra_(extra)
400 {
401 #if HAVE_SMPI
402   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
403     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
404     filename   = loc->filename;
405     linenumber = loc->linenumber;
406   }
407 #endif
408
409   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
410
411   insertIntoBuffer();
412 }
413
414 simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* val)
415     : PushStateEvent(timestamp, container, type, val, nullptr)
416 {}
417
418 void simgrid::instr::PushStateEvent::print()
419 {
420   if (instr_fmt_type == instr_fmt_paje) {
421     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
422     stream << std::fixed << std::setprecision(TRACE_precision());
423     stream << (int)this->eventType_;
424     print_timestamp(this);
425     stream << " " << type->getId() << " " << container->id_;
426     stream << " " << value->getId();
427
428     if (TRACE_display_sizes()) {
429       stream << " ";
430       if (extra_ != nullptr) {
431         stream << static_cast<instr_extra_data>(extra_)->send_size;
432       } else {
433         stream << 0;
434       }
435     }
436 #if HAVE_SMPI
437     if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
438       stream << " \"" << filename << "\" " << linenumber;
439     }
440 #endif
441     print_row();
442
443     if (extra_ != nullptr) {
444       if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
445         xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
446       if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
447         xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
448       xbt_free(extra_);
449     }
450   } else if (instr_fmt_type == instr_fmt_TI) {
451     if (extra_ == nullptr)
452       return;
453     instr_extra_data extra = (instr_extra_data)extra_;
454
455     char* process_id = nullptr;
456     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
457     if (strstr(container->name_.c_str(), "rank-") == nullptr)
458       process_id = xbt_strdup(container->name_.c_str());
459     else
460       process_id = xbt_strdup(container->name_.c_str() + 5);
461
462     FILE* trace_file = tracing_files.at(container);
463
464     switch (extra->type) {
465       case TRACING_INIT:
466         fprintf(trace_file, "%s init\n", process_id);
467         break;
468       case TRACING_FINALIZE:
469         fprintf(trace_file, "%s finalize\n", process_id);
470         break;
471       case TRACING_SEND:
472         fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
473         break;
474       case TRACING_ISEND:
475         fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
476         break;
477       case TRACING_RECV:
478         fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
479         break;
480       case TRACING_IRECV:
481         fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
482         break;
483       case TRACING_TEST:
484         fprintf(trace_file, "%s test\n", process_id);
485         break;
486       case TRACING_WAIT:
487         fprintf(trace_file, "%s wait\n", process_id);
488         break;
489       case TRACING_WAITALL:
490         fprintf(trace_file, "%s waitAll\n", process_id);
491         break;
492       case TRACING_BARRIER:
493         fprintf(trace_file, "%s barrier\n", process_id);
494         break;
495       case TRACING_BCAST: // rank bcast size (root) (datatype)
496         fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
497         if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
498           fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
499         fprintf(trace_file, "\n");
500         break;
501       case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
502         fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
503         if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
504           fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
505         fprintf(trace_file, "\n");
506         break;
507       case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
508         fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
509                 extra->datatype1);
510         break;
511       case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
512         fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
513                 extra->datatype1, extra->datatype2);
514         break;
515       case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
516         fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
517         for (int i = 0; i < extra->num_processes; i++)
518           fprintf(trace_file, "%d ", extra->sendcounts[i]);
519         fprintf(trace_file, "%d ", extra->recv_size);
520         for (int i = 0; i < extra->num_processes; i++)
521           fprintf(trace_file, "%d ", extra->recvcounts[i]);
522         fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
523         break;
524       case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
525         fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
526                 extra->datatype1, extra->datatype2);
527         break;
528       case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
529         fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
530         for (int i = 0; i < extra->num_processes; i++)
531           fprintf(trace_file, "%d ", extra->recvcounts[i]);
532         fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
533         break;
534       case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
535         fprintf(trace_file, "%s reduceScatter ", process_id);
536         for (int i = 0; i < extra->num_processes; i++)
537           fprintf(trace_file, "%d ", extra->recvcounts[i]);
538         fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
539         break;
540       case TRACING_COMPUTING:
541         fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
542         break;
543       case TRACING_SLEEPING:
544         fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
545         break;
546       case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
547         fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
548         for (int i = 0; i < extra->num_processes; i++)
549           fprintf(trace_file, "%d ", extra->recvcounts[i]);
550         fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
551         break;
552       case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
553         fprintf(trace_file, "%s allGather %d %d %s %s", process_id, extra->send_size, extra->recv_size,
554                 extra->datatype1, extra->datatype2);
555         break;
556       case TRACING_WAITANY:
557       case TRACING_SENDRECV:
558       case TRACING_SCATTER:
559       case TRACING_SCATTERV:
560       case TRACING_SCAN:
561       case TRACING_EXSCAN:
562       case TRACING_COMM_SIZE:
563       case TRACING_COMM_SPLIT:
564       case TRACING_COMM_DUP:
565       case TRACING_SSEND:
566       case TRACING_ISSEND:
567       default:
568         XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->getCname());
569         break;
570     }
571
572     if (extra->recvcounts != nullptr)
573       xbt_free(extra->recvcounts);
574     if (extra->sendcounts != nullptr)
575       xbt_free(extra->sendcounts);
576     xbt_free(process_id);
577     xbt_free(extra);
578
579   } else {
580     THROW_IMPOSSIBLE;
581   }
582 }
583
584 simgrid::instr::PopStateEvent::PopStateEvent(double timestamp, container_t container, Type* type)
585     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_PopState)
586 {
587   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
588   insertIntoBuffer();
589 }
590
591 void simgrid::instr::PopStateEvent::print()
592 {
593   if (instr_fmt_type == instr_fmt_paje) {
594     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
595     stream << std::fixed << std::setprecision(TRACE_precision());
596     stream << (int)this->eventType_;
597     print_timestamp(this);
598     stream << " " << type->getId() << " " << container->id_;
599     print_row();
600   } else if (instr_fmt_type == instr_fmt_TI) {
601     /* Nothing to do */
602   } else {
603     THROW_IMPOSSIBLE;
604   }
605 }
606
607 simgrid::instr::ResetStateEvent::ResetStateEvent(double timestamp, container_t container, Type* type)
608     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_ResetState)
609 {
610   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
611   insertIntoBuffer();
612   delete[] this;
613 }
614
615 void simgrid::instr::ResetStateEvent::print()
616 {
617   if (instr_fmt_type == instr_fmt_paje) {
618     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
619     stream << std::fixed << std::setprecision(TRACE_precision());
620     stream << (int)this->eventType_;
621     print_timestamp(this);
622     stream << " " << type->getId() << " " << container->id_;
623     print_row();
624   } else if (instr_fmt_type == instr_fmt_TI) {
625     /* Nothing to do */
626   } else {
627     THROW_IMPOSSIBLE;
628   }
629 }
630
631 simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type,
632                                                container_t sourceContainer, std::string value, std::string key)
633     : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
634 {}
635
636 simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type,
637                                                container_t sourceContainer, std::string value, std::string key,
638                                                int size)
639     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_StartLink)
640     , sourceContainer_(sourceContainer)
641     , value_(value)
642     , key_(key)
643     , size_(size)
644 {
645   XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__, (int)eventType_, this->timestamp_, this->value_.c_str());
646   insertIntoBuffer();
647 }
648
649 void simgrid::instr::StartLinkEvent::print()
650 {
651   if (instr_fmt_type == instr_fmt_paje) {
652     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
653     stream << std::fixed << std::setprecision(TRACE_precision());
654     stream << (int)this->eventType_;
655     print_timestamp(this);
656     stream << " " << type->getId() << " " << container->id_ << " " << value_;
657     stream << " " << sourceContainer_->id_ << " " << key_;
658
659     if (TRACE_display_sizes()) {
660       stream << " " << size_;
661     }
662     print_row();
663   } else if (instr_fmt_type == instr_fmt_TI) {
664     /* Nothing to do */
665   } else {
666     THROW_IMPOSSIBLE;
667   }
668 }
669
670 simgrid::instr::EndLinkEvent::EndLinkEvent(double timestamp, container_t container, Type* type,
671                                            container_t destContainer, std::string value, std::string key)
672     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_EndLink)
673     , destContainer(destContainer)
674     , value(value)
675     , key(key)
676 {
677   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
678   insertIntoBuffer();
679 }
680
681 void simgrid::instr::EndLinkEvent::print()
682 {
683   if (instr_fmt_type == instr_fmt_paje) {
684     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
685     stream << std::fixed << std::setprecision(TRACE_precision());
686     stream << (int)this->eventType_;
687     print_timestamp(this);
688     stream << " " << type->getId() << " " << container->id_ << " " << value;
689     stream << " " << destContainer->id_ << " " << key;
690     print_row();
691   } else if (instr_fmt_type == instr_fmt_TI) {
692     /* Nothing to do */
693   } else {
694     THROW_IMPOSSIBLE;
695   }
696 }
697
698 simgrid::instr::NewEvent::NewEvent(double timestamp, container_t container, Type* type, Value* val)
699     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent)
700 {
701   this->val                             = val;
702
703   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
704
705   insertIntoBuffer();
706 }
707
708 void simgrid::instr::NewEvent::print()
709 {
710   if (instr_fmt_type == instr_fmt_paje) {
711     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
712     stream << std::fixed << std::setprecision(TRACE_precision());
713     stream << (int)this->eventType_;
714     print_timestamp(this);
715     stream << " " << type->getId() << " " << container->id_ << " " << val->getId();
716     print_row();
717   } else if (instr_fmt_type == instr_fmt_TI) {
718     /* Nothing to do */
719   } else {
720     THROW_IMPOSSIBLE;
721   }
722 }
723
724 void TRACE_TI_start()
725 {
726   char *filename = TRACE_get_filename();
727   tracing_file = fopen(filename, "w");
728   if (tracing_file == nullptr)
729     THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
730
731   XBT_DEBUG("Filename %s is open for writing", filename);
732
733   /* output one line comment */
734   dump_comment(TRACE_get_comment());
735
736   /* output comment file */
737   dump_comment_file(TRACE_get_comment_file());
738 }
739
740 void TRACE_TI_end()
741 {
742   fclose(tracing_file);
743   char *filename = TRACE_get_filename();
744   XBT_DEBUG("Filename %s is closed", filename);
745 }