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<simgrid::instr::PajeEvent*> buffer;
31 void buffer_debug(std::vector<simgrid::instr::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<simgrid::instr::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<simgrid::instr::PajeEvent*>* buf);
92 void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf)
95 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
96 for (auto const& event : *buf) {
98 XBT_DEBUG("%p %s", event, stream.str().c_str());
105 static void print_row() {
107 fprintf(tracing_file, "%s", stream.str().c_str());
108 XBT_DEBUG("Dump %s", stream.str().c_str());
113 static void print_timestamp(simgrid::instr::PajeEvent* event)
116 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
117 if (event->timestamp_ < 1e-12)
120 stream << event->timestamp_;
123 /* internal do the instrumentation module */
124 static void insert_into_buffer(simgrid::instr::PajeEvent* tbi)
126 if (TRACE_buffer() == 0){
131 buffer_debug(&buffer);
133 XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%zu)", __FUNCTION__, (int)tbi->eventType_,
134 tbi->timestamp_, buffer.size());
135 std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
136 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
137 simgrid::instr::PajeEvent* e1 = *i;
138 XBT_DEBUG("compare to %p is of type %d; timestamp:%f", e1, (int)e1->eventType_, e1->timestamp_);
139 if (e1->timestamp_ <= tbi->timestamp_)
142 if (i == buffer.rend())
143 XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
144 else if (i == buffer.rbegin())
145 XBT_DEBUG("%s: inserted at end", __FUNCTION__);
147 XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
148 std::distance(buffer.rbegin(),i));
149 buffer.insert(i.base(), tbi);
151 buffer_debug(&buffer);
154 simgrid::instr::PajeEvent::~PajeEvent()
156 XBT_DEBUG("%s not implemented for %p: event_type=%d, timestamp=%f", __FUNCTION__, this, (int)eventType_, 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 LogContainerTypeDefinition(simgrid::instr::Type* type)
197 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineContainerType);
199 if (instr_fmt_type == instr_fmt_paje) {
200 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineContainerType,
201 TRACE_precision(), 0.);
202 stream << std::fixed << std::setprecision(TRACE_precision());
203 stream << simgrid::instr::PAJE_DefineContainerType;
204 stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_;
206 } else if (instr_fmt_type == instr_fmt_TI) {
214 void LogVariableTypeDefinition(simgrid::instr::Type* type)
217 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineVariableType);
220 if (instr_fmt_type == instr_fmt_paje) {
221 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineVariableType,
222 TRACE_precision(), 0.);
223 stream << std::fixed << std::setprecision(TRACE_precision());
224 stream << simgrid::instr::PAJE_DefineVariableType;
225 stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_;
227 stream << " \"" << type->color_ << "\"";
229 } else if (instr_fmt_type == instr_fmt_TI) {
236 void LogStateTypeDefinition(simgrid::instr::Type* type)
239 if (instr_fmt_type == instr_fmt_paje) {
240 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineStateType, TRACE_precision(),
242 stream << std::fixed << std::setprecision(TRACE_precision());
243 stream << simgrid::instr::PAJE_DefineStateType;
244 stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_;
246 } else if (instr_fmt_type == instr_fmt_TI) {
253 void LogDefineEventType(simgrid::instr::Type* type)
256 if (instr_fmt_type == instr_fmt_paje) {
257 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineEventType,
258 TRACE_precision(), 0.);
259 stream << std::fixed << std::setprecision(TRACE_precision());
260 stream << simgrid::instr::PAJE_DefineEventType;
261 stream << " " << type->id_ << " " << type->father_->id_ << " " << type->name_;
263 } else if (instr_fmt_type == instr_fmt_TI) {
270 void LogLinkTypeDefinition(simgrid::instr::Type* type, simgrid::instr::Type* source, simgrid::instr::Type* dest)
272 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineLinkType);
274 if (instr_fmt_type == instr_fmt_paje) {
275 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, simgrid::instr::PAJE_DefineLinkType, TRACE_precision(),
277 stream << std::fixed << std::setprecision(TRACE_precision());
278 stream << simgrid::instr::PAJE_DefineLinkType;
279 stream << " " << type->id_ << " " << type->father_->id_ << " " << source->id_ << " " << dest->id_ << " "
282 } else if (instr_fmt_type == instr_fmt_TI) {
289 void LogEntityValue(simgrid::instr::Value* val)
291 XBT_DEBUG("%s: event_type=%d", __FUNCTION__, simgrid::instr::PAJE_DefineEntityValue);
293 if (instr_fmt_type == instr_fmt_paje) {
294 stream << std::fixed << std::setprecision(TRACE_precision());
295 stream << simgrid::instr::PAJE_DefineEntityValue;
296 stream << " " << val->id_ << " " << val->father_->id_ << " " << val->name_;
298 stream << " \"" << val->color_ << "\"";
300 } else if (instr_fmt_type == instr_fmt_TI) {
308 void LogContainerCreation (container_t container)
310 double timestamp = SIMIX_get_clock();
312 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, simgrid::instr::PAJE_CreateContainer, timestamp);
314 if (instr_fmt_type == instr_fmt_paje) {
315 stream << std::fixed << std::setprecision(TRACE_precision());
316 stream << simgrid::instr::PAJE_CreateContainer;
318 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
319 if (timestamp < 1e-12)
323 stream << " " << container->id_ << " " << container->type_->id_ << " " << container->father_->id_ << " \""
324 << container->name_ << "\"";
327 } else if (instr_fmt_type == instr_fmt_TI) {
328 // if we are in the mode with only one file
329 static FILE* ti_unique_file = nullptr;
331 if (tracing_files == nullptr) {
332 tracing_files = xbt_dict_new_homogeneous(nullptr);
333 // generate unique run id with time
334 prefix = xbt_os_time();
337 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
338 char* folder_name = bprintf("%s_files", TRACE_get_filename());
339 char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, container->name_);
343 mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
345 ti_unique_file = fopen(filename, "w");
346 xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
347 fprintf(tracing_file, "%s\n", filename);
349 xbt_free(folder_name);
353 xbt_dict_set(tracing_files, container->name_, (void*)ti_unique_file, nullptr);
359 void LogContainerDestruction(container_t container)
361 double timestamp = SIMIX_get_clock();
363 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, simgrid::instr::PAJE_DestroyContainer, timestamp);
365 if (instr_fmt_type == instr_fmt_paje) {
366 stream << std::fixed << std::setprecision(TRACE_precision());
367 stream << simgrid::instr::PAJE_DestroyContainer;
369 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
370 if (timestamp < 1e-12)
374 stream << " " << container->type_->id_ << " " << container->id_;
376 } else if (instr_fmt_type == instr_fmt_TI) {
377 if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
378 FILE* f = (FILE*)xbt_dict_get_or_null(tracing_files, container->name_);
381 xbt_dict_remove(tracing_files, container->name_);
387 simgrid::instr::SetVariableEvent::SetVariableEvent(double timestamp, container_t container, Type* type, double value)
389 this->eventType_ = PAJE_SetVariable;
390 this->timestamp_ = timestamp;
392 this->container = container;
395 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
397 insert_into_buffer (this);
400 void simgrid::instr::SetVariableEvent::print()
402 if (instr_fmt_type == instr_fmt_paje) {
403 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
404 stream << std::fixed << std::setprecision(TRACE_precision());
405 stream << (int)this->eventType_;
406 print_timestamp(this);
407 stream << " " << type->id_ << " " << container->id_ << " " << value;
409 } else if (instr_fmt_type == instr_fmt_TI) {
416 simgrid::instr::AddVariableEvent::AddVariableEvent(double timestamp, container_t container, simgrid::instr::Type* type,
419 this->eventType_ = PAJE_AddVariable;
420 this->timestamp_ = timestamp;
422 this->container = container;
425 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
427 insert_into_buffer (this);
430 void simgrid::instr::AddVariableEvent::print()
432 if (instr_fmt_type == instr_fmt_paje) {
433 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
434 stream << std::fixed << std::setprecision(TRACE_precision());
435 stream << (int)this->eventType_;
436 print_timestamp(this);
437 stream << " " << type->id_ << " " << container->id_ << " " << value;
439 } else if (instr_fmt_type == instr_fmt_TI) {
446 simgrid::instr::SubVariableEvent::SubVariableEvent(double timestamp, container_t container, Type* type, double value)
448 this->eventType_ = PAJE_SubVariable;
449 this->timestamp_ = timestamp;
451 this->container = container;
454 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
456 insert_into_buffer (this);
459 void simgrid::instr::SubVariableEvent::print()
461 if (instr_fmt_type == instr_fmt_paje) {
462 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
463 stream << std::fixed << std::setprecision(TRACE_precision());
464 stream << (int)this->eventType_;
465 print_timestamp(this);
466 stream << " " << type->id_ << " " << container->id_ << " " << value;
468 } else if (instr_fmt_type == instr_fmt_TI) {
475 simgrid::instr::SetStateEvent::SetStateEvent(double timestamp, container_t container, Type* type, Value* val)
477 this->eventType_ = PAJE_SetState;
478 this->timestamp_ = timestamp;
480 this->container = container;
484 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
485 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
486 filename = loc->filename;
487 linenumber = loc->linenumber;
491 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
493 insert_into_buffer (this);
496 void simgrid::instr::SetStateEvent::print()
498 if (instr_fmt_type == instr_fmt_paje) {
499 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
500 stream << std::fixed << std::setprecision(TRACE_precision());
501 stream << (int)this->eventType_;
502 print_timestamp(this);
503 stream << " " << type->id_ << " " << container->id_;
504 stream << " " << val->id_;
506 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
507 stream << " \"" << filename << "\" " << linenumber;
511 } else if (instr_fmt_type == instr_fmt_TI) {
518 simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* val,
521 this->eventType_ = PAJE_PushState;
522 this->timestamp_ = timestamp;
524 this->container = container;
526 this->extra_ = extra;
529 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
530 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
531 filename = loc->filename;
532 linenumber = loc->linenumber;
536 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
538 insert_into_buffer (this);
541 simgrid::instr::PushStateEvent::PushStateEvent(double timestamp, container_t container, Type* type, Value* val)
542 : PushStateEvent(timestamp, container, type, val, nullptr)
544 void simgrid::instr::PushStateEvent::print()
546 if (instr_fmt_type == instr_fmt_paje) {
547 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
548 stream << std::fixed << std::setprecision(TRACE_precision());
549 stream << (int)this->eventType_;
550 print_timestamp(this);
551 stream << " " << type->id_ << " " << container->id_;
552 stream << " " << val->id_;
554 if (TRACE_display_sizes()) {
556 if (extra_ != nullptr) {
557 stream << static_cast<instr_extra_data>(extra_)->send_size;
563 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
564 stream << " \"" << filename << "\" " << linenumber;
569 if (extra_ != nullptr) {
570 if (static_cast<instr_extra_data>(extra_)->sendcounts != nullptr)
571 xbt_free(static_cast<instr_extra_data>(extra_)->sendcounts);
572 if (static_cast<instr_extra_data>(extra_)->recvcounts != nullptr)
573 xbt_free(static_cast<instr_extra_data>(extra_)->recvcounts);
576 } else if (instr_fmt_type == instr_fmt_TI) {
577 if (extra_ == nullptr)
579 instr_extra_data extra = (instr_extra_data)extra_;
581 char* process_id = nullptr;
582 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
583 if (strstr(container->name_, "rank-") == nullptr)
584 process_id = xbt_strdup(container->name_);
586 process_id = xbt_strdup(container->name_ + 5);
588 FILE* trace_file = (FILE*)xbt_dict_get(tracing_files, container->name_);
590 switch (extra->type) {
592 fprintf(trace_file, "%s init\n", process_id);
594 case TRACING_FINALIZE:
595 fprintf(trace_file, "%s finalize\n", process_id);
598 fprintf(trace_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
601 fprintf(trace_file, "%s Isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
604 fprintf(trace_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
607 fprintf(trace_file, "%s Irecv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
610 fprintf(trace_file, "%s test\n", process_id);
613 fprintf(trace_file, "%s wait\n", process_id);
615 case TRACING_WAITALL:
616 fprintf(trace_file, "%s waitAll\n", process_id);
618 case TRACING_BARRIER:
619 fprintf(trace_file, "%s barrier\n", process_id);
621 case TRACING_BCAST: // rank bcast size (root) (datatype)
622 fprintf(trace_file, "%s bcast %d ", process_id, extra->send_size);
623 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
624 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
625 fprintf(trace_file, "\n");
627 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
628 fprintf(trace_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
629 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
630 fprintf(trace_file, "%d %s", extra->root, extra->datatype1);
631 fprintf(trace_file, "\n");
633 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
634 fprintf(trace_file, "%s allReduce %d %f %s\n", process_id, extra->send_size, extra->comp_size,
637 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
638 fprintf(trace_file, "%s allToAll %d %d %s %s\n", process_id, extra->send_size, extra->recv_size,
639 extra->datatype1, extra->datatype2);
641 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
642 fprintf(trace_file, "%s allToAllV %d ", process_id, extra->send_size);
643 for (int i = 0; i < extra->num_processes; i++)
644 fprintf(trace_file, "%d ", extra->sendcounts[i]);
645 fprintf(trace_file, "%d ", extra->recv_size);
646 for (int i = 0; i < extra->num_processes; i++)
647 fprintf(trace_file, "%d ", extra->recvcounts[i]);
648 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
650 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
651 fprintf(trace_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root,
652 extra->datatype1, extra->datatype2);
654 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
655 fprintf(trace_file, "%s allGatherV %d ", process_id, extra->send_size);
656 for (int i = 0; i < extra->num_processes; i++)
657 fprintf(trace_file, "%d ", extra->recvcounts[i]);
658 fprintf(trace_file, "%s %s \n", extra->datatype1, extra->datatype2);
660 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
661 fprintf(trace_file, "%s reduceScatter ", process_id);
662 for (int i = 0; i < extra->num_processes; i++)
663 fprintf(trace_file, "%d ", extra->recvcounts[i]);
664 fprintf(trace_file, "%f %s\n", extra->comp_size, extra->datatype1);
666 case TRACING_COMPUTING:
667 fprintf(trace_file, "%s compute %f\n", process_id, extra->comp_size);
669 case TRACING_SLEEPING:
670 fprintf(trace_file, "%s sleep %f\n", process_id, extra->sleep_duration);
672 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
673 fprintf(trace_file, "%s gatherV %d ", process_id, extra->send_size);
674 for (int i = 0; i < extra->num_processes; i++)
675 fprintf(trace_file, "%d ", extra->recvcounts[i]);
676 fprintf(trace_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
678 case TRACING_ALLGATHER: // rank allgather sendcount recvcounts (sendtype) (recvtype)
679 fprintf(trace_file, "%s allGather %d %d %s %s", process_id, extra->send_size, extra->recv_size, extra->datatype1, extra->datatype2);
681 case TRACING_WAITANY:
682 case TRACING_SENDRECV:
683 case TRACING_SCATTER:
684 case TRACING_SCATTERV:
687 case TRACING_COMM_SIZE:
688 case TRACING_COMM_SPLIT:
689 case TRACING_COMM_DUP:
693 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", val->name_);
697 if (extra->recvcounts != nullptr)
698 xbt_free(extra->recvcounts);
699 if (extra->sendcounts != nullptr)
700 xbt_free(extra->sendcounts);
701 xbt_free(process_id);
709 simgrid::instr::PopStateEvent::PopStateEvent(double timestamp, container_t container, Type* type)
711 this->eventType_ = PAJE_PopState;
712 this->timestamp_ = timestamp;
714 this->container = container;
716 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
718 insert_into_buffer (this);
721 void simgrid::instr::PopStateEvent::print()
723 if (instr_fmt_type == instr_fmt_paje) {
724 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
725 stream << std::fixed << std::setprecision(TRACE_precision());
726 stream << (int)this->eventType_;
727 print_timestamp(this);
728 stream << " " << type->id_ << " " << container->id_;
730 } else if (instr_fmt_type == instr_fmt_TI) {
737 simgrid::instr::ResetStateEvent::ResetStateEvent(double timestamp, container_t container, Type* type)
739 this->eventType_ = PAJE_ResetState;
740 this->timestamp_ = timestamp;
742 this->container = container;
744 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
746 insert_into_buffer (this);
750 void simgrid::instr::ResetStateEvent::print()
752 if (instr_fmt_type == instr_fmt_paje) {
753 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
754 stream << std::fixed << std::setprecision(TRACE_precision());
755 stream << (int)this->eventType_;
756 print_timestamp(this);
757 stream << " " << type->id_ << " " << container->id_;
759 } else if (instr_fmt_type == instr_fmt_TI) {
766 simgrid::instr::StartLinkEvent::~StartLinkEvent()
771 simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type,
772 container_t sourceContainer, const char* value, const char* key)
773 : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
776 simgrid::instr::StartLinkEvent::StartLinkEvent(double timestamp, container_t container, Type* type,
777 container_t sourceContainer, const char* value, const char* key,
779 : container_(container)
781 , sourceContainer_(sourceContainer)
782 , value_(xbt_strdup(value))
783 , key_(xbt_strdup(key))
786 eventType_ = PAJE_StartLink;
787 this->timestamp_ = timestamp;
789 XBT_DEBUG("%s: event_type=%d, timestamp=%f, value:%s", __FUNCTION__, (int)eventType_, this->timestamp_, this->value_);
791 insert_into_buffer (this);
794 void simgrid::instr::StartLinkEvent::print()
796 if (instr_fmt_type == instr_fmt_paje) {
797 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
798 stream << std::fixed << std::setprecision(TRACE_precision());
799 stream << (int)this->eventType_;
800 print_timestamp(this);
801 stream << " " << type_->id_ << " " << container_->id_ << " " << value_;
802 stream << " " << sourceContainer_->id_ << " " << key_;
804 if (TRACE_display_sizes()) {
805 stream << " " << size_;
808 } else if (instr_fmt_type == instr_fmt_TI) {
815 simgrid::instr::EndLinkEvent::EndLinkEvent(double timestamp, container_t container, Type* type,
816 container_t destContainer, const char* value, const char* key)
818 this->eventType_ = PAJE_EndLink;
819 this->timestamp_ = timestamp;
821 this->container = container;
822 this->destContainer = destContainer;
823 this->value = xbt_strdup(value);
824 this->key = xbt_strdup(key);
826 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
828 insert_into_buffer (this);
831 simgrid::instr::EndLinkEvent::~EndLinkEvent()
836 void simgrid::instr::EndLinkEvent::print()
838 if (instr_fmt_type == instr_fmt_paje) {
839 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
840 stream << std::fixed << std::setprecision(TRACE_precision());
841 stream << (int)this->eventType_;
842 print_timestamp(this);
843 stream << " " << type->id_ << " " << container->id_ << " " << value;
844 stream << " " << destContainer->id_ << " " << key;
846 } else if (instr_fmt_type == instr_fmt_TI) {
853 simgrid::instr::NewEvent::NewEvent(double timestamp, container_t container, Type* type, Value* val)
855 this->eventType_ = PAJE_NewEvent;
856 this->timestamp_ = timestamp;
858 this->container = container;
861 XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)eventType_, this->timestamp_);
863 insert_into_buffer (this);
866 void simgrid::instr::NewEvent::print()
868 if (instr_fmt_type == instr_fmt_paje) {
869 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)eventType_, TRACE_precision(), timestamp_);
870 stream << std::fixed << std::setprecision(TRACE_precision());
871 stream << (int)this->eventType_;
872 print_timestamp(this);
873 stream << " " << type->id_ << " " << container->id_ << " " << val->id_;
875 } else if (instr_fmt_type == instr_fmt_TI) {
883 void TRACE_TI_start()
885 char *filename = TRACE_get_filename();
886 tracing_file = fopen(filename, "w");
887 if (tracing_file == nullptr)
888 THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
890 XBT_DEBUG("Filename %s is open for writing", filename);
892 /* output one line comment */
893 dump_comment(TRACE_get_comment());
895 /* output comment file */
896 dump_comment_file(TRACE_get_comment_file());
901 xbt_dict_free(&tracing_files);
902 fclose(tracing_file);
903 char *filename = TRACE_get_filename();
904 XBT_DEBUG("Filename %s is closed", filename);