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_paje_debug(std::string functionName, PajeEvent* event) {
35 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(),
39 static void init_stream(PajeEvent* event) {
40 stream << std::fixed << std::setprecision(TRACE_precision());
41 stream << (int) event->event_type;
44 static void print_row() {
46 fprintf(tracing_file, "%s", stream.str().c_str());
47 XBT_DEBUG("Dump %s", stream.str().c_str());
52 static void print_timestamp(PajeEvent* event) {
54 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
55 if (event->timestamp < 1e-12)
58 stream << event->timestamp;
61 void TRACE_paje_start() {
62 char *filename = TRACE_get_filename();
63 tracing_file = fopen(filename, "w");
64 if (tracing_file == nullptr){
65 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
68 XBT_DEBUG("Filename %s is open for writing", filename);
70 /* output generator version */
71 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
72 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
73 fprintf (tracing_file, "#[");
76 xbt_dynar_foreach (xbt_cmdline, cpt, str){
77 fprintf(tracing_file, "%s ",str);
79 fprintf (tracing_file, "]\n");
81 /* output one line comment */
82 dump_comment (TRACE_get_comment());
84 /* output comment file */
85 dump_comment_file (TRACE_get_comment_file());
88 TRACE_header(TRACE_basic(),TRACE_display_sizes());
91 void TRACE_paje_end() {
93 char *filename = TRACE_get_filename();
94 XBT_DEBUG("Filename %s is closed", filename);
97 void DefineContainerEvent::print() {
98 print_paje_debug(__FUNCTION__, this);
100 stream << " " << type->id
101 << " " << type->father->id
102 << " " << type->name;
106 void DefineVariableTypeEvent::print() {
107 print_paje_debug(__FUNCTION__, this);
109 stream << " " << type->id
110 << " " << type->father->id
111 << " " << type->name;
113 stream << " \"" << type->color << "\"";
117 void DefineStateTypeEvent::print() {
118 print_paje_debug(__FUNCTION__, this);
120 stream << " " << type->id
121 << " " << type->father->id
122 << " " << type->name;
126 void DefineEventTypeEvent::print() {
127 print_paje_debug(__FUNCTION__, this);
129 stream << " " << type->id
130 << " " << type->father->id
131 << " " << type->name;
135 void DefineLinkTypeEvent::print() {
136 print_paje_debug(__FUNCTION__, this);
138 stream << " " << type->id
139 << " " << type->father->id
142 << " " << type->name;
146 void DefineEntityValueEvent::print() {
147 print_paje_debug(__FUNCTION__, this);
149 stream << " " << value->id
150 << " " << value->father->id
151 << " " << value->name;
153 stream << " \"" << value->color << "\"";
157 void CreateContainerEvent::print() {
158 print_paje_debug(__FUNCTION__, this);
160 print_timestamp(this);
161 stream << " " << container->id
162 << " " << container->type->id
163 << " " << container->father->id
164 << " \"" << container->name << "\"";
169 void DestroyContainerEvent::print() {
170 print_paje_debug(__FUNCTION__, this);
172 print_timestamp(this);
173 stream << " " << container->type->id
174 << " " << container->id;
179 void SetVariableEvent::print() {
180 print_paje_debug(__FUNCTION__, this);
182 print_timestamp(this);
183 stream << " " << type->id
184 << " " << container->id
189 void AddVariableEvent::print() {
190 print_paje_debug(__FUNCTION__, this);
192 print_timestamp(this);
193 stream << " " << type->id
194 << " " << container->id
199 void SubVariableEvent::print() {
200 print_paje_debug(__FUNCTION__, this);
202 print_timestamp(this);
203 stream << " " << type->id
204 << " " << container->id
209 void SetStateEvent::print() {
210 print_paje_debug(__FUNCTION__, this);
212 print_timestamp(this);
213 stream << " " << type->id
214 << " " << container->id;
215 stream << " " <<value->id;
217 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
218 stream << " \"" << filename
219 << "\" " << linenumber;
225 void PushStateEvent::print() {
226 print_paje_debug(__FUNCTION__, this);
228 print_timestamp(this);
229 stream << " " << type->id
230 << " " << container->id;
231 stream << " " <<value->id;
233 if (TRACE_display_sizes()) {
235 if (extra != nullptr) {
236 stream << static_cast<instr_extra_data>(extra)->send_size;
243 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
244 stream << " \"" << filename
245 << "\" " << linenumber;
250 if (extra != nullptr) {
251 if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
252 xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
253 if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
254 xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
259 void PopStateEvent::print() {
260 print_paje_debug(__FUNCTION__, this);
262 print_timestamp(this);
263 stream << " " << type->id
264 << " " << container->id;
268 void ResetStateEvent::print() {
269 print_paje_debug(__FUNCTION__, this);
271 print_timestamp(this);
272 stream << " " << type->id
273 << " " << container->id;
277 void StartLinkEvent::print() {
278 print_paje_debug(__FUNCTION__, this);
280 print_timestamp(this);
281 stream << " " <<type->id
282 << " " <<container->id
284 stream << " " << sourceContainer->id
287 if (TRACE_display_sizes()) {
288 stream << " " << size;
293 void EndLinkEvent::print() {
294 print_paje_debug(__FUNCTION__, this);
296 print_timestamp(this);
297 stream << " " <<type->id
298 << " " <<container->id
300 stream << " " << destContainer->id
305 void NewEvent::print () {
306 print_paje_debug(__FUNCTION__, this);
308 print_timestamp(this);
309 stream << " " << type->id
310 << " " << container->id