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) {
23 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
24 for (auto event :*buf){
26 XBT_DEBUG("%s", stream.str().c_str());
33 static void print_paje_debug(std::string functionName, PajeEvent* event) {
34 XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(),
38 static void init_stream(PajeEvent* event) {
39 stream << std::fixed << std::setprecision(TRACE_precision());
40 stream << (int) event->event_type;
43 static void print_row() {
45 fprintf(tracing_file, "%s", stream.str().c_str());
50 static void print_timestamp(PajeEvent* event) {
52 /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
53 if (event->timestamp < 1e-12)
56 stream << event->timestamp;
59 void TRACE_paje_start() {
60 char *filename = TRACE_get_filename();
61 tracing_file = fopen(filename, "w");
62 if (tracing_file == nullptr){
63 THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
66 XBT_DEBUG("Filename %s is open for writing", filename);
68 /* output generator version */
69 fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
70 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
71 fprintf (tracing_file, "#[");
74 xbt_dynar_foreach (xbt_cmdline, cpt, str){
75 fprintf(tracing_file, "%s ",str);
77 fprintf (tracing_file, "]\n");
79 /* output one line comment */
80 dump_comment (TRACE_get_comment());
82 /* output comment file */
83 dump_comment_file (TRACE_get_comment_file());
86 TRACE_header(TRACE_basic(),TRACE_display_sizes());
89 void TRACE_paje_end() {
91 char *filename = TRACE_get_filename();
92 XBT_DEBUG("Filename %s is closed", filename);
95 void DefineContainerEvent::print() {
96 print_paje_debug(__FUNCTION__, this);
98 stream << " " << type->id
99 << " " << type->father->id
100 << " " << type->name;
104 void DefineVariableTypeEvent::print() {
105 print_paje_debug(__FUNCTION__, this);
107 stream << " " << type->id
108 << " " << type->father->id
109 << " " << type->name;
111 stream << " \"" << type->color << "\"";
115 void DefineStateTypeEvent::print() {
116 print_paje_debug(__FUNCTION__, this);
118 stream << " " << type->id
119 << " " << type->father->id
120 << " " << type->name;
124 void DefineEventTypeEvent::print() {
125 print_paje_debug(__FUNCTION__, this);
127 stream << " " << type->id
128 << " " << type->father->id
129 << " " << type->name;
133 void DefineLinkTypeEvent::print() {
134 print_paje_debug(__FUNCTION__, this);
136 stream << " " << type->id
137 << " " << type->father->id
140 << " " << type->name;
144 void DefineEntityValueEvent::print() {
145 print_paje_debug(__FUNCTION__, this);
147 stream << " " << value->id
148 << " " << value->father->id
149 << " " << value->name;
151 stream << " \"" << value->color << "\"";
155 void CreateContainerEvent::print() {
156 print_paje_debug(__FUNCTION__, this);
158 print_timestamp(this);
159 stream << " " << container->id
160 << " " << container->type->id
161 << " " << container->father->id
162 << " \"" << container->name << "\"";
167 void DestroyContainerEvent::print() {
168 print_paje_debug(__FUNCTION__, this);
170 print_timestamp(this);
171 stream << " " << container->type->id
172 << " " << container->id;
177 void SetVariableEvent::print() {
178 print_paje_debug(__FUNCTION__, this);
180 print_timestamp(this);
181 stream << " " << type->id
182 << " " << container->id
187 void AddVariableEvent::print() {
188 print_paje_debug(__FUNCTION__, this);
190 print_timestamp(this);
191 stream << " " << type->id
192 << " " << container->id
197 void SubVariableEvent::print() {
198 print_paje_debug(__FUNCTION__, this);
200 print_timestamp(this);
201 stream << " " << type->id
202 << " " << container->id
207 void SetStateEvent::print() {
208 print_paje_debug(__FUNCTION__, this);
210 print_timestamp(this);
211 stream << " " << type->id
212 << " " << container->id;
213 stream << " " <<value->id;
215 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
216 stream << " \"" << filename
217 << "\" " << linenumber;
223 void PushStateEvent::print() {
224 print_paje_debug(__FUNCTION__, this);
226 print_timestamp(this);
227 stream << " " << type->id
228 << " " << container->id;
229 stream << " " <<value->id;
231 if (TRACE_display_sizes()) {
233 if (extra != nullptr) {
234 stream << static_cast<instr_extra_data>(extra)->send_size;
241 if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
242 stream << " \"" << filename
243 << "\" " << linenumber;
248 if (extra != nullptr) {
249 if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
250 xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
251 if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
252 xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
257 void PopStateEvent::print() {
258 print_paje_debug(__FUNCTION__, this);
260 print_timestamp(this);
261 stream << " " << type->id
262 << " " << container->id;
266 void ResetStateEvent::print() {
267 print_paje_debug(__FUNCTION__, this);
269 print_timestamp(this);
270 stream << " " << type->id
271 << " " << container->id;
275 void StartLinkEvent::print() {
276 print_paje_debug(__FUNCTION__, this);
278 print_timestamp(this);
279 stream << " " <<type->id
280 << " " <<container->id
282 stream << " " << sourceContainer->id
285 if (TRACE_display_sizes()) {
286 stream << " " << size;
291 void EndLinkEvent::print() {
292 print_paje_debug(__FUNCTION__, this);
294 print_timestamp(this);
295 stream << " " <<type->id
296 << " " <<container->id
298 stream << " " << destContainer->id
303 void NewEvent::print () {
304 print_paje_debug(__FUNCTION__, this);
306 print_timestamp(this);
307 stream << " " << type->id
308 << " " << container->id