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 */
10 #include <iomanip> /** std::setprecision **/
11 #include "simgrid/sg_config.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr_trace, "tracing event system");
15 extern FILE * tracing_file;
16 extern s_instr_trace_writer_t active_writer;
18 static std::stringstream stream;
20 static void print_paje_debug(std::string functionName, paje_event_t event) {
21 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(),
25 static void init_stream(paje_event_t event) {
26 stream << std::fixed << std::setprecision(TRACE_precision());
27 stream << (int) event->event_type;
30 static void print_row() {
32 fprintf(tracing_file, "%s", stream.str().c_str());
37 static void print_timestamp(paje_event_t event) {
39 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
40 if (event->timestamp < 1e-12)
43 stream << event->timestamp;
46 void TRACE_paje_init() {
48 //active_writer.print_DefineContainerType = &print_pajeDefineContainerType;
49 active_writer.print_DefineVariableType = &print_pajeDefineVariableType;
50 active_writer.print_DefineStateType = &print_pajeDefineStateType;
51 active_writer.print_DefineEventType = &print_pajeDefineEventType;
52 active_writer.print_DefineLinkType = &print_pajeDefineLinkType;
53 active_writer.print_DefineEntityValue = &print_pajeDefineEntityValue;
54 active_writer.print_CreateContainer = &print_pajeCreateContainer;
55 active_writer.print_DestroyContainer = &print_pajeDestroyContainer;
56 active_writer.print_SetVariable = &print_pajeSetVariable;
57 active_writer.print_AddVariable = &print_pajeAddVariable;
58 active_writer.print_SubVariable = &print_pajeSubVariable;
59 active_writer.print_SetState = &print_pajeSetState;
60 active_writer.print_PushState = &print_pajePushState;
61 active_writer.print_PopState = &print_pajePopState;
62 active_writer.print_ResetState = &print_pajeResetState;
63 active_writer.print_StartLink = &print_pajeStartLink;
64 active_writer.print_EndLink = &print_pajeEndLink;
65 active_writer.print_NewEvent = &print_pajeNewEvent;
69 void TRACE_paje_start() {
70 char *filename = TRACE_get_filename();
71 tracing_file = fopen(filename, "w");
72 if (tracing_file == nullptr){
73 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
76 XBT_DEBUG("Filename %s is open for writing", filename);
78 /* output generator version */
79 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
80 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
81 fprintf (tracing_file, "#[");
84 xbt_dynar_foreach (xbt_cmdline, cpt, str){
85 fprintf(tracing_file, "%s ",str);
87 fprintf (tracing_file, "]\n");
89 /* output one line comment */
90 dump_comment (TRACE_get_comment());
92 /* output comment file */
93 dump_comment_file (TRACE_get_comment_file());
96 TRACE_header(TRACE_basic(),TRACE_display_sizes());
99 void TRACE_paje_end() {
100 fclose(tracing_file);
101 char *filename = TRACE_get_filename();
102 XBT_DEBUG("Filename %s is closed", filename);
105 void DefineContainerEvent::print() {
106 print_paje_debug(__FUNCTION__, this);
108 stream << " " << type->id
109 << " " << type->father->id
110 << " " << type->name;
114 void DefineVariableTypeEvent::print() {
115 print_paje_debug(__FUNCTION__, this);
117 stream << " " << type->id
118 << " " << type->father->id
119 << " " << type->name;
121 stream << " \"" << type->color << "\"";
125 void DefineStateTypeEvent::print() {
126 print_paje_debug(__FUNCTION__, this);
128 stream << " " << type->id
129 << " " << type->father->id
130 << " " << type->name;
134 void DefineEventTypeEvent::print() {
135 print_paje_debug(__FUNCTION__, this);
137 stream << " " << type->id
138 << " " << type->father->id
139 << " " << type->name;
143 void DefineLinkTypeEvent::print() {
144 print_paje_debug(__FUNCTION__, this);
146 stream << " " << type->id
147 << " " << type->father->id
150 << " " << type->name;
154 void DefineEntityValueEvent::print() {
155 print_paje_debug(__FUNCTION__, this);
157 stream << " " << value->id
158 << " " << value->father->id
159 << " " << value->name;
161 stream << " \"" << value->color << "\"";
165 void CreateContainerEvent::print() {
166 print_paje_debug(__FUNCTION__, this);
168 print_timestamp(this);
169 stream << " " << container->id
170 << " " << container->type->id
171 << " " << container->father->id
172 << " \"" << container->name << "\"";
177 void DestroyContainerEvent::print() {
178 print_paje_debug(__FUNCTION__, this);
180 print_timestamp(this);
181 stream << " " << container->type->id
182 << " " << container->id;
187 void SetVariableEvent::print() {
188 print_paje_debug(__FUNCTION__, this);
190 print_timestamp(this);
191 stream << " " << type->id
192 << " " << container->id
197 void AddVariableEvent::print() {
198 print_paje_debug(__FUNCTION__, this);
200 print_timestamp(this);
201 stream << " " << type->id
202 << " " << container->id
207 void SubVariableEvent::print() {
208 print_paje_debug(__FUNCTION__, this);
210 print_timestamp(this);
211 stream << " " << type->id
212 << " " << container->id
217 void SetStateEvent::print() {
218 print_paje_debug(__FUNCTION__, this);
220 print_timestamp(this);
221 stream << " " << type->id
222 << " " << container->id;
223 stream << " " <<value->id;
225 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
226 stream << " \"" << filename
227 << "\" " << linenumber;
233 void PushStateEvent::print() {
234 print_paje_debug(__FUNCTION__, this);
236 print_timestamp(this);
237 stream << " " << type->id
238 << " " << container->id;
239 stream << " " <<value->id;
241 if (TRACE_display_sizes()) {
243 if (extra != nullptr) {
244 stream << static_cast<instr_extra_data>(extra)->send_size;
251 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
252 stream << " \"" << filename
253 << "\" " << linenumber;
258 if (extra != nullptr) {
259 if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
260 xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
261 if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
262 xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
267 void PopStateEvent::print() {
268 print_paje_debug(__FUNCTION__, this);
270 print_timestamp(this);
271 stream << " " << type->id
272 << " " << container->id;
276 void ResetStateEvent::print() {
277 print_paje_debug(__FUNCTION__, this);
279 print_timestamp(this);
280 stream << " " << type->id
281 << " " << container->id;
285 void StartLinkEvent::print() {
286 print_paje_debug(__FUNCTION__, this);
288 print_timestamp(this);
289 stream << " " <<type->id
290 << " " <<container->id
292 stream << " " << sourceContainer->id
295 if (TRACE_display_sizes()) {
296 stream << " " << size;
301 void EndLinkEvent::print() {
302 print_paje_debug(__FUNCTION__, this);
304 print_timestamp(this);
305 stream << " " <<type->id
306 << " " <<container->id
308 stream << " " << destContainer->id
313 void NewEvent::print () {
314 print_paje_debug(__FUNCTION__, this);
316 print_timestamp(this);
317 stream << " " << type->id
318 << " " << container->id