Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6e6f7fad9a78950c15dcfabbb20fce0049ca4ebf
[simgrid.git] / src / instr / instr_paje_trace.cpp
1 /* Copyright (c) 2010-2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "src/instr/instr_private.h"
8 #include "xbt/virtu.h" /* sg_cmdline */
9 #include <sstream>
10 #include <vector>
11 #include <iomanip> /** std::setprecision **/
12 #include "simgrid/sg_config.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr_trace, "tracing event system");
15
16 extern FILE * tracing_file;
17 extern s_instr_trace_writer_t active_writer;
18
19 static std::stringstream stream;
20
21 void buffer_debug(std::vector<PajeEvent*> *buf);
22 void buffer_debug(std::vector<PajeEvent*> *buf) {
23   return;
24   XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
25   for (auto event :*buf){
26     event->print();
27     XBT_DEBUG("%p %s", event, stream.str().c_str());
28     stream.str("");
29     stream.clear();
30   }
31   XBT_DEBUG("<<<<<<");
32 }
33
34 static void print_row() {
35   stream << std::endl;
36   fprintf(tracing_file, "%s", stream.str().c_str());
37   XBT_DEBUG("Dump %s", stream.str().c_str());
38   stream.str("");
39   stream.clear();
40 }
41
42 static void print_timestamp(PajeEvent* event) {
43   stream << " ";
44   /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
45   if (event->timestamp < 1e-12)
46     stream << 0;
47   else 
48     stream << event->timestamp;
49 }  
50
51 void TRACE_paje_start() {
52   char *filename = TRACE_get_filename();
53   tracing_file = fopen(filename, "w");
54   if (tracing_file == nullptr){
55     THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
56   }
57
58   XBT_DEBUG("Filename %s is open for writing", filename);
59
60   /* output generator version */
61   fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
62            SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
63   fprintf (tracing_file, "#[");
64   unsigned int cpt;
65   char *str;
66   xbt_dynar_foreach (xbt_cmdline, cpt, str){
67     fprintf(tracing_file, "%s ",str);
68   }
69   fprintf (tracing_file, "]\n");
70
71   /* output one line comment */
72   dump_comment (TRACE_get_comment());
73
74   /* output comment file */
75   dump_comment_file (TRACE_get_comment_file());
76
77   /* output header */
78   TRACE_header(TRACE_basic(),TRACE_display_sizes());
79 }
80
81 void TRACE_paje_end() {
82   fclose(tracing_file);
83   char *filename = TRACE_get_filename();
84   XBT_DEBUG("Filename %s is closed", filename);
85 }
86
87 void DefineContainerEvent::print() {
88   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
89   stream << std::fixed << std::setprecision(TRACE_precision());
90   stream << (int)this->event_type;
91   stream << " " << type->id
92          << " " << type->father->id
93          << " " << type->name;
94   print_row();
95 }
96
97 void DefineVariableTypeEvent::print() {
98   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
99   stream << std::fixed << std::setprecision(TRACE_precision());
100   stream << (int)this->event_type;
101   stream << " " << type->id
102          << " " << type->father->id
103          << " " << type->name;
104   if (type->color)
105     stream << " \"" << type->color << "\"";
106   print_row();
107 }
108
109 void DefineStateTypeEvent::print() {
110   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
111   stream << std::fixed << std::setprecision(TRACE_precision());
112   stream << (int)this->event_type;
113   stream << " " << type->id
114          << " " << type->father->id
115          << " " << type->name;
116   print_row();
117 }
118
119 void DefineEventTypeEvent::print() {
120   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
121   stream << std::fixed << std::setprecision(TRACE_precision());
122   stream << (int)this->event_type;
123   stream << " " << type->id
124          << " " << type->father->id
125          << " " << type->name;
126   print_row();
127 }
128
129 void DefineLinkTypeEvent::print() {
130   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
131   stream << std::fixed << std::setprecision(TRACE_precision());
132   stream << (int)this->event_type;
133   stream << " " << type->id 
134          << " " << type->father->id 
135          << " " << source->id 
136          << " " << dest->id 
137          << " " << type->name;
138   print_row();
139 }
140
141 void DefineEntityValueEvent::print() {
142   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
143   stream << std::fixed << std::setprecision(TRACE_precision());
144   stream << (int)this->event_type;
145   stream << " "   << value->id
146          << " "   << value->father->id
147          << " "   << value->name;
148   if(value->color)
149     stream << " \"" << value->color << "\"";
150   print_row();
151 }
152
153 void CreateContainerEvent::print() {
154   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
155   stream << std::fixed << std::setprecision(TRACE_precision());
156   stream << (int)this->event_type;
157   print_timestamp(this);
158   stream << " "   << container->id
159          << " "   << container->type->id
160          << " "   << container->father->id
161          << " \"" << container->name << "\"";
162
163   print_row();
164 }
165
166 void DestroyContainerEvent::print() {
167   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
168   stream << std::fixed << std::setprecision(TRACE_precision());
169   stream << (int)this->event_type;
170   print_timestamp(this);
171   stream << " "   << container->type->id
172          << " "   << container->id;
173
174   print_row();
175 }
176
177 void SetVariableEvent::print() {
178   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
179   stream << std::fixed << std::setprecision(TRACE_precision());
180   stream << (int)this->event_type;
181   print_timestamp(this);
182   stream << " " << type->id
183          << " " << container->id
184          << " " << value;
185   print_row();
186 }
187
188 void AddVariableEvent::print() {
189   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
190   stream << std::fixed << std::setprecision(TRACE_precision());
191   stream << (int)this->event_type;
192   print_timestamp(this);
193   stream << " " << type->id
194          << " " << container->id
195          << " " << value;
196   print_row();
197 }
198
199 void SubVariableEvent::print() {
200   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
201   stream << std::fixed << std::setprecision(TRACE_precision());
202   stream << (int)this->event_type;
203   print_timestamp(this);
204   stream << " " << type->id
205          << " " << container->id
206          << " " << value;
207   print_row();
208 }
209
210 void SetStateEvent::print() {
211   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
212   stream << std::fixed << std::setprecision(TRACE_precision());
213   stream << (int)this->event_type;
214   print_timestamp(this);
215   stream << " " << type->id
216          << " " << container->id;
217   stream << " " <<value->id;
218 #if HAVE_SMPI
219   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
220     stream << " \"" << filename
221            << "\" " << linenumber;
222   }
223 #endif
224   print_row();
225 }
226
227 void PushStateEvent::print() {
228   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
229   stream << std::fixed << std::setprecision(TRACE_precision());
230   stream << (int)this->event_type;
231   print_timestamp(this);
232   stream << " " << type->id
233          << " " << container->id;
234   stream << " " <<value->id;
235
236   if (TRACE_display_sizes()) {
237     stream << " ";
238     if (extra != nullptr) {
239       stream << static_cast<instr_extra_data>(extra)->send_size;
240     }
241     else {
242       stream << 0;
243     }
244   }
245 #if HAVE_SMPI
246   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
247     stream << " \"" << filename
248            << "\" " << linenumber;
249   }
250 #endif
251   print_row();
252
253   if (extra != nullptr) {
254     if (static_cast<instr_extra_data>(extra)->sendcounts != nullptr)
255       xbt_free(static_cast<instr_extra_data>(extra)->sendcounts);
256     if (static_cast<instr_extra_data>(extra)->recvcounts != nullptr)
257       xbt_free(static_cast<instr_extra_data>(extra)->recvcounts);
258     xbt_free(extra);
259   }
260 }
261
262 void PopStateEvent::print() {
263   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
264   stream << std::fixed << std::setprecision(TRACE_precision());
265   stream << (int)this->event_type;
266   print_timestamp(this);
267   stream << " " << type->id
268          << " " << container->id;
269   print_row();
270 }
271
272 void ResetStateEvent::print() {
273   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
274   stream << std::fixed << std::setprecision(TRACE_precision());
275   stream << (int)this->event_type;
276   print_timestamp(this);
277   stream << " " << type->id
278          << " " << container->id;
279   print_row();
280 }
281
282 void StartLinkEvent::print() {
283   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
284   stream << std::fixed << std::setprecision(TRACE_precision());
285   stream << (int)this->event_type;
286   print_timestamp(this);
287   stream << " " <<type->id
288          << " " <<container->id
289          << " " <<value;
290   stream << " " << sourceContainer->id
291          << " " << key;
292
293   if (TRACE_display_sizes()) {
294     stream << " " << size;
295   }
296   print_row();
297 }
298
299 void EndLinkEvent::print() {
300   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
301   stream << std::fixed << std::setprecision(TRACE_precision());
302   stream << (int)this->event_type;
303   print_timestamp(this);
304   stream << " " <<type->id
305          << " " <<container->id
306          << " " <<value;
307   stream << " " << destContainer->id
308          << " " << key;
309   print_row();
310 }
311
312 void NewEvent::print () {
313   XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
314   stream << std::fixed << std::setprecision(TRACE_precision());
315   stream << (int)this->event_type;
316   print_timestamp(this);
317   stream << " " << type->id
318          << " " << container->id
319          << " " << value->id;
320   print_row();
321 }