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, PajeEvent* event) {
21 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(),
25 static void init_stream(PajeEvent* 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(PajeEvent* 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_start() {
47 char *filename = TRACE_get_filename();
48 tracing_file = fopen(filename, "w");
49 if (tracing_file == nullptr){
50 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
53 XBT_DEBUG("Filename %s is open for writing", filename);
55 /* output generator version */
56 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
57 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
58 fprintf (tracing_file, "#[");
61 xbt_dynar_foreach (xbt_cmdline, cpt, str){
62 fprintf(tracing_file, "%s ",str);
64 fprintf (tracing_file, "]\n");
66 /* output one line comment */
67 dump_comment (TRACE_get_comment());
69 /* output comment file */
70 dump_comment_file (TRACE_get_comment_file());
73 TRACE_header(TRACE_basic(),TRACE_display_sizes());
76 void TRACE_paje_end() {
78 char *filename = TRACE_get_filename();
79 XBT_DEBUG("Filename %s is closed", filename);
82 void DefineContainerEvent::print() {
83 print_paje_debug(__FUNCTION__, this);
85 stream << " " << type->id
86 << " " << type->father->id
91 void DefineVariableTypeEvent::print() {
92 print_paje_debug(__FUNCTION__, this);
94 stream << " " << type->id
95 << " " << type->father->id
98 stream << " \"" << type->color << "\"";
102 void DefineStateTypeEvent::print() {
103 print_paje_debug(__FUNCTION__, this);
105 stream << " " << type->id
106 << " " << type->father->id
107 << " " << type->name;
111 void DefineEventTypeEvent::print() {
112 print_paje_debug(__FUNCTION__, this);
114 stream << " " << type->id
115 << " " << type->father->id
116 << " " << type->name;
120 void DefineLinkTypeEvent::print() {
121 print_paje_debug(__FUNCTION__, this);
123 stream << " " << type->id
124 << " " << type->father->id
127 << " " << type->name;
131 void DefineEntityValueEvent::print() {
132 print_paje_debug(__FUNCTION__, this);
134 stream << " " << value->id
135 << " " << value->father->id
136 << " " << value->name;
138 stream << " \"" << value->color << "\"";
142 void CreateContainerEvent::print() {
143 print_paje_debug(__FUNCTION__, this);
145 print_timestamp(this);
146 stream << " " << container->id
147 << " " << container->type->id
148 << " " << container->father->id
149 << " \"" << container->name << "\"";
154 void DestroyContainerEvent::print() {
155 print_paje_debug(__FUNCTION__, this);
157 print_timestamp(this);
158 stream << " " << container->type->id
159 << " " << container->id;
164 void SetVariableEvent::print() {
165 print_paje_debug(__FUNCTION__, this);
167 print_timestamp(this);
168 stream << " " << type->id
169 << " " << container->id
174 void AddVariableEvent::print() {
175 print_paje_debug(__FUNCTION__, this);
177 print_timestamp(this);
178 stream << " " << type->id
179 << " " << container->id
184 void SubVariableEvent::print() {
185 print_paje_debug(__FUNCTION__, this);
187 print_timestamp(this);
188 stream << " " << type->id
189 << " " << container->id
194 void SetStateEvent::print() {
195 print_paje_debug(__FUNCTION__, this);
197 print_timestamp(this);
198 stream << " " << type->id
199 << " " << container->id;
200 stream << " " <<value->id;
202 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
203 stream << " \"" << filename
204 << "\" " << linenumber;
210 void PushStateEvent::print() {
211 print_paje_debug(__FUNCTION__, this);
213 print_timestamp(this);
214 stream << " " << type->id
215 << " " << container->id;
216 stream << " " <<value->id;
218 if (TRACE_display_sizes()) {
220 if (extra != nullptr) {
221 stream << static_cast<instr_extra_data>(extra)->send_size;
228 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
229 stream << " \"" << filename
230 << "\" " << linenumber;
235 if (extra != nullptr) {
236 if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
237 xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
238 if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
239 xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
244 void PopStateEvent::print() {
245 print_paje_debug(__FUNCTION__, this);
247 print_timestamp(this);
248 stream << " " << type->id
249 << " " << container->id;
253 void ResetStateEvent::print() {
254 print_paje_debug(__FUNCTION__, this);
256 print_timestamp(this);
257 stream << " " << type->id
258 << " " << container->id;
262 void StartLinkEvent::print() {
263 print_paje_debug(__FUNCTION__, this);
265 print_timestamp(this);
266 stream << " " <<type->id
267 << " " <<container->id
269 stream << " " << sourceContainer->id
272 if (TRACE_display_sizes()) {
273 stream << " " << size;
278 void EndLinkEvent::print() {
279 print_paje_debug(__FUNCTION__, this);
281 print_timestamp(this);
282 stream << " " <<type->id
283 << " " <<container->id
285 stream << " " << destContainer->id
290 void NewEvent::print () {
291 print_paje_debug(__FUNCTION__, this);
293 print_timestamp(this);
294 stream << " " << type->id
295 << " " << container->id