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 init_stream(PajeEvent* event) {
35 stream << std::fixed << std::setprecision(TRACE_precision());
36 stream << (int) event->event_type;
39 static void print_row() {
41 fprintf(tracing_file, "%s", stream.str().c_str());
42 XBT_DEBUG("Dump %s", stream.str().c_str());
47 static void print_timestamp(PajeEvent* event) {
49 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
50 if (event->timestamp < 1e-12)
53 stream << event->timestamp;
56 void TRACE_paje_start() {
57 char *filename = TRACE_get_filename();
58 tracing_file = fopen(filename, "w");
59 if (tracing_file == nullptr){
60 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
63 XBT_DEBUG("Filename %s is open for writing", filename);
65 /* output generator version */
66 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
67 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
68 fprintf (tracing_file, "#[");
71 xbt_dynar_foreach (xbt_cmdline, cpt, str){
72 fprintf(tracing_file, "%s ",str);
74 fprintf (tracing_file, "]\n");
76 /* output one line comment */
77 dump_comment (TRACE_get_comment());
79 /* output comment file */
80 dump_comment_file (TRACE_get_comment_file());
83 TRACE_header(TRACE_basic(),TRACE_display_sizes());
86 void TRACE_paje_end() {
88 char *filename = TRACE_get_filename();
89 XBT_DEBUG("Filename %s is closed", filename);
92 void DefineContainerEvent::print() {
93 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
95 stream << " " << type->id
96 << " " << type->father->id
101 void DefineVariableTypeEvent::print() {
102 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
104 stream << " " << type->id
105 << " " << type->father->id
106 << " " << type->name;
108 stream << " \"" << type->color << "\"";
112 void DefineStateTypeEvent::print() {
113 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
115 stream << " " << type->id
116 << " " << type->father->id
117 << " " << type->name;
121 void DefineEventTypeEvent::print() {
122 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
124 stream << " " << type->id
125 << " " << type->father->id
126 << " " << type->name;
130 void DefineLinkTypeEvent::print() {
131 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
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);
144 stream << " " << value->id
145 << " " << value->father->id
146 << " " << value->name;
148 stream << " \"" << value->color << "\"";
152 void CreateContainerEvent::print() {
153 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
155 print_timestamp(this);
156 stream << " " << container->id
157 << " " << container->type->id
158 << " " << container->father->id
159 << " \"" << container->name << "\"";
164 void DestroyContainerEvent::print() {
165 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
167 print_timestamp(this);
168 stream << " " << container->type->id
169 << " " << container->id;
174 void SetVariableEvent::print() {
175 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
177 print_timestamp(this);
178 stream << " " << type->id
179 << " " << container->id
184 void AddVariableEvent::print() {
185 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
187 print_timestamp(this);
188 stream << " " << type->id
189 << " " << container->id
194 void SubVariableEvent::print() {
195 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
197 print_timestamp(this);
198 stream << " " << type->id
199 << " " << container->id
204 void SetStateEvent::print() {
205 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
207 print_timestamp(this);
208 stream << " " << type->id
209 << " " << container->id;
210 stream << " " <<value->id;
212 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
213 stream << " \"" << filename
214 << "\" " << linenumber;
220 void PushStateEvent::print() {
221 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
223 print_timestamp(this);
224 stream << " " << type->id
225 << " " << container->id;
226 stream << " " <<value->id;
228 if (TRACE_display_sizes()) {
230 if (extra != nullptr) {
231 stream << static_cast<instr_extra_data>(extra)->send_size;
238 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
239 stream << " \"" << filename
240 << "\" " << linenumber;
245 if (extra != nullptr) {
246 if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
247 xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
248 if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
249 xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
254 void PopStateEvent::print() {
255 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
257 print_timestamp(this);
258 stream << " " << type->id
259 << " " << container->id;
263 void ResetStateEvent::print() {
264 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
266 print_timestamp(this);
267 stream << " " << type->id
268 << " " << container->id;
272 void StartLinkEvent::print() {
273 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
275 print_timestamp(this);
276 stream << " " <<type->id
277 << " " <<container->id
279 stream << " " << sourceContainer->id
282 if (TRACE_display_sizes()) {
283 stream << " " << size;
288 void EndLinkEvent::print() {
289 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
291 print_timestamp(this);
292 stream << " " <<type->id
293 << " " <<container->id
295 stream << " " << destContainer->id
300 void NewEvent::print () {
301 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
303 print_timestamp(this);
304 stream << " " << type->id
305 << " " << container->id