1 /* Copyright (c) 2012-2017. 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.hpp"
8 #include "src/instr/instr_smpi.hpp"
9 #include "src/smpi/include/private.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", __FUNCTION__, 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", __FUNCTION__, 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", __FUNCTION__, 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;
66 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
70 void NewEvent::print()
72 std::stringstream stream;
73 stream << std::fixed << std::setprecision(TRACE_precision());
74 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
75 if (instr_fmt_type != instr_fmt_paje)
78 if (timestamp_ < 1e-12)
79 stream << eventType_ << " " << 0 << " ";
81 stream << eventType_ << " " << timestamp_ << " ";
82 stream << getType()->getId() << " " << getContainer()->getId() << " " << 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", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
92 if (instr_fmt_type != instr_fmt_paje)
94 if (timestamp_ < 1e-12)
95 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
97 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
99 stream << " " << value_ << " " << endpoint_->getId() << " " << key_;
101 if (TRACE_display_sizes()) {
102 stream << " " << size_;
104 XBT_DEBUG("Dump %s", stream.str().c_str());
105 fprintf(tracing_file, "%s\n", stream.str().c_str());
108 void VariableEvent::print()
110 std::stringstream stream;
111 stream << std::fixed << std::setprecision(TRACE_precision());
112 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
113 if (instr_fmt_type != instr_fmt_paje)
116 if (timestamp_ < 1e-12)
117 stream << eventType_ << " " << 0 << " ";
119 stream << eventType_ << " " << timestamp_ << " ";
120 stream << getType()->getId() << " " << getContainer()->getId() << " " << value;
121 XBT_DEBUG("Dump %s", stream.str().c_str());
122 fprintf(tracing_file, "%s\n", stream.str().c_str());
125 void StateEvent::print()
127 std::stringstream stream;
128 stream << std::fixed << std::setprecision(TRACE_precision());
129 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
130 if (instr_fmt_type == instr_fmt_paje) {
131 if (timestamp_ < 1e-12)
132 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
134 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
136 if (value != nullptr) // PAJE_PopState Event does not need to have a value
137 stream << " " << value->getId();
139 if (TRACE_display_sizes())
140 stream << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
143 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
144 stream << " \"" << filename << "\" " << linenumber;
147 XBT_DEBUG("Dump %s", stream.str().c_str());
148 fprintf(tracing_file, "%s\n", stream.str().c_str());
149 } else if (instr_fmt_type == instr_fmt_TI) {
150 if (extra_ == nullptr)
153 /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
155 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
156 if (getContainer()->getName().find("rank-") != 0)
157 stream << getContainer()->getName() << " " << extra_->print();
159 /* Subtract -1 because this is the process id and we transform it to the rank id */
160 stream << stoi(getContainer()->getName().erase(0, 5)) - 1 << " " << extra_->print();
162 fprintf(tracing_files.at(getContainer()), "%s\n", stream.str().c_str());