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 static std::stringstream stream;
25 FILE *tracing_file = nullptr;
27 static xbt_dict_t tracing_files = nullptr; // TI specific
28 static double prefix=0.0; // TI specific
30 std::vector<PajeEvent*> buffer;
31 void buffer_debug(std::vector<PajeEvent*> *buf);
33 void dump_comment (const char *comment)
35 if (not strlen(comment))
37 fprintf (tracing_file, "# %s\n", comment);
40 void dump_comment_file (const char *filename)
42 if (not strlen(filename))
44 FILE *file = fopen (filename, "r");
46 THROWF (system_error, 1, "Comment file %s could not be opened for reading.", filename);
48 while (not feof(file)) {
51 if (feof(file)) break;
52 fprintf (tracing_file, "# ");
54 fprintf (tracing_file, "%c", c);
56 if (feof(file)) break;
58 fprintf (tracing_file, "\n");
63 double TRACE_last_timestamp_to_dump = 0;
64 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
65 void TRACE_paje_dump_buffer (int force)
67 if (not TRACE_is_enabled())
69 XBT_DEBUG("%s: dump until %f. starts", __FUNCTION__, TRACE_last_timestamp_to_dump);
71 for (auto event : buffer){
77 std::vector<PajeEvent*>::iterator i = buffer.begin();
78 for (auto event :buffer){
79 double head_timestamp = event->timestamp;
80 if (head_timestamp > TRACE_last_timestamp_to_dump)
86 buffer.erase(buffer.begin(), i);
88 XBT_DEBUG("%s: ends", __FUNCTION__);
91 void buffer_debug(std::vector<PajeEvent*> *buf);
92 void buffer_debug(std::vector<PajeEvent*> *buf) {
94 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
95 for (auto event :*buf){
97 XBT_DEBUG("%p %s", event, stream.str().c_str());
104 static void print_row() {
106 fprintf(tracing_file, "%s", stream.str().c_str());
107 XBT_DEBUG("Dump %s", stream.str().c_str());
112 static void print_timestamp(PajeEvent* event) {
114 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
115 if (event->timestamp < 1e-12)
118 stream << event->timestamp;
121 /* internal do the instrumentation module */
122 static void insert_into_buffer (PajeEvent* tbi)
124 if (TRACE_buffer() == 0){
129 buffer_debug(&buffer);
131 XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)",
132 __FUNCTION__, (int)tbi->event_type, tbi->timestamp, buffer.size());
133 std::vector<PajeEvent*>::reverse_iterator i;
134 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
136 XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1,
137 (int)e1->event_type, e1->timestamp);
138 if (e1->timestamp <= tbi->timestamp)
141 if (i == buffer.rend())
142 XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
143 else if (i == buffer.rbegin())
144 XBT_DEBUG("%s: inserted at end", __FUNCTION__);
146 XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
147 std::distance(buffer.rbegin(),i));
148 buffer.insert(i.base(), tbi);
150 buffer_debug(&buffer);
153 PajeEvent:: ~PajeEvent()
155 XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__,
156 this, (int)event_type, timestamp);
159 void TRACE_paje_start() {
160 char *filename = TRACE_get_filename();
161 tracing_file = fopen(filename, "w");
162 if (tracing_file == nullptr){
163 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
166 XBT_DEBUG("Filename %s is open for writing", filename);
168 /* output generator version */
169 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
170 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
171 fprintf (tracing_file, "#[");
174 xbt_dynar_foreach (xbt_cmdline, cpt, str){
175 fprintf(tracing_file, "%s ",str);
177 fprintf (tracing_file, "]\n");
179 /* output one line comment */
180 dump_comment (TRACE_get_comment());
182 /* output comment file */
183 dump_comment_file (TRACE_get_comment_file());
186 TRACE_header(TRACE_basic(),TRACE_display_sizes());
189 void TRACE_paje_end() {
190 fclose(tracing_file);
191 char *filename = TRACE_get_filename();
192 XBT_DEBUG("Filename %s is closed", filename);
195 void DefineContainerEvent(type_t type)
197 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineContainerType);
199 if (instr_fmt_type == instr_fmt_paje) {
200 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineContainerType, TRACE_precision(), 0.);
201 stream << std::fixed << std::setprecision(TRACE_precision());
202 stream << PAJE_DefineContainerType;
203 stream << " " << type->id << " " << type->father->id << " " << type->name;
205 } else if (instr_fmt_type == instr_fmt_TI) {
215 void LogVariableTypeDefinition(type_t type)
218 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineVariableType);
221 if (instr_fmt_type == instr_fmt_paje) {
222 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineVariableType, TRACE_precision(), 0.);
223 stream << std::fixed << std::setprecision(TRACE_precision());
224 stream << PAJE_DefineVariableType;
225 stream << " " << type->id << " " << type->father->id << " " << type->name;
227 stream << " \"" << type->color << "\"";
229 } else if (instr_fmt_type == instr_fmt_TI) {
237 void LogStateTypeDefinition(type_t type)
240 if (instr_fmt_type == instr_fmt_paje) {
241 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineStateType, TRACE_precision(), 0.);
242 stream << std::fixed << std::setprecision(TRACE_precision());
243 stream << PAJE_DefineStateType;
244 stream << " " << type->id << " " << type->father->id << " " << type->name;
246 } else if (instr_fmt_type == instr_fmt_TI) {
254 void LogDefineEventType(type_t type)
257 if (instr_fmt_type == instr_fmt_paje) {
258 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineEventType, TRACE_precision(), 0.);
259 stream << std::fixed << std::setprecision(TRACE_precision());
260 stream << PAJE_DefineEventType;
261 stream << " " << type->id << " " << type->father->id << " " << type->name;
263 } else if (instr_fmt_type == instr_fmt_TI) {
270 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest)
272 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineLinkType);
274 if (instr_fmt_type == instr_fmt_paje) {
275 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.);
276 stream << std::fixed << std::setprecision(TRACE_precision());
277 stream << PAJE_DefineLinkType;
278 stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
280 } else if (instr_fmt_type == instr_fmt_TI) {
287 void LogEntityValue (val_t value)
289 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineEntityValue);
291 if (instr_fmt_type == instr_fmt_paje) {
292 stream << std::fixed << std::setprecision(TRACE_precision());
293 stream << PAJE_DefineEntityValue;
294 stream << " " << value->id << " " << value->father->id << " " << value->name;
296 stream << " \"" << value->color << "\"";
298 } else if (instr_fmt_type == instr_fmt_TI) {
306 void LogContainerCreation (container_t container)
308 double timestamp = SIMIX_get_clock();
310 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_CreateContainer,timestamp);
312 if (instr_fmt_type == instr_fmt_paje) {
313 stream << std::fixed << std::setprecision(TRACE_precision());
314 stream << PAJE_CreateContainer;
316 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
317 if (timestamp < 1e-12)
321 stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
322 << container->name << "\"";
325 } else if (instr_fmt_type == instr_fmt_TI) {
326 // if we are in the mode with only one file
327 static FILE* ti_unique_file = nullptr;
329 if (tracing_files == nullptr) {
330 tracing_files = xbt_dict_new_homogeneous(nullptr);
331 // generate unique run id with time
332 prefix = xbt_os_time();
335 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
336 char* folder_name = bprintf("%s_files", TRACE_get_filename());
337 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
341 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
343 ti_unique_file = fopen(filename, "w");
344 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
345 fprintf(tracing_file, "%s\n", filename);
347 xbt_free(folder_name);
351 xbt_dict_set(tracing_files, container->name, (void*)ti_unique_file, nullptr);
357 void LogContainerDestruction(container_t container)
359 double timestamp = SIMIX_get_clock();
361 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_DestroyContainer, timestamp);
363 if (instr_fmt_type == instr_fmt_paje) {
364 stream << std::fixed << std::setprecision(TRACE_precision());
365 stream << PAJE_DestroyContainer;
367 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
368 if (timestamp < 1e-12)
372 stream << " " << container->type->id << " " << container->id;
374 } else if (instr_fmt_type == instr_fmt_TI) {
375 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
376 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
379 xbt_dict_remove(tracing_files, container->name);
386 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
388 this->event_type = PAJE_SetVariable;
389 this->timestamp = timestamp;
391 this->container = container;
394 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
396 insert_into_buffer (this);
399 void SetVariableEvent::print() {
400 if (instr_fmt_type == instr_fmt_paje) {
401 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
402 stream << std::fixed << std::setprecision(TRACE_precision());
403 stream << (int)this->event_type;
404 print_timestamp(this);
405 stream << " " << type->id << " " << container->id << " " << value;
407 } else if (instr_fmt_type == instr_fmt_TI) {
414 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, type_t type, double value)
416 this->event_type = PAJE_AddVariable;
417 this->timestamp = timestamp;
419 this->container = container;
422 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
424 insert_into_buffer (this);
427 void AddVariableEvent::print() {
428 if (instr_fmt_type == instr_fmt_paje) {
429 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
430 stream << std::fixed << std::setprecision(TRACE_precision());
431 stream << (int)this->event_type;
432 print_timestamp(this);
433 stream << " " << type->id << " " << container->id << " " << value;
435 } else if (instr_fmt_type == instr_fmt_TI) {
442 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, type_t type, double value)
444 this->event_type = PAJE_SubVariable;
445 this->timestamp = timestamp;
447 this->container = container;
450 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
452 insert_into_buffer (this);
455 void SubVariableEvent::print() {
456 if (instr_fmt_type == instr_fmt_paje) {
457 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
458 stream << std::fixed << std::setprecision(TRACE_precision());
459 stream << (int)this->event_type;
460 print_timestamp(this);
461 stream << " " << type->id << " " << container->id << " " << value;
463 } else if (instr_fmt_type == instr_fmt_TI) {
470 SetStateEvent::SetStateEvent (double timestamp, container_t container, type_t type, val_t value)
472 this->event_type = PAJE_SetState;
473 this->timestamp = timestamp;
475 this->container = container;
479 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
480 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
481 filename = loc->filename;
482 linenumber = loc->linenumber;
486 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
488 insert_into_buffer (this);
491 void SetStateEvent::print() {
492 if (instr_fmt_type == instr_fmt_paje) {
493 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
494 stream << std::fixed << std::setprecision(TRACE_precision());
495 stream << (int)this->event_type;
496 print_timestamp(this);
497 stream << " " << type->id << " " << container->id;
498 stream << " " << value->id;
500 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
501 stream << " \"" << filename << "\" " << linenumber;
505 } else if (instr_fmt_type == instr_fmt_TI) {
512 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value, void* extra)
514 this->event_type = PAJE_PushState;
515 this->timestamp = timestamp;
517 this->container = container;
519 this->extra_ = extra;
522 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
523 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
524 filename = loc->filename;
525 linenumber = loc->linenumber;
529 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
531 insert_into_buffer (this);
534 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value)
535 : PushStateEvent(timestamp, container, type, value, nullptr)
537 void PushStateEvent::print() {
538 if (instr_fmt_type == instr_fmt_paje) {
539 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
540 stream << std::fixed << std::setprecision(TRACE_precision());
541 stream << (int)this->event_type;
542 print_timestamp(this);
543 stream << " " << type->id << " " << container->id;
544 stream << " " << value->id;
546 if (TRACE_display_sizes()) {
548 if (extra_ != nullptr) {
549 stream << static_cast<instr_extra_data>(extra_)->send_size;
555 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
556 stream << " \"" << filename << "\" " << linenumber;
561 if (extra_ != nullptr) {
562 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
563 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
564 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
565 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
568 } else if (instr_fmt_type == instr_fmt_TI) {
569 if (extra_ == nullptr)
571 instr_extra_data extra = (instr_extra_data)extra_;
573 char* process_id = nullptr;
574 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
575 if (strstr(container->name, "rank-") == nullptr)
576 process_id = xbt_strdup(container->name);
578 process_id = xbt_strdup(container->name + 5);
580 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name);
582 switch (extra->type) {
584 fprintf(trace_file, "%s init\n", process_id);
586 case TRACING_FINALIZE:
587 fprintf(trace_file, "%s finalize\n", process_id);
590 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
593 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
596 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
599 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
602 fprintf(trace_file, "%s test\n", process_id);
605 fprintf(trace_file, "%s wait\n", process_id);
607 case TRACING_WAITALL:
608 fprintf(trace_file, "%s waitAll\n", process_id);
610 case TRACING_BARRIER:
611 fprintf(trace_file, "%s barrier\n", process_id);
613 case TRACING_BCAST: // rank bcast size (root) (datatype)
614 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
615 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
616 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
617 fprintf(trace_file, "\n");
619 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
620 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
621 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
622 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
623 fprintf(trace_file, "\n");
625 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
626 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
629 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
630 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
631 extra->datatype1, extra->datatype2);
633 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
634 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
635 for (int i = 0; i < extra->num_processes; i++)
636 fprintf(trace_file, "%d ", extra->sendcounts[i]);
637 fprintf(trace_file, "%d ", extra->recv_size);
638 for (int i = 0; i < extra->num_processes; i++)
639 fprintf(trace_file, "%d ", extra->recvcounts[i]);
640 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
642 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
643 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
644 extra->datatype1, extra->datatype2);
646 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
647 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
648 for (int i = 0; i < extra->num_processes; i++)
649 fprintf(trace_file, "%d ", extra->recvcounts[i]);
650 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
652 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
653 fprintf(trace_file, "%s reduceScatter ", process_id);
654 for (int i = 0; i < extra->num_processes; i++)
655 fprintf(trace_file, "%d ", extra->recvcounts[i]);
656 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
658 case TRACING_COMPUTING:
659 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
661 case TRACING_SLEEPING:
662 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
664 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
665 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
666 for (int i = 0; i < extra->num_processes; i++)
667 fprintf(trace_file, "%d ", extra->recvcounts[i]);
668 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
670 case TRACING_WAITANY:
671 case TRACING_SENDRECV:
672 case TRACING_SCATTER:
673 case TRACING_SCATTERV:
674 case TRACING_ALLGATHER:
677 case TRACING_COMM_SIZE:
678 case TRACING_COMM_SPLIT:
679 case TRACING_COMM_DUP:
683 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->name);
687 if (extra->recvcounts != nullptr)
688 xbt_free(extra->recvcounts);
689 if (extra->sendcounts != nullptr)
690 xbt_free(extra->sendcounts);
691 xbt_free(process_id);
700 PopStateEvent::PopStateEvent (double timestamp, container_t container, type_t type)
702 this->event_type = PAJE_PopState;
703 this->timestamp = timestamp;
705 this->container = container;
707 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
709 insert_into_buffer (this);
712 void PopStateEvent::print() {
713 if (instr_fmt_type == instr_fmt_paje) {
714 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
715 stream << std::fixed << std::setprecision(TRACE_precision());
716 stream << (int)this->event_type;
717 print_timestamp(this);
718 stream << " " << type->id << " " << container->id;
720 } else if (instr_fmt_type == instr_fmt_TI) {
727 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_t type)
729 this->event_type = PAJE_ResetState;
730 this->timestamp = timestamp;
732 this->container = container;
734 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
736 insert_into_buffer (this);
740 void ResetStateEvent::print() {
741 if (instr_fmt_type == instr_fmt_paje) {
742 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
743 stream << std::fixed << std::setprecision(TRACE_precision());
744 stream << (int)this->event_type;
745 print_timestamp(this);
746 stream << " " << type->id << " " << container->id;
748 } else if (instr_fmt_type == instr_fmt_TI) {
755 StartLinkEvent::~StartLinkEvent()
760 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
761 type_t type, container_t sourceContainer, const char *value, const char *key)
762 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
765 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, type_t type, container_t sourceContainer,
766 const char *value, const char *key, int size)
768 event_type = PAJE_StartLink;
769 this->timestamp = timestamp;
771 this->container = container;
772 this->sourceContainer = sourceContainer;
773 this->value = xbt_strdup(value);
774 this->key = xbt_strdup(key);
777 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
778 (int)event_type, this->timestamp, this->value);
780 insert_into_buffer (this);
783 void StartLinkEvent::print() {
784 if (instr_fmt_type == instr_fmt_paje) {
785 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
786 stream << std::fixed << std::setprecision(TRACE_precision());
787 stream << (int)this->event_type;
788 print_timestamp(this);
789 stream << " " << type->id << " " << container->id << " " << value;
790 stream << " " << sourceContainer->id << " " << key;
792 if (TRACE_display_sizes()) {
793 stream << " " << size;
796 } else if (instr_fmt_type == instr_fmt_TI) {
803 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
804 const char *value, const char *key)
806 this->event_type = PAJE_EndLink;
807 this->timestamp = timestamp;
809 this->container = container;
810 this->destContainer = destContainer;
811 this->value = xbt_strdup(value);
812 this->key = xbt_strdup(key);
814 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
816 insert_into_buffer (this);
819 EndLinkEvent::~EndLinkEvent()
824 void EndLinkEvent::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 << " " << value;
831 stream << " " << destContainer->id << " " << key;
833 } else if (instr_fmt_type == instr_fmt_TI) {
840 NewEvent::NewEvent (double timestamp, container_t container, type_t type, val_t value)
842 this->event_type = PAJE_NewEvent;
843 this->timestamp = timestamp;
845 this->container = container;
848 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
850 insert_into_buffer (this);
853 void NewEvent::print () {
854 if (instr_fmt_type == instr_fmt_paje) {
855 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
856 stream << std::fixed << std::setprecision(TRACE_precision());
857 stream << (int)this->event_type;
858 print_timestamp(this);
859 stream << " " << type->id << " " << container->id << " " << value->id;
861 } else if (instr_fmt_type == instr_fmt_TI) {
869 void TRACE_TI_start()
871 char *filename = TRACE_get_filename();
872 tracing_file = fopen(filename, "w");
873 if (tracing_file == nullptr)
874 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
876 XBT_DEBUG("Filename %s is open for writing", filename);
878 /* output one line comment */
879 dump_comment(TRACE_get_comment());
881 /* output comment file */
882 dump_comment_file(TRACE_get_comment_file());
887 xbt_dict_free(&tracing_files);
888 fclose(tracing_file);
889 char *filename = TRACE_get_filename();
890 XBT_DEBUG("Filename %s is closed", filename);