1 /* Copyright (c) 2010-2016. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "src/instr/instr_private.h"
8 #include "src/instr/instr_smpi.h"
9 #include "src/smpi/private.hpp"
11 #include "xbt/virtu.h" /* sg_cmdline */
12 #include "simgrid/sg_config.h"
16 #include <iomanip> /** std::setprecision **/
19 #include <direct.h> // _mkdir
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
24 extern s_instr_trace_writer_t active_writer;
26 static std::stringstream stream;
27 FILE *tracing_file = nullptr;
29 static xbt_dict_t tracing_files = nullptr; // TI specific
30 static double prefix=0.0; // TI specific
33 void print_NULL(PajeEvent* event){}
35 /* The active set of functions for the selected trace format
36 * By default, they all do nothing, hence the print_NULL to avoid segfaults */
38 s_instr_trace_writer_t active_writer = {&print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL,
39 &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL,
40 &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL};
42 std::vector<PajeEvent*> buffer;
43 void buffer_debug(std::vector<PajeEvent*> *buf);
45 void dump_comment (const char *comment)
47 if (!strlen(comment)) return;
48 fprintf (tracing_file, "# %s\n", comment);
51 void dump_comment_file (const char *filename)
53 if (!strlen(filename)) return;
54 FILE *file = fopen (filename, "r");
56 THROWF (system_error, 1, "Comment file %s could not be opened for reading.", filename);
61 if (feof(file)) break;
62 fprintf (tracing_file, "# ");
64 fprintf (tracing_file, "%c", c);
66 if (feof(file)) break;
68 fprintf (tracing_file, "\n");
73 double TRACE_last_timestamp_to_dump = 0;
74 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
75 void TRACE_paje_dump_buffer (int force)
77 if (!TRACE_is_enabled()) return;
78 XBT_DEBUG("%s: dump until %f. starts", __FUNCTION__, TRACE_last_timestamp_to_dump);
80 for (auto event : buffer){
86 std::vector<PajeEvent*>::iterator i = buffer.begin();
87 for (auto event :buffer){
88 double head_timestamp = event->timestamp;
89 if (head_timestamp > TRACE_last_timestamp_to_dump)
95 buffer.erase(buffer.begin(), i);
97 XBT_DEBUG("%s: ends", __FUNCTION__);
100 void buffer_debug(std::vector<PajeEvent*> *buf);
101 void buffer_debug(std::vector<PajeEvent*> *buf) {
103 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
104 for (auto event :*buf){
106 XBT_DEBUG("%p %s", event, stream.str().c_str());
113 static void print_row() {
115 fprintf(tracing_file, "%s", stream.str().c_str());
116 XBT_DEBUG("Dump %s", stream.str().c_str());
121 static void print_timestamp(PajeEvent* event) {
123 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
124 if (event->timestamp < 1e-12)
127 stream << event->timestamp;
130 /* internal do the instrumentation module */
131 static void insert_into_buffer (PajeEvent* tbi)
133 if (TRACE_buffer() == 0){
138 buffer_debug(&buffer);
140 XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)",
141 __FUNCTION__, (int)tbi->event_type, tbi->timestamp, buffer.size());
142 std::vector<PajeEvent*>::reverse_iterator i;
143 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
145 XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1,
146 (int)e1->event_type, e1->timestamp);
147 if (e1->timestamp <= tbi->timestamp)
150 buffer.insert(i.base(), tbi);
151 if (i == buffer.rend())
152 XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
153 else if (i == buffer.rbegin())
154 XBT_DEBUG("%s: inserted at end", __FUNCTION__);
156 XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
157 std::distance(buffer.rbegin(),i));
159 buffer_debug(&buffer);
162 PajeEvent:: ~PajeEvent()
164 XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__,
165 this, (int)event_type, timestamp);
166 // xbt_backtrace_display_current();
168 /* switch (event->event_type){
170 xbt_free (((startLink_t)(event->data))->value);
171 xbt_free (((startLink_t)(event->data))->key);
174 xbt_free (((endLink_t)(event->data))->value);
175 xbt_free (((endLink_t)(event->data))->key);
182 void TRACE_paje_start() {
183 char *filename = TRACE_get_filename();
184 tracing_file = fopen(filename, "w");
185 if (tracing_file == nullptr){
186 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
189 XBT_DEBUG("Filename %s is open for writing", filename);
191 /* output generator version */
192 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
193 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
194 fprintf (tracing_file, "#[");
197 xbt_dynar_foreach (xbt_cmdline, cpt, str){
198 fprintf(tracing_file, "%s ",str);
200 fprintf (tracing_file, "]\n");
202 /* output one line comment */
203 dump_comment (TRACE_get_comment());
205 /* output comment file */
206 dump_comment_file (TRACE_get_comment_file());
209 TRACE_header(TRACE_basic(),TRACE_display_sizes());
212 void TRACE_paje_end() {
213 fclose(tracing_file);
214 char *filename = TRACE_get_filename();
215 XBT_DEBUG("Filename %s is closed", filename);
218 DefineContainerEvent::DefineContainerEvent(type_t type)
221 event_type = PAJE_DefineContainerType;
224 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
229 void DefineContainerEvent::print() {
230 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
231 stream << std::fixed << std::setprecision(TRACE_precision());
232 stream << (int)this->event_type;
233 stream << " " << type->id
234 << " " << type->father->id
235 << " " << type->name;
241 DefineVariableTypeEvent::DefineVariableTypeEvent(type_t type)
243 this->event_type = PAJE_DefineVariableType;
247 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
253 void DefineVariableTypeEvent::print() {
254 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
255 stream << std::fixed << std::setprecision(TRACE_precision());
256 stream << (int)this->event_type;
257 stream << " " << type->id
258 << " " << type->father->id
259 << " " << type->name;
261 stream << " \"" << type->color << "\"";
265 DefineStateTypeEvent::DefineStateTypeEvent(type_t type)
267 this->event_type = PAJE_DefineStateType;
271 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
278 DefineEventTypeEvent::DefineEventTypeEvent(type_t type)
280 this->event_type = PAJE_DefineEventType;
284 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
291 void DefineStateTypeEvent::print() {
292 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
293 stream << std::fixed << std::setprecision(TRACE_precision());
294 stream << (int)this->event_type;
295 stream << " " << type->id
296 << " " << type->father->id
297 << " " << type->name;
301 void DefineEventTypeEvent::print() {
302 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
303 stream << std::fixed << std::setprecision(TRACE_precision());
304 stream << (int)this->event_type;
305 stream << " " << type->id
306 << " " << type->father->id
307 << " " << type->name;
311 DefineLinkTypeEvent::DefineLinkTypeEvent(type_t type, type_t source, type_t dest)
313 this->event_type = PAJE_DefineLinkType;
316 this->source = source;
319 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
325 void DefineLinkTypeEvent::print() {
326 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
327 stream << std::fixed << std::setprecision(TRACE_precision());
328 stream << (int)this->event_type;
329 stream << " " << type->id
330 << " " << type->father->id
333 << " " << type->name;
337 DefineEntityValueEvent::DefineEntityValueEvent (val_t value)
339 this->event_type = PAJE_DefineEntityValue;
343 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
350 void DefineEntityValueEvent::print() {
351 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
352 stream << std::fixed << std::setprecision(TRACE_precision());
353 stream << (int)this->event_type;
354 stream << " " << value->id
355 << " " << value->father->id
356 << " " << value->name;
358 stream << " \"" << value->color << "\"";
362 CreateContainerEvent::CreateContainerEvent (container_t container)
364 this->event_type = PAJE_CreateContainer;
365 this->timestamp = SIMIX_get_clock();
366 this->container = container;
368 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
373 void CreateContainerEvent::print() {
374 if (instr_fmt_type == instr_fmt_paje) {
375 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
376 stream << std::fixed << std::setprecision(TRACE_precision());
377 stream << (int)this->event_type;
378 print_timestamp(this);
379 stream << " " << container->id
380 << " " << container->type->id
381 << " " << container->father->id
382 << " \"" << container->name << "\"";
385 } else if (instr_fmt_type == instr_fmt_TI) {
386 //if we are in the mode with only one file
387 static FILE *temp = nullptr;
389 if (tracing_files == nullptr) {
390 tracing_files = xbt_dict_new_homogeneous(nullptr);
391 //generate unique run id with time
392 prefix = xbt_os_time();
395 if (!xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || temp == nullptr) {
396 char *folder_name = bprintf("%s_files", TRACE_get_filename());
397 char *filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
401 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
403 temp = fopen(filename, "w");
404 xbt_assert(temp, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
405 fprintf(tracing_file, "%s\n", filename);
407 xbt_free(folder_name);
411 xbt_dict_set(tracing_files, container->name, (void *) temp, nullptr);
417 DestroyContainerEvent::DestroyContainerEvent (container_t container)
419 this->event_type = PAJE_DestroyContainer;
420 this->timestamp = SIMIX_get_clock();
421 this->container = container;
423 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
428 void DestroyContainerEvent::print() {
429 if (instr_fmt_type == instr_fmt_paje) {
430 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
431 stream << std::fixed << std::setprecision(TRACE_precision());
432 stream << (int)this->event_type;
433 print_timestamp(this);
434 stream << " " << container->type->id
435 << " " << container->id;
438 } else if (instr_fmt_type == instr_fmt_TI) {
439 if (!xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file")|| xbt_dict_length(tracing_files) == 1) {
440 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
443 xbt_dict_remove(tracing_files, container->name);
449 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
451 this->event_type = PAJE_SetVariable;
452 this->timestamp = timestamp;
454 this->container = container;
457 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
459 insert_into_buffer (this);
462 void SetVariableEvent::print() {
463 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
464 stream << std::fixed << std::setprecision(TRACE_precision());
465 stream << (int)this->event_type;
466 print_timestamp(this);
467 stream << " " << type->id
468 << " " << container->id
473 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, type_t type, double value)
475 this->event_type = PAJE_AddVariable;
476 this->timestamp = timestamp;
478 this->container = container;
481 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
483 insert_into_buffer (this);
486 void AddVariableEvent::print() {
487 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
488 stream << std::fixed << std::setprecision(TRACE_precision());
489 stream << (int)this->event_type;
490 print_timestamp(this);
491 stream << " " << type->id
492 << " " << container->id
497 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, type_t type, double value)
499 this->event_type = PAJE_SubVariable;
500 this->timestamp = timestamp;
502 this->container = container;
505 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
507 insert_into_buffer (this);
510 void SubVariableEvent::print() {
511 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
512 stream << std::fixed << std::setprecision(TRACE_precision());
513 stream << (int)this->event_type;
514 print_timestamp(this);
515 stream << " " << type->id
516 << " " << container->id
521 SetStateEvent::SetStateEvent (double timestamp, container_t container, type_t type, val_t value)
523 this->event_type = PAJE_SetState;
524 this->timestamp = timestamp;
526 this->container = container;
530 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
531 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
532 filename = loc->filename;
533 linenumber = loc->linenumber;
537 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
539 insert_into_buffer (this);
542 void SetStateEvent::print() {
543 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
544 stream << std::fixed << std::setprecision(TRACE_precision());
545 stream << (int)this->event_type;
546 print_timestamp(this);
547 stream << " " << type->id
548 << " " << container->id;
549 stream << " " <<value->id;
551 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
552 stream << " \"" << filename
553 << "\" " << linenumber;
559 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value, void* extra)
561 this->event_type = PAJE_PushState;
562 this->timestamp = timestamp;
564 this->container = container;
566 this->extra_ = extra;
569 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
570 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
571 filename = loc->filename;
572 linenumber = loc->linenumber;
576 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
578 insert_into_buffer (this);
581 PushStateEvent::PushStateEvent (double timestamp, container_t container, type_t type, val_t value)
582 : PushStateEvent(timestamp, container, type, value, nullptr)
584 void PushStateEvent::print() {
585 if (instr_fmt_type == instr_fmt_paje) {
586 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
587 stream << std::fixed << std::setprecision(TRACE_precision());
588 stream << (int)this->event_type;
589 print_timestamp(this);
590 stream << " " << type->id
591 << " " << container->id;
592 stream << " " <<value->id;
594 if (TRACE_display_sizes()) {
596 if (extra_ != nullptr) {
597 stream << static_cast<instr_extra_data>(extra_)->send_size;
604 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
605 stream << " \"" << filename
606 << "\" " << linenumber;
611 if (extra_ != nullptr) {
612 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
613 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
614 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
615 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
618 } else if (instr_fmt_type == instr_fmt_TI) {
619 if (extra_ == nullptr)
621 instr_extra_data extra = (instr_extra_data)extra_;
623 char *process_id = nullptr;
624 //FIXME: dirty extract "rank-" from the name, as we want the bare process id here
625 if (strstr(container->name, "rank-") == nullptr)
626 process_id = xbt_strdup(container->name);
628 process_id = xbt_strdup(container->name + 5);
630 FILE* trace_file = (FILE* )xbt_dict_get(tracing_files, container->name);
632 switch (extra->type) {
634 fprintf(trace_file, "%s init\n", process_id);
636 case TRACING_FINALIZE:
637 fprintf(trace_file, "%s finalize\n", process_id);
640 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
643 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
646 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
649 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
652 fprintf(trace_file, "%s test\n", process_id);
655 fprintf(trace_file, "%s wait\n", process_id);
657 case TRACING_WAITALL:
658 fprintf(trace_file, "%s waitAll\n", process_id);
660 case TRACING_BARRIER:
661 fprintf(trace_file, "%s barrier\n", process_id);
663 case TRACING_BCAST: // rank bcast size (root) (datatype)
664 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
665 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
666 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
667 fprintf(trace_file, "\n");
669 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
670 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
671 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
672 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
673 fprintf(trace_file, "\n");
675 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
676 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size, extra->datatype1);
678 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
679 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->datatype1,
682 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
683 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
684 for (int i = 0; i < extra->num_processes; i++)
685 fprintf(trace_file, "%d ", extra->sendcounts[i]);
686 fprintf(trace_file, "%d ", extra->recv_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_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
692 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
693 extra->datatype1, extra->datatype2);
695 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
696 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
697 for (int i = 0; i < extra->num_processes; i++)
698 fprintf(trace_file, "%d ", extra->recvcounts[i]);
699 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
701 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
702 fprintf(trace_file, "%s reduceScatter ", process_id);
703 for (int i = 0; i < extra->num_processes; i++)
704 fprintf(trace_file, "%d ", extra->recvcounts[i]);
705 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
707 case TRACING_COMPUTING:
708 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
710 case TRACING_SLEEPING:
711 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
713 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
714 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
715 for (int i = 0; i < extra->num_processes; i++)
716 fprintf(trace_file, "%d ", extra->recvcounts[i]);
717 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
719 case TRACING_WAITANY:
720 case TRACING_SENDRECV:
721 case TRACING_SCATTER:
722 case TRACING_SCATTERV:
723 case TRACING_ALLGATHER:
726 case TRACING_COMM_SIZE:
727 case TRACING_COMM_SPLIT:
728 case TRACING_COMM_DUP:
732 XBT_WARN ("Call from %s impossible to translate into replay command : Not implemented (yet)",
737 if (extra->recvcounts != nullptr)
738 xbt_free(extra->recvcounts);
739 if (extra->sendcounts != nullptr)
740 xbt_free(extra->sendcounts);
741 xbt_free(process_id);
750 PopStateEvent::PopStateEvent (double timestamp, container_t container, type_t type)
752 this->event_type = PAJE_PopState;
753 this->timestamp = timestamp;
755 this->container = container;
757 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
759 insert_into_buffer (this);
762 void PopStateEvent::print() {
763 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
764 stream << std::fixed << std::setprecision(TRACE_precision());
765 stream << (int)this->event_type;
766 print_timestamp(this);
767 stream << " " << type->id
768 << " " << container->id;
772 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_t type)
774 this->event_type = PAJE_ResetState;
775 this->timestamp = timestamp;
777 this->container = container;
779 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
781 insert_into_buffer (this);
784 void ResetStateEvent::print() {
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
790 << " " << container->id;
794 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
795 type_t type, container_t sourceContainer, const char *value, const char *key)
796 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
799 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, type_t type, container_t sourceContainer,
800 const char *value, const char *key, int size)
802 event_type = PAJE_StartLink;
803 this->timestamp = timestamp;
805 this->container = container;
806 this->sourceContainer = sourceContainer;
807 this->value = xbt_strdup(value);
808 this->key = xbt_strdup(key);
811 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
812 (int)event_type, this->timestamp, this->value);
814 insert_into_buffer (this);
817 void StartLinkEvent::print() {
818 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
819 stream << std::fixed << std::setprecision(TRACE_precision());
820 stream << (int)this->event_type;
821 print_timestamp(this);
822 stream << " " <<type->id
823 << " " <<container->id
825 stream << " " << sourceContainer->id
828 if (TRACE_display_sizes()) {
829 stream << " " << size;
834 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type, container_t destContainer,
835 const char *value, const char *key)
837 this->event_type = PAJE_EndLink;
838 this->timestamp = timestamp;
840 this->container = container;
841 this->destContainer = destContainer;
842 this->value = xbt_strdup(value);
843 this->key = xbt_strdup(key);
845 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
847 insert_into_buffer (this);
851 void EndLinkEvent::print() {
852 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
853 stream << std::fixed << std::setprecision(TRACE_precision());
854 stream << (int)this->event_type;
855 print_timestamp(this);
856 stream << " " <<type->id
857 << " " <<container->id
859 stream << " " << destContainer->id
864 NewEvent::NewEvent (double timestamp, container_t container, type_t type, val_t value)
866 this->event_type = PAJE_NewEvent;
867 this->timestamp = timestamp;
869 this->container = container;
872 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
874 insert_into_buffer (this);
877 void NewEvent::print () {
878 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
879 stream << std::fixed << std::setprecision(TRACE_precision());
880 stream << (int)this->event_type;
881 print_timestamp(this);
882 stream << " " << type->id
883 << " " << container->id
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);