Logo AND Algorithmique Numérique Distribuée

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