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 std::ofstream tracing_file;
13 extern std::map<container_t, std::ofstream*> 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 void PajeEvent::print()
31 if (trace_format != simgrid::instr::TraceFormat::Paje)
34 XBT_DEBUG("Dump %s", stream_.str().c_str());
35 tracing_file << stream_.str() << std::endl;
38 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
39 : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
42 if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
43 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
44 filename = loc->filename;
45 linenumber = loc->linenumber;
50 void NewEvent::print()
52 if (trace_format != simgrid::instr::TraceFormat::Paje)
55 stream_ << " " << value->get_id();
57 XBT_DEBUG("Dump %s", stream_.str().c_str());
58 tracing_file << stream_.str() << std::endl;
61 void LinkEvent::print()
63 if (trace_format != simgrid::instr::TraceFormat::Paje)
66 stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
68 if (TRACE_display_sizes())
69 stream_ << " " << size_;
71 XBT_DEBUG("Dump %s", stream_.str().c_str());
72 tracing_file << stream_.str() << std::endl;
75 void VariableEvent::print()
77 if (trace_format != simgrid::instr::TraceFormat::Paje)
80 stream_ << " " << value_;
82 XBT_DEBUG("Dump %s", stream_.str().c_str());
83 tracing_file << stream_.str() << std::endl;
86 void StateEvent::print()
88 if (trace_format == simgrid::instr::TraceFormat::Paje) {
90 if (value != nullptr) // PAJE_PopState Event does not need to have a value
91 stream_ << " " << value->get_id();
93 if (TRACE_display_sizes())
94 stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
97 if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
98 stream_ << " \"" << filename << "\" " << linenumber;
101 XBT_DEBUG("Dump %s", stream_.str().c_str());
102 tracing_file << stream_.str() << std::endl;
103 } else if (trace_format == simgrid::instr::TraceFormat::Ti) {
104 if (extra_ == nullptr)
107 /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
109 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
110 if (get_container()->get_name().find("rank-") != 0)
111 stream_ << get_container()->get_name() << " " << extra_->print();
113 /* Subtract -1 because this is the process id and we transform it to the rank id */
114 stream_ << stoi(get_container()->get_name().erase(0, 5)) - 1 << " " << extra_->print();
116 *tracing_files.at(get_container()) << stream_.str() << std::endl;