1 /* Copyright (c) 2010-2016. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "src/instr/instr_private.h"
8 #include "src/instr/instr_smpi.h"
9 #include "src/smpi/private.hpp"
11 #include "xbt/virtu.h" /* sg_cmdline */
12 #include "simgrid/sg_config.h"
16 #include <iomanip> /** std::setprecision **/
19 #include <direct.h> // _mkdir
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
24 extern s_instr_trace_writer_t active_writer;
26 static std::stringstream stream;
27 FILE *tracing_file = nullptr;
29 static xbt_dict_t tracing_files = nullptr; // TI specific
30 static double prefix=0.0; // TI specific
33 void print_NULL(PajeEvent* event){}
35 /* The active set of functions for the selected trace format
36 * By default, they all do nothing, hence the print_NULL to avoid segfaults */
38 s_instr_trace_writer_t active_writer = {&print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL,
39 &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL,
40 &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL};
42 std::vector<PajeEvent*> buffer;
43 void buffer_debug(std::vector<PajeEvent*> *buf);
45 void dump_comment (const char *comment)
47 if (not strlen(comment))
49 fprintf (tracing_file, "# %s\n", comment);
52 void dump_comment_file (const char *filename)
54 if (not strlen(filename))
56 FILE *file = fopen (filename, "r");
58 THROWF (system_error, 1, "Comment file %s could not be opened for reading.", filename);
60 while (not feof(file)) {
63 if (feof(file)) break;
64 fprintf (tracing_file, "# ");
66 fprintf (tracing_file, "%c", c);
68 if (feof(file)) break;
70 fprintf (tracing_file, "\n");
75 double TRACE_last_timestamp_to_dump = 0;
76 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
77 void TRACE_paje_dump_buffer (int force)
79 if (not TRACE_is_enabled())
81 XBT_DEBUG("%s: dump until %f. starts", __FUNCTION__, TRACE_last_timestamp_to_dump);
83 for (auto event : buffer){
89 std::vector<PajeEvent*>::iterator i = buffer.begin();
90 for (auto event :buffer){
91 double head_timestamp = event->timestamp;
92 if (head_timestamp > TRACE_last_timestamp_to_dump)
98 buffer.erase(buffer.begin(), i);
100 XBT_DEBUG("%s: ends", __FUNCTION__);
103 void buffer_debug(std::vector<PajeEvent*> *buf);
104 void buffer_debug(std::vector<PajeEvent*> *buf) {
106 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
107 for (auto event :*buf){
109 XBT_DEBUG("%p %s", event, stream.str().c_str());
116 static void print_row() {
118 fprintf(tracing_file, "%s", stream.str().c_str());
119 XBT_DEBUG("Dump %s", stream.str().c_str());
124 static void print_timestamp(PajeEvent* event) {
126 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
127 if (event->timestamp < 1e-12)
130 stream << event->timestamp;
133 /* internal do the instrumentation module */
134 static void insert_into_buffer (PajeEvent* tbi)
136 if (TRACE_buffer() == 0){
141 buffer_debug(&buffer);
143 XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)",
144 __FUNCTION__, (int)tbi->event_type, tbi->timestamp, buffer.size());
145 std::vector<PajeEvent*>::reverse_iterator i;
146 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
148 XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1,
149 (int)e1->event_type, e1->timestamp);
150 if (e1->timestamp <= tbi->timestamp)
153 buffer.insert(i.base(), tbi);
154 if (i == buffer.rend())
155 XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
156 else if (i == buffer.rbegin())
157 XBT_DEBUG("%s: inserted at end", __FUNCTION__);
159 XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
160 std::distance(buffer.rbegin(),i));
162 buffer_debug(&buffer);
165 PajeEvent:: ~PajeEvent()
167 XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__,
168 this, (int)event_type, timestamp);
169 // xbt_backtrace_display_current();
171 /* switch (event->event_type){
173 xbt_free (((startLink_t)(event->data))->value);
174 xbt_free (((startLink_t)(event->data))->key);
177 xbt_free (((endLink_t)(event->data))->value);
178 xbt_free (((endLink_t)(event->data))->key);
185 void TRACE_paje_start() {
186 char *filename = TRACE_get_filename();
187 tracing_file = fopen(filename, "w");
188 if (tracing_file == nullptr){
189 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
192 XBT_DEBUG("Filename %s is open for writing", filename);
194 /* output generator version */
195 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
196 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
197 fprintf (tracing_file, "#[");
200 xbt_dynar_foreach (xbt_cmdline, cpt, str){
201 fprintf(tracing_file, "%s ",str);
203 fprintf (tracing_file, "]\n");
205 /* output one line comment */
206 dump_comment (TRACE_get_comment());
208 /* output comment file */
209 dump_comment_file (TRACE_get_comment_file());
212 TRACE_header(TRACE_basic(),TRACE_display_sizes());
215 void TRACE_paje_end() {
216 fclose(tracing_file);
217 char *filename = TRACE_get_filename();
218 XBT_DEBUG("Filename %s is closed", filename);
221 DefineContainerEvent::DefineContainerEvent(type_t type)
224 event_type = PAJE_DefineContainerType;
227 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
232 void DefineContainerEvent::print() {
233 if (instr_fmt_type == instr_fmt_paje) {
234 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
235 stream << std::fixed << std::setprecision(TRACE_precision());
236 stream << (int)this->event_type;
237 stream << " " << type->id << " " << type->father->id << " " << type->name;
239 } else if (instr_fmt_type == instr_fmt_TI) {
248 DefineVariableTypeEvent::DefineVariableTypeEvent(type_t type)
250 this->event_type = PAJE_DefineVariableType;
254 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
260 void DefineVariableTypeEvent::print() {
261 if (instr_fmt_type == instr_fmt_paje) {
262 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
263 stream << std::fixed << std::setprecision(TRACE_precision());
264 stream << (int)this->event_type;
265 stream << " " << type->id << " " << type->father->id << " " << type->name;
267 stream << " \"" << type->color << "\"";
269 } else if (instr_fmt_type == instr_fmt_TI) {
276 DefineStateTypeEvent::DefineStateTypeEvent(type_t type)
278 this->event_type = PAJE_DefineStateType;
282 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
289 DefineEventTypeEvent::DefineEventTypeEvent(type_t type)
291 this->event_type = PAJE_DefineEventType;
295 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
302 void DefineStateTypeEvent::print() {
303 if (instr_fmt_type == instr_fmt_paje) {
304 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
305 stream << std::fixed << std::setprecision(TRACE_precision());
306 stream << (int)this->event_type;
307 stream << " " << type->id << " " << type->father->id << " " << type->name;
309 } else if (instr_fmt_type == instr_fmt_TI) {
316 void DefineEventTypeEvent::print() {
317 if (instr_fmt_type == instr_fmt_paje) {
318 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
319 stream << std::fixed << std::setprecision(TRACE_precision());
320 stream << (int)this->event_type;
321 stream << " " << type->id << " " << type->father->id << " " << type->name;
323 } else if (instr_fmt_type == instr_fmt_TI) {
330 DefineLinkTypeEvent::DefineLinkTypeEvent(type_t type, type_t source, type_t dest)
332 this->event_type = PAJE_DefineLinkType;
335 this->source = source;
338 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
344 void DefineLinkTypeEvent::print() {
345 if (instr_fmt_type == instr_fmt_paje) {
346 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
347 stream << std::fixed << std::setprecision(TRACE_precision());
348 stream << (int)this->event_type;
349 stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
351 } else if (instr_fmt_type == instr_fmt_TI) {
358 DefineEntityValueEvent::DefineEntityValueEvent (val_t value)
360 this->event_type = PAJE_DefineEntityValue;
364 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
371 void DefineEntityValueEvent::print() {
372 if (instr_fmt_type == instr_fmt_paje) {
373 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
374 stream << std::fixed << std::setprecision(TRACE_precision());
375 stream << (int)this->event_type;
376 stream << " " << value->id << " " << value->father->id << " " << value->name;
378 stream << " \"" << value->color << "\"";
380 } else if (instr_fmt_type == instr_fmt_TI) {
387 CreateContainerEvent::CreateContainerEvent (container_t container)
389 this->event_type = PAJE_CreateContainer;
390 this->timestamp = SIMIX_get_clock();
391 this->container = container;
393 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
398 void CreateContainerEvent::print() {
399 if (instr_fmt_type == instr_fmt_paje) {
400 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
401 stream << std::fixed << std::setprecision(TRACE_precision());
402 stream << (int)this->event_type;
403 print_timestamp(this);
404 stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
405 << container->name << "\"";
408 } else if (instr_fmt_type == instr_fmt_TI) {
409 // if we are in the mode with only one file
410 static FILE* ti_unique_file = nullptr;
412 if (tracing_files == nullptr) {
413 tracing_files = xbt_dict_new_homogeneous(nullptr);
414 // generate unique run id with time
415 prefix = xbt_os_time();
418 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
419 char* folder_name = bprintf("%s_files", TRACE_get_filename());
420 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
424 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
426 ti_unique_file = fopen(filename, "w");
427 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
428 fprintf(tracing_file, "%s\n", filename);
430 xbt_free(folder_name);
434 xbt_dict_set(tracing_files, container->name, (void*)ti_unique_file, nullptr);
440 DestroyContainerEvent::DestroyContainerEvent (container_t container)
442 this->event_type = PAJE_DestroyContainer;
443 this->timestamp = SIMIX_get_clock();
444 this->container = container;
446 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
451 void DestroyContainerEvent::print() {
452 if (instr_fmt_type == instr_fmt_paje) {
453 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
454 stream << std::fixed << std::setprecision(TRACE_precision());
455 stream << (int)this->event_type;
456 print_timestamp(this);
457 stream << " " << container->type->id << " " << container->id;
460 } else if (instr_fmt_type == instr_fmt_TI) {
461 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
462 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
465 xbt_dict_remove(tracing_files, container->name);
471 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
473 this->event_type = PAJE_SetVariable;
474 this->timestamp = timestamp;
476 this->container = container;
479 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
481 insert_into_buffer (this);
484 void SetVariableEvent::print() {
485 if (instr_fmt_type == instr_fmt_paje) {
486 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
487 stream << std::fixed << std::setprecision(TRACE_precision());
488 stream << (int)this->event_type;
489 print_timestamp(this);
490 stream << " " << type->id << " " << container->id << " " << value;
492 } else if (instr_fmt_type == instr_fmt_TI) {
499 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, type_t type, double value)
501 this->event_type = PAJE_AddVariable;
502 this->timestamp = timestamp;
504 this->container = container;
507 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
509 insert_into_buffer (this);
512 void AddVariableEvent::print() {
513 if (instr_fmt_type == instr_fmt_paje) {
514 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
515 stream << std::fixed << std::setprecision(TRACE_precision());
516 stream << (int)this->event_type;
517 print_timestamp(this);
518 stream << " " << type->id << " " << container->id << " " << value;
520 } else if (instr_fmt_type == instr_fmt_TI) {
527 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, type_t type, double value)
529 this->event_type = PAJE_SubVariable;
530 this->timestamp = timestamp;
532 this->container = container;
535 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
537 insert_into_buffer (this);
540 void SubVariableEvent::print() {
541 if (instr_fmt_type == instr_fmt_paje) {
542 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
543 stream << std::fixed << std::setprecision(TRACE_precision());
544 stream << (int)this->event_type;
545 print_timestamp(this);
546 stream << " " << type->id << " " << container->id << " " << value;
548 } else if (instr_fmt_type == instr_fmt_TI) {
555 SetStateEvent::SetStateEvent (double timestamp, container_t container, type_t type, val_t value)
557 this->event_type = PAJE_SetState;
558 this->timestamp = timestamp;
560 this->container = container;
564 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
565 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
566 filename = loc->filename;
567 linenumber = loc->linenumber;
571 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
573 insert_into_buffer (this);
576 void SetStateEvent::print() {
577 if (instr_fmt_type == instr_fmt_paje) {
578 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
579 stream << std::fixed << std::setprecision(TRACE_precision());
580 stream << (int)this->event_type;
581 print_timestamp(this);
582 stream << " " << type->id << " " << container->id;
583 stream << " " << value->id;
585 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
586 stream << " \"" << filename << "\" " << linenumber;
590 } else if (instr_fmt_type == instr_fmt_TI) {
597 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value, void* extra)
599 this->event_type = PAJE_PushState;
600 this->timestamp = timestamp;
602 this->container = container;
604 this->extra_ = extra;
607 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
608 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
609 filename = loc->filename;
610 linenumber = loc->linenumber;
614 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
616 insert_into_buffer (this);
619 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value)
620 : PushStateEvent(timestamp, container, type, value, nullptr)
622 void PushStateEvent::print() {
623 if (instr_fmt_type == instr_fmt_paje) {
624 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
625 stream << std::fixed << std::setprecision(TRACE_precision());
626 stream << (int)this->event_type;
627 print_timestamp(this);
628 stream << " " << type->id << " " << container->id;
629 stream << " " << value->id;
631 if (TRACE_display_sizes()) {
633 if (extra_ != nullptr) {
634 stream << static_cast<instr_extra_data>(extra_)->send_size;
640 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
641 stream << " \"" << filename << "\" " << linenumber;
646 if (extra_ != nullptr) {
647 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
648 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
649 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
650 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
653 } else if (instr_fmt_type == instr_fmt_TI) {
654 if (extra_ == nullptr)
656 instr_extra_data extra = (instr_extra_data)extra_;
658 char* process_id = nullptr;
659 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
660 if (strstr(container->name, "rank-") == nullptr)
661 process_id = xbt_strdup(container->name);
663 process_id = xbt_strdup(container->name + 5);
665 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name);
667 switch (extra->type) {
669 fprintf(trace_file, "%s init\n", process_id);
671 case TRACING_FINALIZE:
672 fprintf(trace_file, "%s finalize\n", process_id);
675 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
678 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
681 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
684 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
687 fprintf(trace_file, "%s test\n", process_id);
690 fprintf(trace_file, "%s wait\n", process_id);
692 case TRACING_WAITALL:
693 fprintf(trace_file, "%s waitAll\n", process_id);
695 case TRACING_BARRIER:
696 fprintf(trace_file, "%s barrier\n", process_id);
698 case TRACING_BCAST: // rank bcast size (root) (datatype)
699 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
700 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
701 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
702 fprintf(trace_file, "\n");
704 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
705 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
706 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
707 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
708 fprintf(trace_file, "\n");
710 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
711 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
714 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
715 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
716 extra->datatype1, extra->datatype2);
718 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
719 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
720 for (int i = 0; i < extra->num_processes; i++)
721 fprintf(trace_file, "%d ", extra->sendcounts[i]);
722 fprintf(trace_file, "%d ", extra->recv_size);
723 for (int i = 0; i < extra->num_processes; i++)
724 fprintf(trace_file, "%d ", extra->recvcounts[i]);
725 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
727 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
728 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
729 extra->datatype1, extra->datatype2);
731 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
732 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
733 for (int i = 0; i < extra->num_processes; i++)
734 fprintf(trace_file, "%d ", extra->recvcounts[i]);
735 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
737 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
738 fprintf(trace_file, "%s reduceScatter ", process_id);
739 for (int i = 0; i < extra->num_processes; i++)
740 fprintf(trace_file, "%d ", extra->recvcounts[i]);
741 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
743 case TRACING_COMPUTING:
744 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
746 case TRACING_SLEEPING:
747 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
749 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
750 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
751 for (int i = 0; i < extra->num_processes; i++)
752 fprintf(trace_file, "%d ", extra->recvcounts[i]);
753 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
755 case TRACING_WAITANY:
756 case TRACING_SENDRECV:
757 case TRACING_SCATTER:
758 case TRACING_SCATTERV:
759 case TRACING_ALLGATHER:
762 case TRACING_COMM_SIZE:
763 case TRACING_COMM_SPLIT:
764 case TRACING_COMM_DUP:
768 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->name);
772 if (extra->recvcounts != nullptr)
773 xbt_free(extra->recvcounts);
774 if (extra->sendcounts != nullptr)
775 xbt_free(extra->sendcounts);
776 xbt_free(process_id);
785 PopStateEvent::PopStateEvent (double timestamp, container_t container, type_t type)
787 this->event_type = PAJE_PopState;
788 this->timestamp = timestamp;
790 this->container = container;
792 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
794 insert_into_buffer (this);
797 void PopStateEvent::print() {
798 if (instr_fmt_type == instr_fmt_paje) {
799 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
800 stream << std::fixed << std::setprecision(TRACE_precision());
801 stream << (int)this->event_type;
802 print_timestamp(this);
803 stream << " " << type->id << " " << container->id;
805 } else if (instr_fmt_type == instr_fmt_TI) {
812 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_t type)
814 this->event_type = PAJE_ResetState;
815 this->timestamp = timestamp;
817 this->container = container;
819 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
821 insert_into_buffer (this);
824 void ResetStateEvent::print() {
825 if (instr_fmt_type == instr_fmt_paje) {
826 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
827 stream << std::fixed << std::setprecision(TRACE_precision());
828 stream << (int)this->event_type;
829 print_timestamp(this);
830 stream << " " << type->id << " " << container->id;
832 } else if (instr_fmt_type == instr_fmt_TI) {
839 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
840 type_t type, container_t sourceContainer, const char *value, const char *key)
841 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
844 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, type_t type, container_t sourceContainer,
845 const char *value, const char *key, int size)
847 event_type = PAJE_StartLink;
848 this->timestamp = timestamp;
850 this->container = container;
851 this->sourceContainer = sourceContainer;
852 this->value = xbt_strdup(value);
853 this->key = xbt_strdup(key);
856 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
857 (int)event_type, this->timestamp, this->value);
859 insert_into_buffer (this);
862 void StartLinkEvent::print() {
863 if (instr_fmt_type == instr_fmt_paje) {
864 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
865 stream << std::fixed << std::setprecision(TRACE_precision());
866 stream << (int)this->event_type;
867 print_timestamp(this);
868 stream << " " << type->id << " " << container->id << " " << value;
869 stream << " " << sourceContainer->id << " " << key;
871 if (TRACE_display_sizes()) {
872 stream << " " << size;
875 } else if (instr_fmt_type == instr_fmt_TI) {
882 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
883 const char *value, const char *key)
885 this->event_type = PAJE_EndLink;
886 this->timestamp = timestamp;
888 this->container = container;
889 this->destContainer = destContainer;
890 this->value = xbt_strdup(value);
891 this->key = xbt_strdup(key);
893 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
895 insert_into_buffer (this);
899 void EndLinkEvent::print() {
900 if (instr_fmt_type == instr_fmt_paje) {
901 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
902 stream << std::fixed << std::setprecision(TRACE_precision());
903 stream << (int)this->event_type;
904 print_timestamp(this);
905 stream << " " << type->id << " " << container->id << " " << value;
906 stream << " " << destContainer->id << " " << key;
908 } else if (instr_fmt_type == instr_fmt_TI) {
915 NewEvent::NewEvent (double timestamp, container_t container, type_t type, val_t value)
917 this->event_type = PAJE_NewEvent;
918 this->timestamp = timestamp;
920 this->container = container;
923 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
925 insert_into_buffer (this);
928 void NewEvent::print () {
929 if (instr_fmt_type == instr_fmt_paje) {
930 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
931 stream << std::fixed << std::setprecision(TRACE_precision());
932 stream << (int)this->event_type;
933 print_timestamp(this);
934 stream << " " << type->id << " " << container->id << " " << value->id;
936 } else if (instr_fmt_type == instr_fmt_TI) {
944 void TRACE_TI_start()
946 char *filename = TRACE_get_filename();
947 tracing_file = fopen(filename, "w");
948 if (tracing_file == nullptr)
949 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
951 XBT_DEBUG("Filename %s is open for writing", filename);
953 /* output one line comment */
954 dump_comment(TRACE_get_comment());
956 /* output comment file */
957 dump_comment_file(TRACE_get_comment_file());
962 xbt_dict_free(&tracing_files);
963 fclose(tracing_file);
964 char *filename = TRACE_get_filename();
965 XBT_DEBUG("Filename %s is closed", filename);