1 /* Copyright (c) 2010-2016. 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.h"
8 #include "xbt/virtu.h" /* sg_cmdline */
11 #include <iomanip> /** std::setprecision **/
12 #include "simgrid/sg_config.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr_trace, "tracing event system");
16 extern FILE * tracing_file;
17 extern s_instr_trace_writer_t active_writer;
19 static std::stringstream stream;
21 void buffer_debug(std::vector<PajeEvent*> *buf);
22 void buffer_debug(std::vector<PajeEvent*> *buf) {
24 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
25 for (auto event :*buf){
27 XBT_DEBUG("%p %s", event, stream.str().c_str());
34 static void print_row() {
36 fprintf(tracing_file, "%s", stream.str().c_str());
37 XBT_DEBUG("Dump %s", stream.str().c_str());
42 static void print_timestamp(PajeEvent* event) {
44 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
45 if (event->timestamp < 1e-12)
48 stream << event->timestamp;
51 void TRACE_paje_start() {
52 char *filename = TRACE_get_filename();
53 tracing_file = fopen(filename, "w");
54 if (tracing_file == nullptr){
55 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
58 XBT_DEBUG("Filename %s is open for writing", filename);
60 /* output generator version */
61 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
62 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
63 fprintf (tracing_file, "#[");
66 xbt_dynar_foreach (xbt_cmdline, cpt, str){
67 fprintf(tracing_file, "%s ",str);
69 fprintf (tracing_file, "]\n");
71 /* output one line comment */
72 dump_comment (TRACE_get_comment());
74 /* output comment file */
75 dump_comment_file (TRACE_get_comment_file());
78 TRACE_header(TRACE_basic(),TRACE_display_sizes());
81 void TRACE_paje_end() {
83 char *filename = TRACE_get_filename();
84 XBT_DEBUG("Filename %s is closed", filename);
87 void DefineContainerEvent::print() {
88 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
89 stream << std::fixed << std::setprecision(TRACE_precision());
90 stream << (int)this->event_type;
91 stream << " " << type->id
92 << " " << type->father->id
97 void DefineVariableTypeEvent::print() {
98 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
99 stream << std::fixed << std::setprecision(TRACE_precision());
100 stream << (int)this->event_type;
101 stream << " " << type->id
102 << " " << type->father->id
103 << " " << type->name;
105 stream << " \"" << type->color << "\"";
109 void DefineStateTypeEvent::print() {
110 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
111 stream << std::fixed << std::setprecision(TRACE_precision());
112 stream << (int)this->event_type;
113 stream << " " << type->id
114 << " " << type->father->id
115 << " " << type->name;
119 void DefineEventTypeEvent::print() {
120 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
121 stream << std::fixed << std::setprecision(TRACE_precision());
122 stream << (int)this->event_type;
123 stream << " " << type->id
124 << " " << type->father->id
125 << " " << type->name;
129 void DefineLinkTypeEvent::print() {
130 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
131 stream << std::fixed << std::setprecision(TRACE_precision());
132 stream << (int)this->event_type;
133 stream << " " << type->id
134 << " " << type->father->id
137 << " " << type->name;
141 void DefineEntityValueEvent::print() {
142 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
143 stream << std::fixed << std::setprecision(TRACE_precision());
144 stream << (int)this->event_type;
145 stream << " " << value->id
146 << " " << value->father->id
147 << " " << value->name;
149 stream << " \"" << value->color << "\"";
153 void CreateContainerEvent::print() {
154 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
155 stream << std::fixed << std::setprecision(TRACE_precision());
156 stream << (int)this->event_type;
157 print_timestamp(this);
158 stream << " " << container->id
159 << " " << container->type->id
160 << " " << container->father->id
161 << " \"" << container->name << "\"";
166 void DestroyContainerEvent::print() {
167 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
168 stream << std::fixed << std::setprecision(TRACE_precision());
169 stream << (int)this->event_type;
170 print_timestamp(this);
171 stream << " " << container->type->id
172 << " " << container->id;
177 void SetVariableEvent::print() {
178 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
179 stream << std::fixed << std::setprecision(TRACE_precision());
180 stream << (int)this->event_type;
181 print_timestamp(this);
182 stream << " " << type->id
183 << " " << container->id
188 void AddVariableEvent::print() {
189 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
190 stream << std::fixed << std::setprecision(TRACE_precision());
191 stream << (int)this->event_type;
192 print_timestamp(this);
193 stream << " " << type->id
194 << " " << container->id
199 void SubVariableEvent::print() {
200 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
201 stream << std::fixed << std::setprecision(TRACE_precision());
202 stream << (int)this->event_type;
203 print_timestamp(this);
204 stream << " " << type->id
205 << " " << container->id
210 void SetStateEvent::print() {
211 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
212 stream << std::fixed << std::setprecision(TRACE_precision());
213 stream << (int)this->event_type;
214 print_timestamp(this);
215 stream << " " << type->id
216 << " " << container->id;
217 stream << " " <<value->id;
219 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
220 stream << " \"" << filename
221 << "\" " << linenumber;
227 void PushStateEvent::print() {
228 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
229 stream << std::fixed << std::setprecision(TRACE_precision());
230 stream << (int)this->event_type;
231 print_timestamp(this);
232 stream << " " << type->id
233 << " " << container->id;
234 stream << " " <<value->id;
236 if (TRACE_display_sizes()) {
238 if (extra != nullptr) {
239 stream << static_cast<instr_extra_data>(extra)->send_size;
246 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
247 stream << " \"" << filename
248 << "\" " << linenumber;
253 if (extra != nullptr) {
254 if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
255 xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
256 if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
257 xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
262 void PopStateEvent::print() {
263 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
264 stream << std::fixed << std::setprecision(TRACE_precision());
265 stream << (int)this->event_type;
266 print_timestamp(this);
267 stream << " " << type->id
268 << " " << container->id;
272 void ResetStateEvent::print() {
273 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
274 stream << std::fixed << std::setprecision(TRACE_precision());
275 stream << (int)this->event_type;
276 print_timestamp(this);
277 stream << " " << type->id
278 << " " << container->id;
282 void StartLinkEvent::print() {
283 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
284 stream << std::fixed << std::setprecision(TRACE_precision());
285 stream << (int)this->event_type;
286 print_timestamp(this);
287 stream << " " <<type->id
288 << " " <<container->id
290 stream << " " << sourceContainer->id
293 if (TRACE_display_sizes()) {
294 stream << " " << size;
299 void EndLinkEvent::print() {
300 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
301 stream << std::fixed << std::setprecision(TRACE_precision());
302 stream << (int)this->event_type;
303 print_timestamp(this);
304 stream << " " <<type->id
305 << " " <<container->id
307 stream << " " << destContainer->id
312 void NewEvent::print () {
313 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
314 stream << std::fixed << std::setprecision(TRACE_precision());
315 stream << (int)this->event_type;
316 print_timestamp(this);
317 stream << " " << type->id
318 << " " << container->id