Logo AND Algorithmique Numérique Distribuée

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