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
224 << " " << type->father->id
225 << " " << type->name;
227 } else if (instr_fmt_type == instr_fmt_TI) {
237 void LogVariableTypeDefinition(type_t type)
240 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineVariableType);
243 if (instr_fmt_type == instr_fmt_paje) {
244 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineVariableType, TRACE_precision(), 0.);
245 stream << std::fixed << std::setprecision(TRACE_precision());
246 stream << PAJE_DefineVariableType;
247 stream << " " << type->id << " " << type->father->id << " " << type->name;
249 stream << " \"" << type->color << "\"";
251 } else if (instr_fmt_type == instr_fmt_TI) {
259 void LogStateTypeDefinition(type_t type)
262 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineStateType);
265 if (instr_fmt_type == instr_fmt_paje) {
266 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineStateType, TRACE_precision(), 0.);
267 stream << std::fixed << std::setprecision(TRACE_precision());
268 stream << PAJE_DefineStateType;
269 stream << " " << type->id << " " << type->father->id << " " << type->name;
271 } else if (instr_fmt_type == instr_fmt_TI) {
279 DefineEventTypeEvent::DefineEventTypeEvent(type_t type)
281 this->event_type = PAJE_DefineEventType;
285 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
292 void DefineEventTypeEvent::print() {
293 if (instr_fmt_type == instr_fmt_paje) {
294 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
295 stream << std::fixed << std::setprecision(TRACE_precision());
296 stream << (int)this->event_type;
297 stream << " " << type->id << " " << type->father->id << " " << type->name;
299 } else if (instr_fmt_type == instr_fmt_TI) {
306 void LogLinkTypeDefinition(type_t type, type_t source, type_t dest)
308 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineLinkType);
310 if (instr_fmt_type == instr_fmt_paje) {
311 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.);
312 stream << std::fixed << std::setprecision(TRACE_precision());
313 stream << PAJE_DefineLinkType;
314 stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
316 } else if (instr_fmt_type == instr_fmt_TI) {
323 void LogEntityValue (val_t value)
325 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineEntityValue);
327 if (instr_fmt_type == instr_fmt_paje) {
328 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineEntityValue, TRACE_precision(),0.);
329 stream << std::fixed << std::setprecision(TRACE_precision());
330 stream << PAJE_DefineEntityValue;
331 stream << " " << value->id << " " << value->father->id << " " << value->name;
333 stream << " \"" << value->color << "\"";
335 } else if (instr_fmt_type == instr_fmt_TI) {
343 void LogContainerCreation (container_t container)
345 double timestamp = SIMIX_get_clock();
347 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_CreateContainer,timestamp);
349 if (instr_fmt_type == instr_fmt_paje) {
350 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_CreateContainer, TRACE_precision(), timestamp);
351 stream << std::fixed << std::setprecision(TRACE_precision());
352 stream << PAJE_CreateContainer;
354 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
355 if (timestamp < 1e-12)
359 stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
360 << container->name << "\"";
363 } else if (instr_fmt_type == instr_fmt_TI) {
364 // if we are in the mode with only one file
365 static FILE* ti_unique_file = nullptr;
367 if (tracing_files == nullptr) {
368 tracing_files = xbt_dict_new_homogeneous(nullptr);
369 // generate unique run id with time
370 prefix = xbt_os_time();
373 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
374 char* folder_name = bprintf("%s_files", TRACE_get_filename());
375 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
379 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
381 ti_unique_file = fopen(filename, "w");
382 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
383 fprintf(tracing_file, "%s\n", filename);
385 xbt_free(folder_name);
389 xbt_dict_set(tracing_files, container->name, (void*)ti_unique_file, nullptr);
395 void LogContainerDestruction(container_t container)
397 double timestamp = SIMIX_get_clock();
399 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_DestroyContainer, timestamp);
401 if (instr_fmt_type == instr_fmt_paje) {
402 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DestroyContainer, TRACE_precision(), timestamp);
403 stream << std::fixed << std::setprecision(TRACE_precision());
404 stream << PAJE_DestroyContainer;
406 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
407 if (timestamp < 1e-12)
411 stream << " " << container->type->id << " " << container->id;
413 } else if (instr_fmt_type == instr_fmt_TI) {
414 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
415 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
418 xbt_dict_remove(tracing_files, container->name);
425 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
427 this->event_type = PAJE_SetVariable;
428 this->timestamp = timestamp;
430 this->container = container;
433 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
435 insert_into_buffer (this);
438 void SetVariableEvent::print() {
439 if (instr_fmt_type == instr_fmt_paje) {
440 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
441 stream << std::fixed << std::setprecision(TRACE_precision());
442 stream << (int)this->event_type;
443 print_timestamp(this);
444 stream << " " << type->id << " " << container->id << " " << value;
446 } else if (instr_fmt_type == instr_fmt_TI) {
453 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, type_t type, double value)
455 this->event_type = PAJE_AddVariable;
456 this->timestamp = timestamp;
458 this->container = container;
461 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
463 insert_into_buffer (this);
466 void AddVariableEvent::print() {
467 if (instr_fmt_type == instr_fmt_paje) {
468 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
469 stream << std::fixed << std::setprecision(TRACE_precision());
470 stream << (int)this->event_type;
471 print_timestamp(this);
472 stream << " " << type->id << " " << container->id << " " << value;
474 } else if (instr_fmt_type == instr_fmt_TI) {
481 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, type_t type, double value)
483 this->event_type = PAJE_SubVariable;
484 this->timestamp = timestamp;
486 this->container = container;
489 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
491 insert_into_buffer (this);
494 void SubVariableEvent::print() {
495 if (instr_fmt_type == instr_fmt_paje) {
496 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
497 stream << std::fixed << std::setprecision(TRACE_precision());
498 stream << (int)this->event_type;
499 print_timestamp(this);
500 stream << " " << type->id << " " << container->id << " " << value;
502 } else if (instr_fmt_type == instr_fmt_TI) {
509 SetStateEvent::SetStateEvent (double timestamp, container_t container, type_t type, val_t value)
511 this->event_type = PAJE_SetState;
512 this->timestamp = timestamp;
514 this->container = container;
518 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
519 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
520 filename = loc->filename;
521 linenumber = loc->linenumber;
525 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
527 insert_into_buffer (this);
530 void SetStateEvent::print() {
531 if (instr_fmt_type == instr_fmt_paje) {
532 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
533 stream << std::fixed << std::setprecision(TRACE_precision());
534 stream << (int)this->event_type;
535 print_timestamp(this);
536 stream << " " << type->id << " " << container->id;
537 stream << " " << value->id;
539 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
540 stream << " \"" << filename << "\" " << linenumber;
544 } else if (instr_fmt_type == instr_fmt_TI) {
551 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value, void* extra)
553 this->event_type = PAJE_PushState;
554 this->timestamp = timestamp;
556 this->container = container;
558 this->extra_ = extra;
561 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
562 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
563 filename = loc->filename;
564 linenumber = loc->linenumber;
568 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
570 insert_into_buffer (this);
573 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value)
574 : PushStateEvent(timestamp, container, type, value, nullptr)
576 void PushStateEvent::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 (TRACE_display_sizes()) {
587 if (extra_ != nullptr) {
588 stream << static_cast<instr_extra_data>(extra_)->send_size;
594 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
595 stream << " \"" << filename << "\" " << linenumber;
600 if (extra_ != nullptr) {
601 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
602 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
603 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
604 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
607 } else if (instr_fmt_type == instr_fmt_TI) {
608 if (extra_ == nullptr)
610 instr_extra_data extra = (instr_extra_data)extra_;
612 char* process_id = nullptr;
613 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
614 if (strstr(container->name, "rank-") == nullptr)
615 process_id = xbt_strdup(container->name);
617 process_id = xbt_strdup(container->name + 5);
619 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name);
621 switch (extra->type) {
623 fprintf(trace_file, "%s init\n", process_id);
625 case TRACING_FINALIZE:
626 fprintf(trace_file, "%s finalize\n", process_id);
629 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
632 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
635 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
638 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
641 fprintf(trace_file, "%s test\n", process_id);
644 fprintf(trace_file, "%s wait\n", process_id);
646 case TRACING_WAITALL:
647 fprintf(trace_file, "%s waitAll\n", process_id);
649 case TRACING_BARRIER:
650 fprintf(trace_file, "%s barrier\n", process_id);
652 case TRACING_BCAST: // rank bcast size (root) (datatype)
653 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
654 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
655 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
656 fprintf(trace_file, "\n");
658 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
659 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
660 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
661 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
662 fprintf(trace_file, "\n");
664 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
665 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
668 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
669 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
670 extra->datatype1, extra->datatype2);
672 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
673 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
674 for (int i = 0; i < extra->num_processes; i++)
675 fprintf(trace_file, "%d ", extra->sendcounts[i]);
676 fprintf(trace_file, "%d ", extra->recv_size);
677 for (int i = 0; i < extra->num_processes; i++)
678 fprintf(trace_file, "%d ", extra->recvcounts[i]);
679 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
681 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
682 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
683 extra->datatype1, extra->datatype2);
685 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
686 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
687 for (int i = 0; i < extra->num_processes; i++)
688 fprintf(trace_file, "%d ", extra->recvcounts[i]);
689 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
691 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
692 fprintf(trace_file, "%s reduceScatter ", process_id);
693 for (int i = 0; i < extra->num_processes; i++)
694 fprintf(trace_file, "%d ", extra->recvcounts[i]);
695 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
697 case TRACING_COMPUTING:
698 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
700 case TRACING_SLEEPING:
701 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
703 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
704 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
705 for (int i = 0; i < extra->num_processes; i++)
706 fprintf(trace_file, "%d ", extra->recvcounts[i]);
707 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
709 case TRACING_WAITANY:
710 case TRACING_SENDRECV:
711 case TRACING_SCATTER:
712 case TRACING_SCATTERV:
713 case TRACING_ALLGATHER:
716 case TRACING_COMM_SIZE:
717 case TRACING_COMM_SPLIT:
718 case TRACING_COMM_DUP:
722 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", value->name);
726 if (extra->recvcounts != nullptr)
727 xbt_free(extra->recvcounts);
728 if (extra->sendcounts != nullptr)
729 xbt_free(extra->sendcounts);
730 xbt_free(process_id);
739 PopStateEvent::PopStateEvent (double timestamp, container_t container, type_t type)
741 this->event_type = PAJE_PopState;
742 this->timestamp = timestamp;
744 this->container = container;
746 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
748 insert_into_buffer (this);
751 void PopStateEvent::print() {
752 if (instr_fmt_type == instr_fmt_paje) {
753 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
754 stream << std::fixed << std::setprecision(TRACE_precision());
755 stream << (int)this->event_type;
756 print_timestamp(this);
757 stream << " " << type->id << " " << container->id;
759 } else if (instr_fmt_type == instr_fmt_TI) {
766 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_t type)
768 this->event_type = PAJE_ResetState;
769 this->timestamp = timestamp;
771 this->container = container;
773 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
775 insert_into_buffer (this);
779 void ResetStateEvent::print() {
780 if (instr_fmt_type == instr_fmt_paje) {
781 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
782 stream << std::fixed << std::setprecision(TRACE_precision());
783 stream << (int)this->event_type;
784 print_timestamp(this);
785 stream << " " << type->id << " " << container->id;
787 } else if (instr_fmt_type == instr_fmt_TI) {
794 StartLinkEvent::~StartLinkEvent()
799 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
800 type_t type, container_t sourceContainer, const char *value, const char *key)
801 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
804 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, type_t type, container_t sourceContainer,
805 const char *value, const char *key, int size)
807 event_type = PAJE_StartLink;
808 this->timestamp = timestamp;
810 this->container = container;
811 this->sourceContainer = sourceContainer;
812 this->value = xbt_strdup(value);
813 this->key = xbt_strdup(key);
816 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
817 (int)event_type, this->timestamp, this->value);
819 insert_into_buffer (this);
822 void StartLinkEvent::print() {
823 if (instr_fmt_type == instr_fmt_paje) {
824 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
825 stream << std::fixed << std::setprecision(TRACE_precision());
826 stream << (int)this->event_type;
827 print_timestamp(this);
828 stream << " " << type->id << " " << container->id << " " << value;
829 stream << " " << sourceContainer->id << " " << key;
831 if (TRACE_display_sizes()) {
832 stream << " " << size;
835 } else if (instr_fmt_type == instr_fmt_TI) {
842 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
843 const char *value, const char *key)
845 this->event_type = PAJE_EndLink;
846 this->timestamp = timestamp;
848 this->container = container;
849 this->destContainer = destContainer;
850 this->value = xbt_strdup(value);
851 this->key = xbt_strdup(key);
853 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
855 insert_into_buffer (this);
858 EndLinkEvent::~EndLinkEvent()
863 void EndLinkEvent::print() {
864 if (instr_fmt_type == instr_fmt_paje) {
865 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
866 stream << std::fixed << std::setprecision(TRACE_precision());
867 stream << (int)this->event_type;
868 print_timestamp(this);
869 stream << " " << type->id << " " << container->id << " " << value;
870 stream << " " << destContainer->id << " " << key;
872 } else if (instr_fmt_type == instr_fmt_TI) {
879 NewEvent::NewEvent (double timestamp, container_t container, type_t type, val_t value)
881 this->event_type = PAJE_NewEvent;
882 this->timestamp = timestamp;
884 this->container = container;
887 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
889 insert_into_buffer (this);
892 void NewEvent::print () {
893 if (instr_fmt_type == instr_fmt_paje) {
894 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
895 stream << std::fixed << std::setprecision(TRACE_precision());
896 stream << (int)this->event_type;
897 print_timestamp(this);
898 stream << " " << type->id << " " << container->id << " " << value->id;
900 } else if (instr_fmt_type == instr_fmt_TI) {
908 void TRACE_TI_start()
910 char *filename = TRACE_get_filename();
911 tracing_file = fopen(filename, "w");
912 if (tracing_file == nullptr)
913 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
915 XBT_DEBUG("Filename %s is open for writing", filename);
917 /* output one line comment */
918 dump_comment(TRACE_get_comment());
920 /* output comment file */
921 dump_comment_file(TRACE_get_comment_file());
926 xbt_dict_free(&tracing_files);
927 fclose(tracing_file);
928 char *filename = TRACE_get_filename();
929 XBT_DEBUG("Filename %s is closed", filename);