Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill unused private functions instr_{pause,resume}_tracing().
[simgrid.git] / src / instr / instr_config.cpp
1 /* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "include/xbt/config.hpp"
7 #include "src/instr/instr_private.hpp"
8 #include "surf/surf.hpp"
9 #include <string>
10 #include <vector>
11
12 XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)");
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
14
15 #define OPT_TRACING_BASIC                "tracing/basic"
16 #define OPT_TRACING_BUFFER               "tracing/buffer"
17 #define OPT_TRACING_CATEGORIZED          "tracing/categorized"
18 #define OPT_TRACING_COMMENT_FILE         "tracing/comment-file"
19 #define OPT_TRACING_COMMENT              "tracing/comment"
20 #define OPT_TRACING_DISABLE_DESTROY      "tracing/disable-destroy"
21 #define OPT_TRACING_DISABLE_LINK         "tracing/disable-link"
22 #define OPT_TRACING_DISABLE_POWER        "tracing/disable-power"
23 #define OPT_TRACING_DISPLAY_SIZES        "tracing/smpi/display-sizes"
24 #define OPT_TRACING_FILENAME             "tracing/filename"
25 #define OPT_TRACING_FORMAT_TI_ONEFILE    "tracing/smpi/format/ti-one-file"
26 #define OPT_TRACING_FORMAT               "tracing/smpi/format"
27 #define OPT_TRACING_MSG_PROCESS          "tracing/msg/process"
28 #define OPT_TRACING_MSG_VM               "tracing/msg/vm"
29 #define OPT_TRACING_PLATFORM             "tracing/platform"
30 #define OPT_TRACING_PRECISION            "tracing/precision"
31 #define OPT_TRACING_SMPI_COMPUTING       "tracing/smpi/computing"
32 #define OPT_TRACING_SMPI_GROUP           "tracing/smpi/group"
33 #define OPT_TRACING_SMPI_INTERNALS       "tracing/smpi/internals"
34 #define OPT_TRACING_SMPI_SLEEPING        "tracing/smpi/sleeping"
35 #define OPT_TRACING_SMPI                 "tracing/smpi"
36 #define OPT_TRACING_TOPOLOGY             "tracing/platform/topology"
37 #define OPT_TRACING                      "tracing"
38 #define OPT_TRACING_UNCATEGORIZED        "tracing/uncategorized"
39
40 static bool trace_enabled = false;
41 static bool trace_platform;
42 static bool trace_platform_topology;
43 static bool trace_smpi_enabled;
44 static bool trace_smpi_grouped;
45 static bool trace_smpi_computing;
46 static bool trace_smpi_sleeping;
47 static bool trace_view_internals;
48 static bool trace_categorized;
49 static bool trace_uncategorized;
50 static bool trace_actor_enabled;
51 static bool trace_msg_vm_enabled;
52 static bool trace_buffer;
53 static bool trace_disable_destroy;
54 static bool trace_basic;
55 static bool trace_display_sizes = false;
56 static bool trace_disable_link;
57 static bool trace_disable_power;
58 static int trace_precision;
59
60 static bool trace_configured = false;
61 static bool trace_active     = false;
62
63 instr_fmt_type_t instr_fmt_type = instr_fmt_paje;
64
65 static void TRACE_getopts()
66 {
67   trace_enabled             = xbt_cfg_get_boolean(OPT_TRACING);
68   trace_platform            = xbt_cfg_get_boolean(OPT_TRACING_PLATFORM);
69   trace_platform_topology   = xbt_cfg_get_boolean(OPT_TRACING_TOPOLOGY);
70   trace_smpi_enabled        = xbt_cfg_get_boolean(OPT_TRACING_SMPI);
71   trace_smpi_grouped        = xbt_cfg_get_boolean(OPT_TRACING_SMPI_GROUP);
72   trace_smpi_computing      = xbt_cfg_get_boolean(OPT_TRACING_SMPI_COMPUTING);
73   trace_smpi_sleeping       = xbt_cfg_get_boolean(OPT_TRACING_SMPI_SLEEPING);
74   trace_view_internals      = xbt_cfg_get_boolean(OPT_TRACING_SMPI_INTERNALS);
75   trace_categorized         = xbt_cfg_get_boolean(OPT_TRACING_CATEGORIZED);
76   trace_uncategorized       = xbt_cfg_get_boolean(OPT_TRACING_UNCATEGORIZED);
77   trace_actor_enabled       = trace_enabled && xbt_cfg_get_boolean(OPT_TRACING_MSG_PROCESS);
78   trace_msg_vm_enabled      = xbt_cfg_get_boolean(OPT_TRACING_MSG_VM);
79   trace_buffer              = xbt_cfg_get_boolean(OPT_TRACING_BUFFER);
80   trace_disable_destroy     = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_DESTROY);
81   trace_basic               = xbt_cfg_get_boolean(OPT_TRACING_BASIC);
82   trace_display_sizes       = xbt_cfg_get_boolean(OPT_TRACING_DISPLAY_SIZES);
83   trace_disable_link        = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_LINK);
84   trace_disable_power       = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_POWER);
85   trace_precision           = xbt_cfg_get_int(OPT_TRACING_PRECISION);
86 }
87
88 int TRACE_start()
89 {
90   if (TRACE_is_configured())
91     TRACE_getopts();
92
93   // tracing system must be:
94   //    - enabled (with --cfg=tracing:yes)
95   //    - already configured (TRACE_global_init already called)
96   if (TRACE_is_enabled()) {
97
98     XBT_DEBUG("Tracing starts");
99     /* init the tracing module to generate the right output */
100
101     /* open the trace file(s) */
102     std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
103     XBT_DEBUG("Tracing format %s\n", format.c_str());
104     if (format == "Paje") {
105       TRACE_paje_start();
106     } else if (format == "TI") {
107       instr_fmt_type = instr_fmt_TI;
108       TRACE_TI_start();
109     }else{
110       xbt_die("Unknown trace format :%s ", format.c_str());
111     }
112
113     /* activate trace */
114     if (trace_active) {
115       THROWF(tracing_error, 0, "Tracing is already active");
116     }
117     trace_active = true;
118     XBT_DEBUG("Tracing is on");
119   }
120   return 0;
121 }
122
123 int TRACE_end()
124 {
125   int retval;
126   if (not trace_active) {
127     retval = 1;
128   } else {
129     retval = 0;
130
131     /* dump trace buffer */
132     TRACE_last_timestamp_to_dump = surf_get_clock();
133     TRACE_paje_dump_buffer(true);
134
135     simgrid::instr::Type* root_type = simgrid::instr::Container::getRoot()->type_;
136     /* destroy all data structures of tracing (and free) */
137     delete simgrid::instr::Container::getRoot();
138     delete root_type;
139
140     /* close the trace files */
141     std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
142     XBT_DEBUG("Tracing format %s\n", format.c_str());
143     if (format == "Paje") {
144       TRACE_paje_end();
145     } else if (format == "TI") {
146       TRACE_TI_end();
147     }else{
148       xbt_die("Unknown trace format :%s ", format.c_str());
149     }
150
151     /* de-activate trace */
152     trace_active = false;
153     XBT_DEBUG("Tracing is off");
154     XBT_DEBUG("Tracing system is shutdown");
155   }
156   return retval;
157 }
158
159 bool TRACE_needs_platform ()
160 {
161   return TRACE_actor_is_enabled() || TRACE_msg_vm_is_enabled() || TRACE_categorized() || TRACE_uncategorized() ||
162          TRACE_platform() || (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
163 }
164
165 bool TRACE_is_enabled()
166 {
167   return trace_enabled;
168 }
169
170 bool TRACE_platform()
171 {
172   return trace_platform;
173 }
174
175 bool TRACE_platform_topology()
176 {
177   return trace_platform_topology;
178 }
179
180 bool TRACE_is_configured()
181 {
182   return trace_configured;
183 }
184
185 bool TRACE_smpi_is_enabled()
186 {
187   return (trace_smpi_enabled || TRACE_smpi_is_grouped()) && TRACE_is_enabled();
188 }
189
190 bool TRACE_smpi_is_grouped()
191 {
192   return trace_smpi_grouped;
193 }
194
195 bool TRACE_smpi_is_computing()
196 {
197   return trace_smpi_computing;
198 }
199
200 bool TRACE_smpi_is_sleeping()
201 {
202   return trace_smpi_sleeping;
203 }
204
205 bool TRACE_smpi_view_internals()
206 {
207   return trace_view_internals;
208 }
209
210 bool TRACE_categorized ()
211 {
212   return trace_categorized;
213 }
214
215 bool TRACE_uncategorized ()
216 {
217   return trace_uncategorized;
218 }
219
220 bool TRACE_actor_is_enabled()
221 {
222   return trace_actor_enabled;
223 }
224
225 bool TRACE_msg_vm_is_enabled()
226 {
227   return trace_msg_vm_enabled && TRACE_is_enabled();
228 }
229
230 bool TRACE_disable_link()
231 {
232   return trace_disable_link && TRACE_is_enabled();
233 }
234
235 bool TRACE_disable_speed()
236 {
237   return trace_disable_power && TRACE_is_enabled();
238 }
239
240 bool TRACE_buffer ()
241 {
242   return trace_buffer && TRACE_is_enabled();
243 }
244
245 bool TRACE_disable_destroy ()
246 {
247   return trace_disable_destroy && TRACE_is_enabled();
248 }
249
250 bool TRACE_basic ()
251 {
252   return trace_basic && TRACE_is_enabled();
253 }
254
255 bool TRACE_display_sizes ()
256 {
257    return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
258 }
259
260 std::string TRACE_get_comment()
261 {
262   return xbt_cfg_get_string(OPT_TRACING_COMMENT);
263 }
264
265 std::string TRACE_get_comment_file()
266 {
267   return xbt_cfg_get_string(OPT_TRACING_COMMENT_FILE);
268 }
269
270 int TRACE_precision ()
271 {
272   return xbt_cfg_get_int(OPT_TRACING_PRECISION);
273 }
274
275 std::string TRACE_get_filename()
276 {
277   return xbt_cfg_get_string(OPT_TRACING_FILENAME);
278 }
279
280 void TRACE_global_init()
281 {
282   static bool is_initialised = false;
283   if (is_initialised)
284     return;
285
286   is_initialised = true;
287   /* name of the tracefile */
288   xbt_cfg_register_string (OPT_TRACING_FILENAME, "simgrid.trace", nullptr, "Trace file created by the instrumented SimGrid.");
289   xbt_cfg_register_boolean(OPT_TRACING, "no", nullptr, "Enable Tracing.");
290   xbt_cfg_register_boolean(OPT_TRACING_PLATFORM, "no", nullptr, "Register the platform in the trace as a hierarchy.");
291   xbt_cfg_register_boolean(OPT_TRACING_TOPOLOGY, "yes", nullptr, "Register the platform topology in the trace as a graph.");
292   xbt_cfg_register_boolean(OPT_TRACING_SMPI, "no", nullptr, "Tracing of the SMPI interface.");
293   xbt_cfg_register_boolean(OPT_TRACING_SMPI_GROUP,"no", nullptr, "Group MPI processes by host.");
294   xbt_cfg_register_boolean(OPT_TRACING_SMPI_COMPUTING, "no", nullptr, "Generate states for timing out of SMPI parts of the application");
295   xbt_cfg_register_boolean(OPT_TRACING_SMPI_SLEEPING, "no", nullptr, "Generate states for timing out of SMPI parts of the application");
296   xbt_cfg_register_boolean(OPT_TRACING_SMPI_INTERNALS, "no", nullptr, "View internal messages sent by Collective communications in SMPI");
297   xbt_cfg_register_boolean(OPT_TRACING_CATEGORIZED, "no", nullptr, "Tracing categorized resource utilization of hosts and links.");
298   xbt_cfg_register_boolean(OPT_TRACING_UNCATEGORIZED, "no", nullptr, "Tracing uncategorized resource utilization of hosts and links.");
299
300   xbt_cfg_register_boolean(OPT_TRACING_MSG_PROCESS, "no", nullptr, "Tracing of MSG process behavior.");
301   xbt_cfg_register_boolean(OPT_TRACING_MSG_VM, "no", nullptr, "Tracing of MSG process behavior.");
302   xbt_cfg_register_boolean(OPT_TRACING_DISABLE_LINK, "no", nullptr, "Do not trace link bandwidth and latency.");
303   xbt_cfg_register_boolean(OPT_TRACING_DISABLE_POWER, "no", nullptr, "Do not trace host power.");
304   xbt_cfg_register_boolean(OPT_TRACING_BUFFER, "yes", nullptr, "Buffer trace events to put them in temporal order.");
305
306   xbt_cfg_register_boolean(OPT_TRACING_DISABLE_DESTROY, "no", nullptr, "Disable platform containers destruction.");
307   xbt_cfg_register_boolean(OPT_TRACING_BASIC, "no", nullptr, "Avoid extended events (impoverished trace file).");
308   xbt_cfg_register_boolean(OPT_TRACING_DISPLAY_SIZES, "no", nullptr, "(smpi only) Extended events with message size information");
309   xbt_cfg_register_string(OPT_TRACING_FORMAT, "Paje", nullptr, "(smpi only) Switch the output format of Tracing");
310   xbt_cfg_register_boolean(OPT_TRACING_FORMAT_TI_ONEFILE, "no", nullptr, "(smpi only) For replay format only : output to one file only");
311   xbt_cfg_register_string(OPT_TRACING_COMMENT, "", nullptr, "Comment to be added on the top of the trace file.");
312   xbt_cfg_register_string(OPT_TRACING_COMMENT_FILE, "", nullptr,
313       "The contents of the file are added to the top of the trace file as comment.");
314   xbt_cfg_register_int(OPT_TRACING_PRECISION, 6, nullptr, "Numerical precision used when timestamping events "
315       "(expressed in number of digits after decimal point)");
316
317   xbt_cfg_register_alias(OPT_TRACING_COMMENT_FILE,"tracing/comment_file");
318   xbt_cfg_register_alias(OPT_TRACING_DISABLE_DESTROY, "tracing/disable_destroy");
319   xbt_cfg_register_alias(OPT_TRACING_DISABLE_LINK, "tracing/disable_link");
320   xbt_cfg_register_alias(OPT_TRACING_DISABLE_POWER, "tracing/disable_power");
321   xbt_cfg_register_alias(OPT_TRACING_DISPLAY_SIZES, "tracing/smpi/display_sizes");
322   xbt_cfg_register_alias(OPT_TRACING_FORMAT_TI_ONEFILE, "tracing/smpi/format/ti_one_file");
323
324   /* instrumentation can be considered configured now */
325   trace_configured = true;
326 }
327
328 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
329 {
330   std::string str = std::string("--cfg=") + option + " ";
331
332   int len = str.size();
333   printf("%s%*.*s %s\n", str.c_str(), 30 - len, 30 - len, "", desc);
334   if (longdesc != nullptr && detailed){
335     printf ("%s\n\n", longdesc);
336   }
337 }
338
339 void TRACE_help (int detailed)
340 {
341   printf("Description of the tracing options accepted by this simulator:\n\n");
342   print_line (OPT_TRACING, "Enable the tracing system",
343       "  It activates the tracing system and register the simulation platform\n"
344       "  in the trace file. You have to enable this option to others take effect.", detailed);
345   print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
346       "  It activates the categorized resource utilization tracing. It should\n"
347       "  be enabled if tracing categories are used by this simulator.", detailed);
348   print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
349       "  It activates the uncategorized resource utilization tracing. Use it if\n"
350       "  this simulator do not use tracing categories and resource use have to be\n"
351       "  traced.", detailed);
352   print_line(OPT_TRACING_FILENAME, "Filename to register traces",
353              "  A file with this name will be created to register the simulation. The file\n"
354              "  is in the Paje format and can be analyzed using Paje, and PajeNG visualization\n"
355              "  tools. More information can be found in these webpages:\n"
356              "     http://github.com/schnorr/pajeng/\n"
357              "     http://paje.sourceforge.net/",
358              detailed);
359   print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
360       "  This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
361       "  interface and generates a trace that can be analyzed using Gantt-like\n"
362       "  visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
363       "  state, and point-to-point communications can be analyzed with arrows.", detailed);
364   print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
365       "  This option only has effect if this simulator is SMPI-based. The processes\n"
366       "  are grouped by the hosts where they were executed.", detailed);
367   print_line (OPT_TRACING_SMPI_COMPUTING, "Generates a \" Computing \" State",
368       "  This option aims at tracing computations in the application, outside SMPI\n"
369       "  to allow further study of simulated or real computation time", detailed);
370    print_line (OPT_TRACING_SMPI_SLEEPING, "Generates a \" Sleeping \" State",
371       "  This option aims at tracing sleeps in the application, outside SMPI\n"
372       "  to allow further study of simulated or real sleep time", detailed);
373   print_line (OPT_TRACING_SMPI_INTERNALS, "Generates tracing events corresponding",
374       "  to point-to-point messages sent by collective communications", detailed);
375   print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
376       "  This option only has effect if this simulator is MSG-based. It traces the\n"
377       "  behavior of all categorized MSG processes, grouping them by hosts. This option\n"
378       "  can be used to track process location if this simulator has process migration.", detailed);
379   print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
380       "  This option put some events in a time-ordered buffer using the insertion\n"
381       "  sort algorithm. The process of acquiring and releasing locks to access this\n"
382       "  buffer and the cost of the sorting algorithm make this process slow. The\n"
383       "  simulator performance can be severely impacted if this option is activated,\n"
384       "  but you are sure to get a trace file with events sorted.", detailed);
385   print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
386       "  Disable the destruction of containers at the end of simulation. This can be\n"
387       "  used with simulators that have a different notion of time (different from\n"
388       "  the simulated time).", detailed);
389   print_line (OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
390       "  Some visualization tools are not able to parse correctly the Paje file format.\n"
391       "  Use this option if you are using one of these tools to visualize the simulation\n"
392       "  trace. Keep in mind that the trace might be incomplete, without all the\n"
393       "  information that would be registered otherwise.", detailed);
394   print_line (OPT_TRACING_DISPLAY_SIZES, "Only works for SMPI now. Add message size information",
395       "  Message size (in bytes) is added to links, and to states. For collectives,\n"
396       "  the displayed value is the more relevant to the collective (total sent by\n"
397       "  the process, usually)", detailed);
398   print_line (OPT_TRACING_FORMAT, "Only works for SMPI now. Switch output format",
399       "  Default format is Paje. Time independent traces are also supported,\n"
400       "  to output traces that can later be used by the trace replay tool", detailed);
401   print_line (OPT_TRACING_FORMAT_TI_ONEFILE, "Only works for SMPI now, and TI output format",
402       "  By default, each process outputs to a separate file, inside a filename_files folder\n"
403       "  By setting this option to yes, all processes will output to only one file\n"
404       "  This is meant to avoid opening thousands of files with large simulations", detailed);
405   print_line (OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
406       "  Use this to add a comment line to the top of the trace file.", detailed);
407   print_line (OPT_TRACING_COMMENT_FILE, "File contents added to trace file as comment.",
408       "  Use this to add the contents of a file to the top of the trace file as comment.", detailed);
409   print_line (OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
410         "  This option (enabled by default) can be used to disable the tracing of\n"
411         "  the platform topology in the trace file. Sometimes, such task is really\n"
412         "  time consuming, since it must get the route from each host to other hosts\n"
413         "  within the same Autonomous System (AS).", detailed);
414 }
415
416 static void output_types (const char *name, xbt_dynar_t types, FILE *file)
417 {
418   unsigned int i;
419   fprintf (file, "  %s = (", name);
420   for (i = xbt_dynar_length(types); i > 0; i--) {
421     char *type = *(static_cast<char**>(xbt_dynar_get_ptr(types, i - 1)));
422     fprintf (file, "\"%s\"", type);
423     if (i - 1 > 0){
424       fprintf (file, ",");
425     }else{
426       fprintf (file, ");\n");
427     }
428   }
429   xbt_dynar_free (&types);
430 }