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 <xbt/config.hpp>
8 #include "src/instr/instr_private.hpp"
9 #include "src/instr/instr_smpi.hpp"
10 #include "src/smpi/include/private.hpp"
11 #include "src/surf/surf_interface.hpp"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
14 extern FILE* tracing_file;
15 std::map<container_t, FILE*> tracing_files; // TI specific
20 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
21 : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
23 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
24 if (trace_format == simgrid::instr::TraceFormat::Paje) {
25 stream_ << std::fixed << std::setprecision(TRACE_precision());
26 stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
31 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
32 : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
35 if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
36 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
37 filename = loc->filename;
38 linenumber = loc->linenumber;
43 void NewEvent::print()
45 if (trace_format != simgrid::instr::TraceFormat::Paje)
48 stream_ << " " << value->getId();
50 XBT_DEBUG("Dump %s", stream_.str().c_str());
51 fprintf(tracing_file, "%s\n", stream_.str().c_str());
54 void LinkEvent::print()
56 if (trace_format != simgrid::instr::TraceFormat::Paje)
59 stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
61 if (TRACE_display_sizes())
62 stream_ << " " << size_;
64 XBT_DEBUG("Dump %s", stream_.str().c_str());
65 fprintf(tracing_file, "%s\n", stream_.str().c_str());
68 void VariableEvent::print()
70 if (trace_format != simgrid::instr::TraceFormat::Paje)
73 stream_ << " " << value;
75 XBT_DEBUG("Dump %s", stream_.str().c_str());
76 fprintf(tracing_file, "%s\n", stream_.str().c_str());
79 void StateEvent::print()
81 if (trace_format == simgrid::instr::TraceFormat::Paje) {
83 if (value != nullptr) // PAJE_PopState Event does not need to have a value
84 stream_ << " " << value->getId();
86 if (TRACE_display_sizes())
87 stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
90 if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
91 stream_ << " \"" << filename << "\" " << linenumber;
94 XBT_DEBUG("Dump %s", stream_.str().c_str());
95 fprintf(tracing_file, "%s\n", stream_.str().c_str());
96 } else if (trace_format == simgrid::instr::TraceFormat::Ti) {
97 if (extra_ == nullptr)
100 /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
102 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
103 if (getContainer()->get_name().find("rank-") != 0)
104 stream_ << getContainer()->get_name() << " " << extra_->print();
106 /* Subtract -1 because this is the process id and we transform it to the rank id */
107 stream_ << stoi(getContainer()->get_name().erase(0, 5)) - 1 << " " << extra_->print();
109 fprintf(tracing_files.at(getContainer()), "%s\n", stream_.str().c_str());