1 /* Copyright (c) 2012-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/instr/instr_private.hpp"
7 #include "src/instr/instr_smpi.hpp"
8 #include "src/smpi/include/private.hpp"
9 #include "src/surf/surf_interface.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
12 extern FILE* tracing_file;
13 std::map<container_t, FILE*> tracing_files; // TI specific
18 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
19 : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
21 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
22 if (trace_format == simgrid::instr::TraceFormat::Paje) {
23 stream_ << std::fixed << std::setprecision(TRACE_precision());
24 stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
29 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
30 : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
33 if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
34 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
35 filename = loc->filename;
36 linenumber = loc->linenumber;
41 void NewEvent::print()
43 if (trace_format != simgrid::instr::TraceFormat::Paje)
46 stream_ << " " << value->getId();
48 XBT_DEBUG("Dump %s", stream_.str().c_str());
49 fprintf(tracing_file, "%s\n", stream_.str().c_str());
52 void LinkEvent::print()
54 if (trace_format != simgrid::instr::TraceFormat::Paje)
57 stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
59 if (TRACE_display_sizes())
60 stream_ << " " << size_;
62 XBT_DEBUG("Dump %s", stream_.str().c_str());
63 fprintf(tracing_file, "%s\n", stream_.str().c_str());
66 void VariableEvent::print()
68 if (trace_format != simgrid::instr::TraceFormat::Paje)
71 stream_ << " " << value;
73 XBT_DEBUG("Dump %s", stream_.str().c_str());
74 fprintf(tracing_file, "%s\n", stream_.str().c_str());
77 void StateEvent::print()
79 if (trace_format == simgrid::instr::TraceFormat::Paje) {
81 if (value != nullptr) // PAJE_PopState Event does not need to have a value
82 stream_ << " " << value->getId();
84 if (TRACE_display_sizes())
85 stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
88 if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
89 stream_ << " \"" << filename << "\" " << linenumber;
92 XBT_DEBUG("Dump %s", stream_.str().c_str());
93 fprintf(tracing_file, "%s\n", stream_.str().c_str());
94 } else if (trace_format == simgrid::instr::TraceFormat::Ti) {
95 if (extra_ == nullptr)
98 /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
100 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
101 if (getContainer()->get_name().find("rank-") != 0)
102 stream_ << getContainer()->get_name() << " " << extra_->print();
104 /* Subtract -1 because this is the process id and we transform it to the rank id */
105 stream_ << stoi(getContainer()->get_name().erase(0, 5)) - 1 << " " << extra_->print();
107 fprintf(tracing_files.at(getContainer()), "%s\n", stream_.str().c_str());