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"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
11 extern FILE* tracing_file;
12 std::map<container_t, FILE*> tracing_files; // TI specific
17 NewEvent::NewEvent(double timestamp, container_t container, Type* type, EntityValue* val)
18 : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent), val(val)
20 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, eventType_, timestamp_);
24 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
25 std::string value, std::string key)
26 : LinkEvent(container, type, event_type, endpoint, value, key, -1)
30 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
31 std::string value, std::string key, int size)
32 : PajeEvent(container, type, SIMIX_get_clock(), event_type)
38 XBT_DEBUG("%s: event_type=%u, timestamp=%f, value:%s", __func__, eventType_, timestamp_, value_.c_str());
42 VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
43 : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
45 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, eventType_, timestamp_);
49 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value)
50 : StateEvent(container, type, event_type, value, nullptr)
54 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
55 : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
58 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
59 smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
60 filename = loc->filename;
61 linenumber = loc->linenumber;
68 XBT_DEBUG("%s: event_type=%u, timestamp=%f", __func__, eventType_, timestamp_);
72 void NewEvent::print()
74 std::stringstream stream;
75 stream << std::fixed << std::setprecision(TRACE_precision());
76 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
77 if (instr_fmt_type != instr_fmt_paje)
80 if (timestamp_ < 1e-12)
81 stream << eventType_ << " " << 0 << " ";
83 stream << eventType_ << " " << timestamp_ << " ";
84 stream << getType()->getId() << " " << getContainer()->getId() << " " << val->getId();
85 XBT_DEBUG("Dump %s", stream.str().c_str());
86 fprintf(tracing_file, "%s\n", stream.str().c_str());
89 void LinkEvent::print()
91 std::stringstream stream;
92 stream << std::fixed << std::setprecision(TRACE_precision());
93 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
94 if (instr_fmt_type != instr_fmt_paje)
96 if (timestamp_ < 1e-12)
97 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
99 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
101 stream << " " << value_ << " " << endpoint_->getId() << " " << key_;
103 if (TRACE_display_sizes()) {
104 stream << " " << size_;
106 XBT_DEBUG("Dump %s", stream.str().c_str());
107 fprintf(tracing_file, "%s\n", stream.str().c_str());
110 void VariableEvent::print()
112 std::stringstream stream;
113 stream << std::fixed << std::setprecision(TRACE_precision());
114 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
115 if (instr_fmt_type != instr_fmt_paje)
118 if (timestamp_ < 1e-12)
119 stream << eventType_ << " " << 0 << " ";
121 stream << eventType_ << " " << timestamp_ << " ";
122 stream << getType()->getId() << " " << getContainer()->getId() << " " << value;
123 XBT_DEBUG("Dump %s", stream.str().c_str());
124 fprintf(tracing_file, "%s\n", stream.str().c_str());
127 void StateEvent::print()
129 std::stringstream stream;
130 stream << std::fixed << std::setprecision(TRACE_precision());
131 XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
132 if (instr_fmt_type == instr_fmt_paje) {
133 if (timestamp_ < 1e-12)
134 stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
136 stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
138 if (value != nullptr) // PAJE_PopState Event does not need to have a value
139 stream << " " << value->getId();
141 if (TRACE_display_sizes())
142 stream << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
145 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
146 stream << " \"" << filename << "\" " << linenumber;
149 XBT_DEBUG("Dump %s", stream.str().c_str());
150 fprintf(tracing_file, "%s\n", stream.str().c_str());
151 } else if (instr_fmt_type == instr_fmt_TI) {
152 if (extra_ == nullptr)
155 /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
157 // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
158 if (getContainer()->getName().find("rank-") != 0)
159 stream << getContainer()->getName() << " " << extra_->print();
161 /* Subtract -1 because this is the process id and we transform it to the rank id */
162 stream << stoi(getContainer()->getName().erase(0, 5)) - 1 << " " << extra_->print();
164 fprintf(tracing_files.at(getContainer()), "%s\n", stream.str().c_str());