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 const& event : buffer) {
77 std::vector<PajeEvent*>::iterator i = buffer.begin();
78 for (auto const& 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 const& event : *buf) {
97 XBT_DEBUG("%p %s", event, stream.str().c_str());
104 static void print_row() {
106 fprintf(tracing_file, "%s", stream.str().c_str());
107 XBT_DEBUG("Dump %s", stream.str().c_str());
112 static void print_timestamp(PajeEvent* event) {
114 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
115 if (event->timestamp < 1e-12)
118 stream << event->timestamp;
121 /* internal do the instrumentation module */
122 static void insert_into_buffer (PajeEvent* tbi)
124 if (TRACE_buffer() == 0){
129 buffer_debug(&buffer);
131 XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)",
132 __FUNCTION__, (int)tbi->event_type, tbi->timestamp, buffer.size());
133 std::vector<PajeEvent*>::reverse_iterator i;
134 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
136 XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1,
137 (int)e1->event_type, e1->timestamp);
138 if (e1->timestamp <= tbi->timestamp)
141 if (i == buffer.rend())
142 XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
143 else if (i == buffer.rbegin())
144 XBT_DEBUG("%s: inserted at end", __FUNCTION__);
146 XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
147 std::distance(buffer.rbegin(),i));
148 buffer.insert(i.base(), tbi);
150 buffer_debug(&buffer);
153 PajeEvent:: ~PajeEvent()
155 XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__,
156 this, (int)event_type, timestamp);
159 void TRACE_paje_start() {
160 char *filename = TRACE_get_filename();
161 tracing_file = fopen(filename, "w");
162 if (tracing_file == nullptr){
163 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
166 XBT_DEBUG("Filename %s is open for writing", filename);
168 /* output generator version */
169 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
170 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
171 fprintf (tracing_file, "#[");
174 xbt_dynar_foreach (xbt_cmdline, cpt, str){
175 fprintf(tracing_file, "%s ",str);
177 fprintf (tracing_file, "]\n");
179 /* output one line comment */
180 dump_comment (TRACE_get_comment());
182 /* output comment file */
183 dump_comment_file (TRACE_get_comment_file());
186 TRACE_header(TRACE_basic(),TRACE_display_sizes());
189 void TRACE_paje_end() {
190 fclose(tracing_file);
191 char *filename = TRACE_get_filename();
192 XBT_DEBUG("Filename %s is closed", filename);
195 void DefineContainerEvent(Type* type)
197 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineContainerType);
199 if (instr_fmt_type == instr_fmt_paje) {
200 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineContainerType, TRACE_precision(), 0.);
201 stream << std::fixed << std::setprecision(TRACE_precision());
202 stream << PAJE_DefineContainerType;
203 stream << " " << type->id << " " << type->father->id << " " << type->name;
205 } else if (instr_fmt_type == instr_fmt_TI) {
213 void LogVariableTypeDefinition(Type* type)
216 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineVariableType);
219 if (instr_fmt_type == instr_fmt_paje) {
220 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineVariableType, TRACE_precision(), 0.);
221 stream << std::fixed << std::setprecision(TRACE_precision());
222 stream << PAJE_DefineVariableType;
223 stream << " " << type->id << " " << type->father->id << " " << type->name;
225 stream << " \"" << type->color << "\"";
227 } else if (instr_fmt_type == instr_fmt_TI) {
234 void LogStateTypeDefinition(Type* type)
237 if (instr_fmt_type == instr_fmt_paje) {
238 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineStateType, TRACE_precision(), 0.);
239 stream << std::fixed << std::setprecision(TRACE_precision());
240 stream << PAJE_DefineStateType;
241 stream << " " << type->id << " " << type->father->id << " " << type->name;
243 } else if (instr_fmt_type == instr_fmt_TI) {
250 void LogDefineEventType(Type* type)
253 if (instr_fmt_type == instr_fmt_paje) {
254 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineEventType, TRACE_precision(), 0.);
255 stream << std::fixed << std::setprecision(TRACE_precision());
256 stream << PAJE_DefineEventType;
257 stream << " " << type->id << " " << type->father->id << " " << type->name;
259 } else if (instr_fmt_type == instr_fmt_TI) {
266 void LogLinkTypeDefinition(Type* type, Type* source, Type* dest)
268 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineLinkType);
270 if (instr_fmt_type == instr_fmt_paje) {
271 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, PAJE_DefineLinkType, TRACE_precision(), 0.);
272 stream << std::fixed << std::setprecision(TRACE_precision());
273 stream << PAJE_DefineLinkType;
274 stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
276 } else if (instr_fmt_type == instr_fmt_TI) {
283 void LogEntityValue(Value* val)
285 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, PAJE_DefineEntityValue);
287 if (instr_fmt_type == instr_fmt_paje) {
288 stream << std::fixed << std::setprecision(TRACE_precision());
289 stream << PAJE_DefineEntityValue;
290 stream << " " << val->id << " " << val->father->id << " " << val->name;
292 stream << " \"" << val->color << "\"";
294 } else if (instr_fmt_type == instr_fmt_TI) {
302 void LogContainerCreation (container_t container)
304 double timestamp = SIMIX_get_clock();
306 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_CreateContainer,timestamp);
308 if (instr_fmt_type == instr_fmt_paje) {
309 stream << std::fixed << std::setprecision(TRACE_precision());
310 stream << PAJE_CreateContainer;
312 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
313 if (timestamp < 1e-12)
317 stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
318 << container->name << "\"";
321 } else if (instr_fmt_type == instr_fmt_TI) {
322 // if we are in the mode with only one file
323 static FILE* ti_unique_file = nullptr;
325 if (tracing_files == nullptr) {
326 tracing_files = xbt_dict_new_homogeneous(nullptr);
327 // generate unique run id with time
328 prefix = xbt_os_time();
331 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
332 char* folder_name = bprintf("%s_files", TRACE_get_filename());
333 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name);
337 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
339 ti_unique_file = fopen(filename, "w");
340 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
341 fprintf(tracing_file, "%s\n", filename);
343 xbt_free(folder_name);
347 xbt_dict_set(tracing_files, container->name, (void*)ti_unique_file, nullptr);
353 void LogContainerDestruction(container_t container)
355 double timestamp = SIMIX_get_clock();
357 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, PAJE_DestroyContainer, timestamp);
359 if (instr_fmt_type == instr_fmt_paje) {
360 stream << std::fixed << std::setprecision(TRACE_precision());
361 stream << PAJE_DestroyContainer;
363 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
364 if (timestamp < 1e-12)
368 stream << " " << container->type->id << " " << container->id;
370 } else if (instr_fmt_type == instr_fmt_TI) {
371 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
372 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name);
375 xbt_dict_remove(tracing_files, container->name);
382 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, Type* type, double value)
384 this->event_type = PAJE_SetVariable;
385 this->timestamp = timestamp;
387 this->container = container;
390 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
392 insert_into_buffer (this);
395 void SetVariableEvent::print() {
396 if (instr_fmt_type == instr_fmt_paje) {
397 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
398 stream << std::fixed << std::setprecision(TRACE_precision());
399 stream << (int)this->event_type;
400 print_timestamp(this);
401 stream << " " << type->id << " " << container->id << " " << value;
403 } else if (instr_fmt_type == instr_fmt_TI) {
410 AddVariableEvent::AddVariableEvent (double timestamp, container_t container, Type* type, double value)
412 this->event_type = PAJE_AddVariable;
413 this->timestamp = timestamp;
415 this->container = container;
418 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
420 insert_into_buffer (this);
423 void AddVariableEvent::print() {
424 if (instr_fmt_type == instr_fmt_paje) {
425 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
426 stream << std::fixed << std::setprecision(TRACE_precision());
427 stream << (int)this->event_type;
428 print_timestamp(this);
429 stream << " " << type->id << " " << container->id << " " << value;
431 } else if (instr_fmt_type == instr_fmt_TI) {
438 SubVariableEvent::SubVariableEvent (double timestamp, container_t container, Type* type, double value)
440 this->event_type = PAJE_SubVariable;
441 this->timestamp = timestamp;
443 this->container = container;
446 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
448 insert_into_buffer (this);
451 void SubVariableEvent::print() {
452 if (instr_fmt_type == instr_fmt_paje) {
453 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
454 stream << std::fixed << std::setprecision(TRACE_precision());
455 stream << (int)this->event_type;
456 print_timestamp(this);
457 stream << " " << type->id << " " << container->id << " " << value;
459 } else if (instr_fmt_type == instr_fmt_TI) {
466 SetStateEvent::SetStateEvent(double timestamp, container_t container, Type* type, Value* val)
468 this->event_type = PAJE_SetState;
469 this->timestamp = timestamp;
471 this->container = container;
475 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
476 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
477 filename = loc->filename;
478 linenumber = loc->linenumber;
482 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
484 insert_into_buffer (this);
487 void SetStateEvent::print() {
488 if (instr_fmt_type == instr_fmt_paje) {
489 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
490 stream << std::fixed << std::setprecision(TRACE_precision());
491 stream << (int)this->event_type;
492 print_timestamp(this);
493 stream << " " << type->id << " " << container->id;
494 stream << " " << val->id;
496 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
497 stream << " \"" << filename << "\" " << linenumber;
501 } else if (instr_fmt_type == instr_fmt_TI) {
508 PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* val, void* extra)
510 this->event_type = PAJE_PushState;
511 this->timestamp = timestamp;
513 this->container = container;
515 this->extra_ = extra;
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 PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* val)
531 : PushStateEvent(timestamp, container, type, val, nullptr)
533 void PushStateEvent::print() {
534 if (instr_fmt_type == instr_fmt_paje) {
535 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
536 stream << std::fixed << std::setprecision(TRACE_precision());
537 stream << (int)this->event_type;
538 print_timestamp(this);
539 stream << " " << type->id << " " << container->id;
540 stream << " " << val->id;
542 if (TRACE_display_sizes()) {
544 if (extra_ != nullptr) {
545 stream << static_cast<instr_extra_data>(extra_)->send_size;
551 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
552 stream << " \"" << filename << "\" " << linenumber;
557 if (extra_ != nullptr) {
558 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
559 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
560 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
561 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
564 } else if (instr_fmt_type == instr_fmt_TI) {
565 if (extra_ == nullptr)
567 instr_extra_data extra = (instr_extra_data)extra_;
569 char* process_id = nullptr;
570 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
571 if (strstr(container->name, "rank-") == nullptr)
572 process_id = xbt_strdup(container->name);
574 process_id = xbt_strdup(container->name + 5);
576 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name);
578 switch (extra->type) {
580 fprintf(trace_file, "%s init\n", process_id);
582 case TRACING_FINALIZE:
583 fprintf(trace_file, "%s finalize\n", process_id);
586 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
589 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
592 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
595 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
598 fprintf(trace_file, "%s test\n", process_id);
601 fprintf(trace_file, "%s wait\n", process_id);
603 case TRACING_WAITALL:
604 fprintf(trace_file, "%s waitAll\n", process_id);
606 case TRACING_BARRIER:
607 fprintf(trace_file, "%s barrier\n", process_id);
609 case TRACING_BCAST: // rank bcast size (root) (datatype)
610 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
611 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
612 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
613 fprintf(trace_file, "\n");
615 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
616 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
617 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
618 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
619 fprintf(trace_file, "\n");
621 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
622 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
625 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
626 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
627 extra->datatype1, extra->datatype2);
629 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
630 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
631 for (int i = 0; i < extra->num_processes; i++)
632 fprintf(trace_file, "%d ", extra->sendcounts[i]);
633 fprintf(trace_file, "%d ", extra->recv_size);
634 for (int i = 0; i < extra->num_processes; i++)
635 fprintf(trace_file, "%d ", extra->recvcounts[i]);
636 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
638 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
639 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
640 extra->datatype1, extra->datatype2);
642 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
643 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
644 for (int i = 0; i < extra->num_processes; i++)
645 fprintf(trace_file, "%d ", extra->recvcounts[i]);
646 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
648 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
649 fprintf(trace_file, "%s reduceScatter ", process_id);
650 for (int i = 0; i < extra->num_processes; i++)
651 fprintf(trace_file, "%d ", extra->recvcounts[i]);
652 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
654 case TRACING_COMPUTING:
655 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
657 case TRACING_SLEEPING:
658 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
660 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
661 fprintf(trace_file, "%s gatherV %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, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
666 case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
667 fprintf(trace_file, "%s allGather %d %d %s %s", process_id, extra->send_size, extra->recv_size, extra->datatype1, extra->datatype2);
669 case TRACING_WAITANY:
670 case TRACING_SENDRECV:
671 case TRACING_SCATTER:
672 case TRACING_SCATTERV:
675 case TRACING_COMM_SIZE:
676 case TRACING_COMM_SPLIT:
677 case TRACING_COMM_DUP:
681 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", val->name);
685 if (extra->recvcounts != nullptr)
686 xbt_free(extra->recvcounts);
687 if (extra->sendcounts != nullptr)
688 xbt_free(extra->sendcounts);
689 xbt_free(process_id);
698 PopStateEvent::PopStateEvent (double timestamp, container_t container, Type* type)
700 this->event_type = PAJE_PopState;
701 this->timestamp = timestamp;
703 this->container = container;
705 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
707 insert_into_buffer (this);
710 void PopStateEvent::print() {
711 if (instr_fmt_type == instr_fmt_paje) {
712 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
713 stream << std::fixed << std::setprecision(TRACE_precision());
714 stream << (int)this->event_type;
715 print_timestamp(this);
716 stream << " " << type->id << " " << container->id;
718 } else if (instr_fmt_type == instr_fmt_TI) {
725 ResetStateEvent::ResetStateEvent (double timestamp, container_t container, Type* type)
727 this->event_type = PAJE_ResetState;
728 this->timestamp = timestamp;
730 this->container = container;
732 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
734 insert_into_buffer (this);
738 void ResetStateEvent::print() {
739 if (instr_fmt_type == instr_fmt_paje) {
740 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
741 stream << std::fixed << std::setprecision(TRACE_precision());
742 stream << (int)this->event_type;
743 print_timestamp(this);
744 stream << " " << type->id << " " << container->id;
746 } else if (instr_fmt_type == instr_fmt_TI) {
753 StartLinkEvent::~StartLinkEvent()
758 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
759 Type* type, container_t sourceContainer, const char *value, const char *key)
760 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
763 StartLinkEvent::StartLinkEvent (double timestamp, container_t container, Type* type, container_t sourceContainer,
764 const char *value, const char *key, int size)
766 event_type = PAJE_StartLink;
767 this->timestamp = timestamp;
769 this->container = container;
770 this->sourceContainer = sourceContainer;
771 this->value = xbt_strdup(value);
772 this->key = xbt_strdup(key);
775 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__,
776 (int)event_type, this->timestamp, this->value);
778 insert_into_buffer (this);
781 void StartLinkEvent::print() {
782 if (instr_fmt_type == instr_fmt_paje) {
783 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
784 stream << std::fixed << std::setprecision(TRACE_precision());
785 stream << (int)this->event_type;
786 print_timestamp(this);
787 stream << " " << type->id << " " << container->id << " " << value;
788 stream << " " << sourceContainer->id << " " << key;
790 if (TRACE_display_sizes()) {
791 stream << " " << size;
794 } else if (instr_fmt_type == instr_fmt_TI) {
801 EndLinkEvent::EndLinkEvent (double timestamp, container_t container, Type* type, container_t destContainer,
802 const char *value, const char *key)
804 this->event_type = PAJE_EndLink;
805 this->timestamp = timestamp;
807 this->container = container;
808 this->destContainer = destContainer;
809 this->value = xbt_strdup(value);
810 this->key = xbt_strdup(key);
812 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
814 insert_into_buffer (this);
817 EndLinkEvent::~EndLinkEvent()
822 void EndLinkEvent::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 << " " << destContainer->id << " " << key;
831 } else if (instr_fmt_type == instr_fmt_TI) {
838 NewEvent::NewEvent(double timestamp, container_t container, Type* type, Value* val)
840 this->event_type = PAJE_NewEvent;
841 this->timestamp = timestamp;
843 this->container = container;
846 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
848 insert_into_buffer (this);
851 void NewEvent::print () {
852 if (instr_fmt_type == instr_fmt_paje) {
853 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
854 stream << std::fixed << std::setprecision(TRACE_precision());
855 stream << (int)this->event_type;
856 print_timestamp(this);
857 stream << " " << type->id << " " << container->id << " " << val->id;
859 } else if (instr_fmt_type == instr_fmt_TI) {
867 void TRACE_TI_start()
869 char *filename = TRACE_get_filename();
870 tracing_file = fopen(filename, "w");
871 if (tracing_file == nullptr)
872 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
874 XBT_DEBUG("Filename %s is open for writing", filename);
876 /* output one line comment */
877 dump_comment(TRACE_get_comment());
879 /* output comment file */
880 dump_comment_file(TRACE_get_comment_file());
885 xbt_dict_free(&tracing_files);
886 fclose(tracing_file);
887 char *filename = TRACE_get_filename();
888 XBT_DEBUG("Filename %s is closed", filename);