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 NewEvent::NewEvent(double timestamp, container_t container, Type* type, EntityValue* val)
19 : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent), val(val)
21 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, eventType_, timestamp_);
25 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
26 std::string value, std::string key)
27 : LinkEvent(container, type, event_type, endpoint, value, key, -1)
31 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
32 std::string value, std::string key, int size)
33 : PajeEvent(container, type, SIMIX_get_clock(), event_type)
39 XBT_DEBUG("%s: event_type=%u, timestamp=%f, value:%s", __func__, eventType_, timestamp_, value_.c_str());
43 VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
44 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
46 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, eventType_, timestamp_);
50 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value)
51 : StateEvent(container, type, event_type, value, nullptr)
55 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
56 : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
59 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
60 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
61 filename = loc->filename;
62 linenumber = loc->linenumber;
69 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, eventType_, timestamp_);
73 void NewEvent::print()
75 std::stringstream stream;
76 stream << std::fixed << std::setprecision(TRACE_precision());
77 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
78 if (instr_fmt_type != instr_fmt_paje)
81 stream << eventType_ << " " << timestamp_ << " ";
82 stream << getType()->get_id() << " " << getContainer()->get_id() << " " << val->getId();
83 XBT_DEBUG("Dump %s", stream.str().c_str());
84 fprintf(tracing_file, "%s\n", stream.str().c_str());
87 void LinkEvent::print()
89 std::stringstream stream;
90 stream << std::fixed << std::setprecision(TRACE_precision());
91 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
92 if (instr_fmt_type != instr_fmt_paje)
94 stream << eventType_ << " " << timestamp_ << " " << getType()->get_id() << " " << getContainer()->get_id();
96 stream << " " << value_ << " " << endpoint_->get_id() << " " << key_;
98 if (TRACE_display_sizes()) {
99 stream << " " << size_;
101 XBT_DEBUG("Dump %s", stream.str().c_str());
102 fprintf(tracing_file, "%s\n", stream.str().c_str());
105 void VariableEvent::print()
107 std::stringstream stream;
108 stream << std::fixed << std::setprecision(TRACE_precision());
109 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
110 if (instr_fmt_type != instr_fmt_paje)
113 stream << eventType_ << " " << timestamp_ << " ";
114 stream << getType()->get_id() << " " << getContainer()->get_id() << " " << value;
115 XBT_DEBUG("Dump %s", stream.str().c_str());
116 fprintf(tracing_file, "%s\n", stream.str().c_str());
119 void StateEvent::print()
121 std::stringstream stream;
122 stream << std::fixed << std::setprecision(TRACE_precision());
123 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
124 if (instr_fmt_type == instr_fmt_paje) {
125 stream << eventType_ << " " << timestamp_ << " " << getType()->get_id() << " " << getContainer()->get_id();
127 if (value != nullptr) // PAJE_PopState Event does not need to have a value
128 stream << " " << value->getId();
130 if (TRACE_display_sizes())
131 stream << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
134 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
135 stream << " \"" << filename << "\" " << linenumber;
138 XBT_DEBUG("Dump %s", stream.str().c_str());
139 fprintf(tracing_file, "%s\n", stream.str().c_str());
140 } else if (instr_fmt_type == instr_fmt_TI) {
141 if (extra_ == nullptr)
144 /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
146 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
147 if (getContainer()->get_name().find("rank-") != 0)
148 stream << getContainer()->get_name() << " " << extra_->print();
150 /* Subtract -1 because this is the process id and we transform it to the rank id */
151 stream << stoi(getContainer()->get_name().erase(0, 5)) - 1 << " " << extra_->print();
153 fprintf(tracing_files.at(getContainer()), "%s\n", stream.str().c_str());