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/include/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);
157 // xbt_backtrace_display_current();
159 /* switch (event->event_type){
161 xbt_free (((startLink_t)(event->data))->value);
162 xbt_free (((startLink_t)(event->data))->key);
165 xbt_free (((endLink_t)(event->data))->value);
166 xbt_free (((endLink_t)(event->data))->key);
173 void TRACE_paje_start() {
174 char *filename = TRACE_get_filename();
175 tracing_file = fopen(filename, "w");
176 if (tracing_file == nullptr){
177 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
180 XBT_DEBUG("Filename %s is open for writing", filename);
182 /* output generator version */
183 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
184 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
185 fprintf (tracing_file, "#[");
188 xbt_dynar_foreach (xbt_cmdline, cpt, str){
189 fprintf(tracing_file, "%s ",str);
191 fprintf (tracing_file, "]\n");
193 /* output one line comment */
194 dump_comment (TRACE_get_comment());
196 /* output comment file */
197 dump_comment_file (TRACE_get_comment_file());
200 TRACE_header(TRACE_basic(),TRACE_display_sizes());
203 void TRACE_paje_end() {
204 fclose(tracing_file);
205 char *filename = TRACE_get_filename();
206 XBT_DEBUG("Filename %s is closed", filename);
209 void DefineContainerEvent(type_t type)
211 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineContainerType);
213 if (instr_fmt_type == instr_fmt_paje) {
214 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineContainerType, TRACE_precision(), 0.);
215 stream << std::fixed << std::setprecision(TRACE_precision());
216 stream << PAJE_DefineContainerType;
217 stream << " " << type->id << " " << type->father->id << " " << type->name;
219 } else if (instr_fmt_type == instr_fmt_TI) {
229 void LogVariableTypeDefinition(type_t type)
232 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineVariableType);
235 if (instr_fmt_type == instr_fmt_paje) {
236 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineVariableType, TRACE_precision(), 0.);
237 stream << std::fixed << std::setprecision(TRACE_precision());
238 stream << PAJE_DefineVariableType;
239 stream << " " << type->id << " " << type->father->id << " " << type->name;
241 stream << " \"" << type->color << "\"";
243 } else if (instr_fmt_type == instr_fmt_TI) {
251 void LogStateTypeDefinition(type_t type)
254 if (instr_fmt_type == instr_fmt_paje) {
255 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineStateType, TRACE_precision(), 0.);
256 stream << std::fixed << std::setprecision(TRACE_precision());
257 stream << PAJE_DefineStateType;
258 stream << " " << type->id << " " << type->father->id << " " << type->name;
260 } else if (instr_fmt_type == instr_fmt_TI) {
268 void LogDefineEventType(type_t type)
271 if (instr_fmt_type == instr_fmt_paje) {
272 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineEventType, TRACE_precision(), 0.);
273 stream << std::fixed << std::setprecision(TRACE_precision());
274 stream << PAJE_DefineEventType;
275 stream << " " << type->id << " " << type->father->id << " " << type->name;
277 } else if (instr_fmt_type == instr_fmt_TI) {
284 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest)
286 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineLinkType);
288 if (instr_fmt_type == instr_fmt_paje) {
289 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.);
290 stream << std::fixed << std::setprecision(TRACE_precision());
291 stream << PAJE_DefineLinkType;
292 stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
294 } else if (instr_fmt_type == instr_fmt_TI) {
301 void LogEntityValue (val_t value)
303 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineEntityValue);
305 if (instr_fmt_type == instr_fmt_paje) {
306 stream << std::fixed << std::setprecision(TRACE_precision());
307 stream << PAJE_DefineEntityValue;
308 stream << " " << value->id << " " << value->father->id << " " << value->name;
310 stream << " \"" << value->color << "\"";
312 } else if (instr_fmt_type == instr_fmt_TI) {
320 void LogContainerCreation (container_t container)
322 double timestamp = SIMIX_get_clock();
324 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_CreateContainer,timestamp);
326 if (instr_fmt_type == instr_fmt_paje) {
327 stream << std::fixed << std::setprecision(TRACE_precision());
328 stream << PAJE_CreateContainer;
330 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
331 if (timestamp < 1e-12)
335 stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
336 << container->name << "\"";
339 } else if (instr_fmt_type == instr_fmt_TI) {
340 // if we are in the mode with only one file
341 static FILE* ti_unique_file = nullptr;
343 if (tracing_files == nullptr) {
344 tracing_files = xbt_dict_new_homogeneous(nullptr);
345 // generate unique run id with time
346 prefix = xbt_os_time();
349 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
350 char* folder_name = bprintf("%s_files", TRACE_get_filename());
351 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
355 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
357 ti_unique_file = fopen(filename, "w");
358 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
359 fprintf(tracing_file, "%s\n", filename);
361 xbt_free(folder_name);
365 xbt_dict_set(tracing_files, container->name, (void*)ti_unique_file, nullptr);
371 void LogContainerDestruction(container_t container)
373 double timestamp = SIMIX_get_clock();
375 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_DestroyContainer, timestamp);
377 if (instr_fmt_type == instr_fmt_paje) {
378 stream << std::fixed << std::setprecision(TRACE_precision());
379 stream << PAJE_DestroyContainer;
381 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
382 if (timestamp < 1e-12)
386 stream << " " << container->type->id << " " << container->id;
388 } else if (instr_fmt_type == instr_fmt_TI) {
389 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
390 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
393 xbt_dict_remove(tracing_files, container->name);
400 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
402 this->event_type = PAJE_SetVariable;
403 this->timestamp = timestamp;
405 this->container = container;
408 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
410 insert_into_buffer (this);
413 void SetVariableEvent::print() {
414 if (instr_fmt_type == instr_fmt_paje) {
415 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
416 stream << std::fixed << std::setprecision(TRACE_precision());
417 stream << (int)this->event_type;
418 print_timestamp(this);
419 stream << " " << type->id << " " << container->id << " " << value;
421 } else if (instr_fmt_type == instr_fmt_TI) {
428 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, type_t type, double value)
430 this->event_type = PAJE_AddVariable;
431 this->timestamp = timestamp;
433 this->container = container;
436 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
438 insert_into_buffer (this);
441 void AddVariableEvent::print() {
442 if (instr_fmt_type == instr_fmt_paje) {
443 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
444 stream << std::fixed << std::setprecision(TRACE_precision());
445 stream << (int)this->event_type;
446 print_timestamp(this);
447 stream << " " << type->id << " " << container->id << " " << value;
449 } else if (instr_fmt_type == instr_fmt_TI) {
456 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, type_t type, double value)
458 this->event_type = PAJE_SubVariable;
459 this->timestamp = timestamp;
461 this->container = container;
464 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
466 insert_into_buffer (this);
469 void SubVariableEvent::print() {
470 if (instr_fmt_type == instr_fmt_paje) {
471 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
472 stream << std::fixed << std::setprecision(TRACE_precision());
473 stream << (int)this->event_type;
474 print_timestamp(this);
475 stream << " " << type->id << " " << container->id << " " << value;
477 } else if (instr_fmt_type == instr_fmt_TI) {
484 SetStateEvent::SetStateEvent (double timestamp, container_t container, type_t type, val_t value)
486 this->event_type = PAJE_SetState;
487 this->timestamp = timestamp;
489 this->container = container;
493 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
494 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
495 filename = loc->filename;
496 linenumber = loc->linenumber;
500 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
502 insert_into_buffer (this);
505 void SetStateEvent::print() {
506 if (instr_fmt_type == instr_fmt_paje) {
507 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
508 stream << std::fixed << std::setprecision(TRACE_precision());
509 stream << (int)this->event_type;
510 print_timestamp(this);
511 stream << " " << type->id << " " << container->id;
512 stream << " " << value->id;
514 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
515 stream << " \"" << filename << "\" " << linenumber;
519 } else if (instr_fmt_type == instr_fmt_TI) {
526 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value, void* extra)
528 this->event_type = PAJE_PushState;
529 this->timestamp = timestamp;
531 this->container = container;
533 this->extra_ = extra;
536 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
537 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
538 filename = loc->filename;
539 linenumber = loc->linenumber;
543 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
545 insert_into_buffer (this);
548 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value)
549 : PushStateEvent(timestamp, container, type, value, nullptr)
551 void PushStateEvent::print() {
552 if (instr_fmt_type == instr_fmt_paje) {
553 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
554 stream << std::fixed << std::setprecision(TRACE_precision());
555 stream << (int)this->event_type;
556 print_timestamp(this);
557 stream << " " << type->id << " " << container->id;
558 stream << " " << value->id;
560 if (TRACE_display_sizes()) {
562 if (extra_ != nullptr) {
563 stream << static_cast<instr_extra_data>(extra_)->send_size;
569 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
570 stream << " \"" << filename << "\" " << linenumber;
575 if (extra_ != nullptr) {
576 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
577 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
578 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
579 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
582 } else if (instr_fmt_type == instr_fmt_TI) {
583 if (extra_ == nullptr)
585 instr_extra_data extra = (instr_extra_data)extra_;
587 char* process_id = nullptr;
588 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
589 if (strstr(container->name, "rank-") == nullptr)
590 process_id = xbt_strdup(container->name);
592 process_id = xbt_strdup(container->name + 5);
594 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name);
596 switch (extra->type) {
598 fprintf(trace_file, "%s init\n", process_id);
600 case TRACING_FINALIZE:
601 fprintf(trace_file, "%s finalize\n", process_id);
604 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
607 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
610 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
613 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
616 fprintf(trace_file, "%s test\n", process_id);
619 fprintf(trace_file, "%s wait\n", process_id);
621 case TRACING_WAITALL:
622 fprintf(trace_file, "%s waitAll\n", process_id);
624 case TRACING_BARRIER:
625 fprintf(trace_file, "%s barrier\n", process_id);
627 case TRACING_BCAST: // rank bcast size (root) (datatype)
628 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
629 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
630 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
631 fprintf(trace_file, "\n");
633 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
634 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
635 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
636 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
637 fprintf(trace_file, "\n");
639 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
640 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
643 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
644 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
645 extra->datatype1, extra->datatype2);
647 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
648 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
649 for (int i = 0; i < extra->num_processes; i++)
650 fprintf(trace_file, "%d ", extra->sendcounts[i]);
651 fprintf(trace_file, "%d ", extra->recv_size);
652 for (int i = 0; i < extra->num_processes; i++)
653 fprintf(trace_file, "%d ", extra->recvcounts[i]);
654 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
656 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
657 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
658 extra->datatype1, extra->datatype2);
660 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
661 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
662 for (int i = 0; i < extra->num_processes; i++)
663 fprintf(trace_file, "%d ", extra->recvcounts[i]);
664 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
666 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
667 fprintf(trace_file, "%s reduceScatter ", process_id);
668 for (int i = 0; i < extra->num_processes; i++)
669 fprintf(trace_file, "%d ", extra->recvcounts[i]);
670 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
672 case TRACING_COMPUTING:
673 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
675 case TRACING_SLEEPING:
676 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
678 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
679 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
680 for (int i = 0; i < extra->num_processes; i++)
681 fprintf(trace_file, "%d ", extra->recvcounts[i]);
682 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
684 case TRACING_WAITANY:
685 case TRACING_SENDRECV:
686 case TRACING_SCATTER:
687 case TRACING_SCATTERV:
688 case TRACING_ALLGATHER:
691 case TRACING_COMM_SIZE:
692 case TRACING_COMM_SPLIT:
693 case TRACING_COMM_DUP:
697 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->name);
701 if (extra->recvcounts != nullptr)
702 xbt_free(extra->recvcounts);
703 if (extra->sendcounts != nullptr)
704 xbt_free(extra->sendcounts);
705 xbt_free(process_id);
714 PopStateEvent::PopStateEvent (double timestamp, container_t container, type_t type)
716 this->event_type = PAJE_PopState;
717 this->timestamp = timestamp;
719 this->container = container;
721 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
723 insert_into_buffer (this);
726 void PopStateEvent::print() {
727 if (instr_fmt_type == instr_fmt_paje) {
728 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
729 stream << std::fixed << std::setprecision(TRACE_precision());
730 stream << (int)this->event_type;
731 print_timestamp(this);
732 stream << " " << type->id << " " << container->id;
734 } else if (instr_fmt_type == instr_fmt_TI) {
741 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_t type)
743 this->event_type = PAJE_ResetState;
744 this->timestamp = timestamp;
746 this->container = container;
748 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
750 insert_into_buffer (this);
754 void ResetStateEvent::print() {
755 if (instr_fmt_type == instr_fmt_paje) {
756 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
757 stream << std::fixed << std::setprecision(TRACE_precision());
758 stream << (int)this->event_type;
759 print_timestamp(this);
760 stream << " " << type->id << " " << container->id;
762 } else if (instr_fmt_type == instr_fmt_TI) {
769 StartLinkEvent::~StartLinkEvent()
774 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
775 type_t type, container_t sourceContainer, const char *value, const char *key)
776 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
779 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, type_t type, container_t sourceContainer,
780 const char *value, const char *key, int size)
782 event_type = PAJE_StartLink;
783 this->timestamp = timestamp;
785 this->container = container;
786 this->sourceContainer = sourceContainer;
787 this->value = xbt_strdup(value);
788 this->key = xbt_strdup(key);
791 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
792 (int)event_type, this->timestamp, this->value);
794 insert_into_buffer (this);
797 void StartLinkEvent::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 << " " << value;
804 stream << " " << sourceContainer->id << " " << key;
806 if (TRACE_display_sizes()) {
807 stream << " " << size;
810 } else if (instr_fmt_type == instr_fmt_TI) {
817 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
818 const char *value, const char *key)
820 this->event_type = PAJE_EndLink;
821 this->timestamp = timestamp;
823 this->container = container;
824 this->destContainer = destContainer;
825 this->value = xbt_strdup(value);
826 this->key = xbt_strdup(key);
828 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
830 insert_into_buffer (this);
833 EndLinkEvent::~EndLinkEvent()
838 void EndLinkEvent::print() {
839 if (instr_fmt_type == instr_fmt_paje) {
840 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
841 stream << std::fixed << std::setprecision(TRACE_precision());
842 stream << (int)this->event_type;
843 print_timestamp(this);
844 stream << " " << type->id << " " << container->id << " " << value;
845 stream << " " << destContainer->id << " " << key;
847 } else if (instr_fmt_type == instr_fmt_TI) {
854 NewEvent::NewEvent (double timestamp, container_t container, type_t type, val_t value)
856 this->event_type = PAJE_NewEvent;
857 this->timestamp = timestamp;
859 this->container = container;
862 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
864 insert_into_buffer (this);
867 void NewEvent::print () {
868 if (instr_fmt_type == instr_fmt_paje) {
869 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
870 stream << std::fixed << std::setprecision(TRACE_precision());
871 stream << (int)this->event_type;
872 print_timestamp(this);
873 stream << " " << type->id << " " << container->id << " " << value->id;
875 } else if (instr_fmt_type == instr_fmt_TI) {
883 void TRACE_TI_start()
885 char *filename = TRACE_get_filename();
886 tracing_file = fopen(filename, "w");
887 if (tracing_file == nullptr)
888 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
890 XBT_DEBUG("Filename %s is open for writing", filename);
892 /* output one line comment */
893 dump_comment(TRACE_get_comment());
895 /* output comment file */
896 dump_comment_file(TRACE_get_comment_file());
901 xbt_dict_free(&tracing_files);
902 fclose(tracing_file);
903 char *filename = TRACE_get_filename();
904 XBT_DEBUG("Filename %s is closed", filename);