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
31 void print_NULL(PajeEvent* event){}
33 /* The active set of functions for the selected trace format
34 * By default, they all do nothing, hence the print_NULL to avoid segfaults */
36 std::vector<PajeEvent*> buffer;
37 void buffer_debug(std::vector<PajeEvent*> *buf);
39 void dump_comment (const char *comment)
41 if (not strlen(comment))
43 fprintf (tracing_file, "# %s\n", comment);
46 void dump_comment_file (const char *filename)
48 if (not strlen(filename))
50 FILE *file = fopen (filename, "r");
52 THROWF (system_error, 1, "Comment file %s could not be opened for reading.", filename);
54 while (not feof(file)) {
57 if (feof(file)) break;
58 fprintf (tracing_file, "# ");
60 fprintf (tracing_file, "%c", c);
62 if (feof(file)) break;
64 fprintf (tracing_file, "\n");
69 double TRACE_last_timestamp_to_dump = 0;
70 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
71 void TRACE_paje_dump_buffer (int force)
73 if (not TRACE_is_enabled())
75 XBT_DEBUG("%s: dump until %f. starts", __FUNCTION__, TRACE_last_timestamp_to_dump);
77 for (auto event : buffer){
83 std::vector<PajeEvent*>::iterator i = buffer.begin();
84 for (auto event :buffer){
85 double head_timestamp = event->timestamp;
86 if (head_timestamp > TRACE_last_timestamp_to_dump)
92 buffer.erase(buffer.begin(), i);
94 XBT_DEBUG("%s: ends", __FUNCTION__);
97 void buffer_debug(std::vector<PajeEvent*> *buf);
98 void buffer_debug(std::vector<PajeEvent*> *buf) {
100 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
101 for (auto event :*buf){
103 XBT_DEBUG("%p %s", event, stream.str().c_str());
110 static void print_row() {
112 fprintf(tracing_file, "%s", stream.str().c_str());
113 XBT_DEBUG("Dump %s", stream.str().c_str());
118 static void print_timestamp(PajeEvent* event) {
120 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
121 if (event->timestamp < 1e-12)
124 stream << event->timestamp;
127 /* internal do the instrumentation module */
128 static void insert_into_buffer (PajeEvent* tbi)
130 if (TRACE_buffer() == 0){
135 buffer_debug(&buffer);
137 XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)",
138 __FUNCTION__, (int)tbi->event_type, tbi->timestamp, buffer.size());
139 std::vector<PajeEvent*>::reverse_iterator i;
140 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
142 XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1,
143 (int)e1->event_type, e1->timestamp);
144 if (e1->timestamp <= tbi->timestamp)
147 if (i == buffer.rend())
148 XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
149 else if (i == buffer.rbegin())
150 XBT_DEBUG("%s: inserted at end", __FUNCTION__);
152 XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
153 std::distance(buffer.rbegin(),i));
154 buffer.insert(i.base(), tbi);
156 buffer_debug(&buffer);
159 PajeEvent:: ~PajeEvent()
161 XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__,
162 this, (int)event_type, timestamp);
163 // xbt_backtrace_display_current();
165 /* switch (event->event_type){
167 xbt_free (((startLink_t)(event->data))->value);
168 xbt_free (((startLink_t)(event->data))->key);
171 xbt_free (((endLink_t)(event->data))->value);
172 xbt_free (((endLink_t)(event->data))->key);
179 void TRACE_paje_start() {
180 char *filename = TRACE_get_filename();
181 tracing_file = fopen(filename, "w");
182 if (tracing_file == nullptr){
183 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
186 XBT_DEBUG("Filename %s is open for writing", filename);
188 /* output generator version */
189 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
190 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
191 fprintf (tracing_file, "#[");
194 xbt_dynar_foreach (xbt_cmdline, cpt, str){
195 fprintf(tracing_file, "%s ",str);
197 fprintf (tracing_file, "]\n");
199 /* output one line comment */
200 dump_comment (TRACE_get_comment());
202 /* output comment file */
203 dump_comment_file (TRACE_get_comment_file());
206 TRACE_header(TRACE_basic(),TRACE_display_sizes());
209 void TRACE_paje_end() {
210 fclose(tracing_file);
211 char *filename = TRACE_get_filename();
212 XBT_DEBUG("Filename %s is closed", filename);
215 void DefineContainerEvent(type_t type)
217 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineContainerType);
219 if (instr_fmt_type == instr_fmt_paje) {
220 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineContainerType, TRACE_precision(), 0.);
221 stream << std::fixed << std::setprecision(TRACE_precision());
222 stream << PAJE_DefineContainerType;
223 stream << " " << type->id << " " << type->father->id << " " << type->name;
225 } else if (instr_fmt_type == instr_fmt_TI) {
235 void LogVariableTypeDefinition(type_t type)
238 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineVariableType);
241 if (instr_fmt_type == instr_fmt_paje) {
242 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineVariableType, TRACE_precision(), 0.);
243 stream << std::fixed << std::setprecision(TRACE_precision());
244 stream << PAJE_DefineVariableType;
245 stream << " " << type->id << " " << type->father->id << " " << type->name;
247 stream << " \"" << type->color << "\"";
249 } else if (instr_fmt_type == instr_fmt_TI) {
257 void LogStateTypeDefinition(type_t type)
260 if (instr_fmt_type == instr_fmt_paje) {
261 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineStateType, TRACE_precision(), 0.);
262 stream << std::fixed << std::setprecision(TRACE_precision());
263 stream << PAJE_DefineStateType;
264 stream << " " << type->id << " " << type->father->id << " " << type->name;
266 } else if (instr_fmt_type == instr_fmt_TI) {
274 void LogDefineEventType(type_t type)
277 if (instr_fmt_type == instr_fmt_paje) {
278 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineEventType, TRACE_precision(), 0.);
279 stream << std::fixed << std::setprecision(TRACE_precision());
280 stream << PAJE_DefineEventType;
281 stream << " " << type->id << " " << type->father->id << " " << type->name;
283 } else if (instr_fmt_type == instr_fmt_TI) {
290 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest)
292 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineLinkType);
294 if (instr_fmt_type == instr_fmt_paje) {
295 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.);
296 stream << std::fixed << std::setprecision(TRACE_precision());
297 stream << PAJE_DefineLinkType;
298 stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
300 } else if (instr_fmt_type == instr_fmt_TI) {
307 void LogEntityValue (val_t value)
309 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineEntityValue);
311 if (instr_fmt_type == instr_fmt_paje) {
312 stream << std::fixed << std::setprecision(TRACE_precision());
313 stream << PAJE_DefineEntityValue;
314 stream << " " << value->id << " " << value->father->id << " " << value->name;
316 stream << " \"" << value->color << "\"";
318 } else if (instr_fmt_type == instr_fmt_TI) {
326 void LogContainerCreation (container_t container)
328 double timestamp = SIMIX_get_clock();
330 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_CreateContainer,timestamp);
332 if (instr_fmt_type == instr_fmt_paje) {
333 stream << std::fixed << std::setprecision(TRACE_precision());
334 stream << PAJE_CreateContainer;
336 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
337 if (timestamp < 1e-12)
341 stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
342 << container->name << "\"";
345 } else if (instr_fmt_type == instr_fmt_TI) {
346 // if we are in the mode with only one file
347 static FILE* ti_unique_file = nullptr;
349 if (tracing_files == nullptr) {
350 tracing_files = xbt_dict_new_homogeneous(nullptr);
351 // generate unique run id with time
352 prefix = xbt_os_time();
355 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
356 char* folder_name = bprintf("%s_files", TRACE_get_filename());
357 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
361 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
363 ti_unique_file = fopen(filename, "w");
364 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
365 fprintf(tracing_file, "%s\n", filename);
367 xbt_free(folder_name);
371 xbt_dict_set(tracing_files, container->name, (void*)ti_unique_file, nullptr);
377 void LogContainerDestruction(container_t container)
379 double timestamp = SIMIX_get_clock();
381 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_DestroyContainer, timestamp);
383 if (instr_fmt_type == instr_fmt_paje) {
384 stream << std::fixed << std::setprecision(TRACE_precision());
385 stream << PAJE_DestroyContainer;
387 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
388 if (timestamp < 1e-12)
392 stream << " " << container->type->id << " " << container->id;
394 } else if (instr_fmt_type == instr_fmt_TI) {
395 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
396 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
399 xbt_dict_remove(tracing_files, container->name);
406 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
408 this->event_type = PAJE_SetVariable;
409 this->timestamp = timestamp;
411 this->container = container;
414 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
416 insert_into_buffer (this);
419 void SetVariableEvent::print() {
420 if (instr_fmt_type == instr_fmt_paje) {
421 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
422 stream << std::fixed << std::setprecision(TRACE_precision());
423 stream << (int)this->event_type;
424 print_timestamp(this);
425 stream << " " << type->id << " " << container->id << " " << value;
427 } else if (instr_fmt_type == instr_fmt_TI) {
434 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, type_t type, double value)
436 this->event_type = PAJE_AddVariable;
437 this->timestamp = timestamp;
439 this->container = container;
442 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
444 insert_into_buffer (this);
447 void AddVariableEvent::print() {
448 if (instr_fmt_type == instr_fmt_paje) {
449 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
450 stream << std::fixed << std::setprecision(TRACE_precision());
451 stream << (int)this->event_type;
452 print_timestamp(this);
453 stream << " " << type->id << " " << container->id << " " << value;
455 } else if (instr_fmt_type == instr_fmt_TI) {
462 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, type_t type, double value)
464 this->event_type = PAJE_SubVariable;
465 this->timestamp = timestamp;
467 this->container = container;
470 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
472 insert_into_buffer (this);
475 void SubVariableEvent::print() {
476 if (instr_fmt_type == instr_fmt_paje) {
477 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
478 stream << std::fixed << std::setprecision(TRACE_precision());
479 stream << (int)this->event_type;
480 print_timestamp(this);
481 stream << " " << type->id << " " << container->id << " " << value;
483 } else if (instr_fmt_type == instr_fmt_TI) {
490 SetStateEvent::SetStateEvent (double timestamp, container_t container, type_t type, val_t value)
492 this->event_type = PAJE_SetState;
493 this->timestamp = timestamp;
495 this->container = container;
499 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
500 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
501 filename = loc->filename;
502 linenumber = loc->linenumber;
506 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
508 insert_into_buffer (this);
511 void SetStateEvent::print() {
512 if (instr_fmt_type == instr_fmt_paje) {
513 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
514 stream << std::fixed << std::setprecision(TRACE_precision());
515 stream << (int)this->event_type;
516 print_timestamp(this);
517 stream << " " << type->id << " " << container->id;
518 stream << " " << value->id;
520 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
521 stream << " \"" << filename << "\" " << linenumber;
525 } else if (instr_fmt_type == instr_fmt_TI) {
532 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value, void* extra)
534 this->event_type = PAJE_PushState;
535 this->timestamp = timestamp;
537 this->container = container;
539 this->extra_ = extra;
542 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
543 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
544 filename = loc->filename;
545 linenumber = loc->linenumber;
549 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
551 insert_into_buffer (this);
554 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value)
555 : PushStateEvent(timestamp, container, type, value, nullptr)
557 void PushStateEvent::print() {
558 if (instr_fmt_type == instr_fmt_paje) {
559 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
560 stream << std::fixed << std::setprecision(TRACE_precision());
561 stream << (int)this->event_type;
562 print_timestamp(this);
563 stream << " " << type->id << " " << container->id;
564 stream << " " << value->id;
566 if (TRACE_display_sizes()) {
568 if (extra_ != nullptr) {
569 stream << static_cast<instr_extra_data>(extra_)->send_size;
575 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
576 stream << " \"" << filename << "\" " << linenumber;
581 if (extra_ != nullptr) {
582 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
583 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
584 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
585 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
588 } else if (instr_fmt_type == instr_fmt_TI) {
589 if (extra_ == nullptr)
591 instr_extra_data extra = (instr_extra_data)extra_;
593 char* process_id = nullptr;
594 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
595 if (strstr(container->name, "rank-") == nullptr)
596 process_id = xbt_strdup(container->name);
598 process_id = xbt_strdup(container->name + 5);
600 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name);
602 switch (extra->type) {
604 fprintf(trace_file, "%s init\n", process_id);
606 case TRACING_FINALIZE:
607 fprintf(trace_file, "%s finalize\n", process_id);
610 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
613 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
616 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
619 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
622 fprintf(trace_file, "%s test\n", process_id);
625 fprintf(trace_file, "%s wait\n", process_id);
627 case TRACING_WAITALL:
628 fprintf(trace_file, "%s waitAll\n", process_id);
630 case TRACING_BARRIER:
631 fprintf(trace_file, "%s barrier\n", process_id);
633 case TRACING_BCAST: // rank bcast size (root) (datatype)
634 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_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_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
640 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
641 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
642 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
643 fprintf(trace_file, "\n");
645 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
646 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
649 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
650 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
651 extra->datatype1, extra->datatype2);
653 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
654 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
655 for (int i = 0; i < extra->num_processes; i++)
656 fprintf(trace_file, "%d ", extra->sendcounts[i]);
657 fprintf(trace_file, "%d ", extra->recv_size);
658 for (int i = 0; i < extra->num_processes; i++)
659 fprintf(trace_file, "%d ", extra->recvcounts[i]);
660 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
662 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
663 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
664 extra->datatype1, extra->datatype2);
666 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
667 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
668 for (int i = 0; i < extra->num_processes; i++)
669 fprintf(trace_file, "%d ", extra->recvcounts[i]);
670 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
672 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
673 fprintf(trace_file, "%s reduceScatter ", process_id);
674 for (int i = 0; i < extra->num_processes; i++)
675 fprintf(trace_file, "%d ", extra->recvcounts[i]);
676 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
678 case TRACING_COMPUTING:
679 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
681 case TRACING_SLEEPING:
682 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
684 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
685 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
686 for (int i = 0; i < extra->num_processes; i++)
687 fprintf(trace_file, "%d ", extra->recvcounts[i]);
688 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
690 case TRACING_WAITANY:
691 case TRACING_SENDRECV:
692 case TRACING_SCATTER:
693 case TRACING_SCATTERV:
694 case TRACING_ALLGATHER:
697 case TRACING_COMM_SIZE:
698 case TRACING_COMM_SPLIT:
699 case TRACING_COMM_DUP:
703 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->name);
707 if (extra->recvcounts != nullptr)
708 xbt_free(extra->recvcounts);
709 if (extra->sendcounts != nullptr)
710 xbt_free(extra->sendcounts);
711 xbt_free(process_id);
720 PopStateEvent::PopStateEvent (double timestamp, container_t container, type_t type)
722 this->event_type = PAJE_PopState;
723 this->timestamp = timestamp;
725 this->container = container;
727 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
729 insert_into_buffer (this);
732 void PopStateEvent::print() {
733 if (instr_fmt_type == instr_fmt_paje) {
734 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
735 stream << std::fixed << std::setprecision(TRACE_precision());
736 stream << (int)this->event_type;
737 print_timestamp(this);
738 stream << " " << type->id << " " << container->id;
740 } else if (instr_fmt_type == instr_fmt_TI) {
747 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_t type)
749 this->event_type = PAJE_ResetState;
750 this->timestamp = timestamp;
752 this->container = container;
754 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
756 insert_into_buffer (this);
760 void ResetStateEvent::print() {
761 if (instr_fmt_type == instr_fmt_paje) {
762 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
763 stream << std::fixed << std::setprecision(TRACE_precision());
764 stream << (int)this->event_type;
765 print_timestamp(this);
766 stream << " " << type->id << " " << container->id;
768 } else if (instr_fmt_type == instr_fmt_TI) {
775 StartLinkEvent::~StartLinkEvent()
780 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
781 type_t type, container_t sourceContainer, const char *value, const char *key)
782 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
785 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, type_t type, container_t sourceContainer,
786 const char *value, const char *key, int size)
788 event_type = PAJE_StartLink;
789 this->timestamp = timestamp;
791 this->container = container;
792 this->sourceContainer = sourceContainer;
793 this->value = xbt_strdup(value);
794 this->key = xbt_strdup(key);
797 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
798 (int)event_type, this->timestamp, this->value);
800 insert_into_buffer (this);
803 void StartLinkEvent::print() {
804 if (instr_fmt_type == instr_fmt_paje) {
805 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
806 stream << std::fixed << std::setprecision(TRACE_precision());
807 stream << (int)this->event_type;
808 print_timestamp(this);
809 stream << " " << type->id << " " << container->id << " " << value;
810 stream << " " << sourceContainer->id << " " << key;
812 if (TRACE_display_sizes()) {
813 stream << " " << size;
816 } else if (instr_fmt_type == instr_fmt_TI) {
823 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
824 const char *value, const char *key)
826 this->event_type = PAJE_EndLink;
827 this->timestamp = timestamp;
829 this->container = container;
830 this->destContainer = destContainer;
831 this->value = xbt_strdup(value);
832 this->key = xbt_strdup(key);
834 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
836 insert_into_buffer (this);
839 EndLinkEvent::~EndLinkEvent()
844 void EndLinkEvent::print() {
845 if (instr_fmt_type == instr_fmt_paje) {
846 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
847 stream << std::fixed << std::setprecision(TRACE_precision());
848 stream << (int)this->event_type;
849 print_timestamp(this);
850 stream << " " << type->id << " " << container->id << " " << value;
851 stream << " " << destContainer->id << " " << key;
853 } else if (instr_fmt_type == instr_fmt_TI) {
860 NewEvent::NewEvent (double timestamp, container_t container, type_t type, val_t value)
862 this->event_type = PAJE_NewEvent;
863 this->timestamp = timestamp;
865 this->container = container;
868 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
870 insert_into_buffer (this);
873 void NewEvent::print () {
874 if (instr_fmt_type == instr_fmt_paje) {
875 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
876 stream << std::fixed << std::setprecision(TRACE_precision());
877 stream << (int)this->event_type;
878 print_timestamp(this);
879 stream << " " << type->id << " " << container->id << " " << value->id;
881 } else if (instr_fmt_type == instr_fmt_TI) {
889 void TRACE_TI_start()
891 char *filename = TRACE_get_filename();
892 tracing_file = fopen(filename, "w");
893 if (tracing_file == nullptr)
894 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
896 XBT_DEBUG("Filename %s is open for writing", filename);
898 /* output one line comment */
899 dump_comment(TRACE_get_comment());
901 /* output comment file */
902 dump_comment_file(TRACE_get_comment_file());
907 xbt_dict_free(&tracing_files);
908 fclose(tracing_file);
909 char *filename = TRACE_get_filename();
910 XBT_DEBUG("Filename %s is closed", filename);