1 /* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved. */
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. */
6 #include "include/xbt/config.hpp"
7 #include "src/instr/instr_private.hpp"
8 #include "surf/surf.hpp"
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");
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_ACTOR "tracing/msg/process"
28 #define OPT_TRACING_VM "tracing/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"
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_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;
59 static bool trace_configured = false;
60 static bool trace_active = false;
62 simgrid::instr::TraceFormat simgrid::instr::trace_format = simgrid::instr::TraceFormat::Paje;
64 static void TRACE_getopts()
66 trace_enabled = xbt_cfg_get_boolean(OPT_TRACING);
67 trace_platform = xbt_cfg_get_boolean(OPT_TRACING_PLATFORM);
68 trace_platform_topology = xbt_cfg_get_boolean(OPT_TRACING_TOPOLOGY);
69 trace_smpi_enabled = xbt_cfg_get_boolean(OPT_TRACING_SMPI);
70 trace_smpi_grouped = xbt_cfg_get_boolean(OPT_TRACING_SMPI_GROUP);
71 trace_smpi_computing = xbt_cfg_get_boolean(OPT_TRACING_SMPI_COMPUTING);
72 trace_smpi_sleeping = xbt_cfg_get_boolean(OPT_TRACING_SMPI_SLEEPING);
73 trace_view_internals = xbt_cfg_get_boolean(OPT_TRACING_SMPI_INTERNALS);
74 trace_categorized = xbt_cfg_get_boolean(OPT_TRACING_CATEGORIZED);
75 trace_uncategorized = xbt_cfg_get_boolean(OPT_TRACING_UNCATEGORIZED);
76 trace_actor_enabled = trace_enabled && xbt_cfg_get_boolean(OPT_TRACING_ACTOR);
77 trace_vm_enabled = xbt_cfg_get_boolean(OPT_TRACING_VM);
78 trace_buffer = xbt_cfg_get_boolean(OPT_TRACING_BUFFER);
79 trace_disable_destroy = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_DESTROY);
80 trace_basic = xbt_cfg_get_boolean(OPT_TRACING_BASIC);
81 trace_display_sizes = xbt_cfg_get_boolean(OPT_TRACING_DISPLAY_SIZES);
82 trace_disable_link = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_LINK);
83 trace_disable_power = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_POWER);
88 if (TRACE_is_configured())
91 // tracing system must be:
92 // - enabled (with --cfg=tracing:yes)
93 // - already configured (TRACE_global_init already called)
94 if (TRACE_is_enabled()) {
96 XBT_DEBUG("Tracing starts");
97 /* init the tracing module to generate the right output */
99 /* open the trace file(s) */
100 std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
101 XBT_DEBUG("Tracing format %s\n", format.c_str());
102 if (format == "Paje") {
104 } else if (format == "TI") {
105 simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
108 xbt_die("Unknown trace format :%s ", format.c_str());
113 THROWF(tracing_error, 0, "Tracing is already active");
116 XBT_DEBUG("Tracing is on");
124 if (not trace_active) {
129 /* dump trace buffer */
130 TRACE_last_timestamp_to_dump = surf_get_clock();
131 TRACE_paje_dump_buffer(true);
133 simgrid::instr::Type* root_type = simgrid::instr::Container::getRoot()->type_;
134 /* destroy all data structures of tracing (and free) */
135 delete simgrid::instr::Container::getRoot();
138 /* close the trace files */
139 std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
140 XBT_DEBUG("Tracing format %s\n", format.c_str());
141 if (format == "Paje") {
143 } else if (format == "TI") {
146 xbt_die("Unknown trace format :%s ", format.c_str());
149 /* de-activate trace */
150 trace_active = false;
151 XBT_DEBUG("Tracing is off");
152 XBT_DEBUG("Tracing system is shutdown");
157 bool TRACE_needs_platform ()
159 return TRACE_actor_is_enabled() || TRACE_vm_is_enabled() || TRACE_categorized() || TRACE_uncategorized() ||
160 TRACE_platform() || (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
163 bool TRACE_is_enabled()
165 return trace_enabled;
168 bool TRACE_platform()
170 return trace_platform;
173 bool TRACE_platform_topology()
175 return trace_platform_topology;
178 bool TRACE_is_configured()
180 return trace_configured;
183 bool TRACE_smpi_is_enabled()
185 return (trace_smpi_enabled || TRACE_smpi_is_grouped()) && TRACE_is_enabled();
188 bool TRACE_smpi_is_grouped()
190 return trace_smpi_grouped;
193 bool TRACE_smpi_is_computing()
195 return trace_smpi_computing;
198 bool TRACE_smpi_is_sleeping()
200 return trace_smpi_sleeping;
203 bool TRACE_smpi_view_internals()
205 return trace_view_internals;
208 bool TRACE_categorized ()
210 return trace_categorized;
213 bool TRACE_uncategorized ()
215 return trace_uncategorized;
218 bool TRACE_actor_is_enabled()
220 return trace_actor_enabled;
223 bool TRACE_vm_is_enabled()
225 return trace_vm_enabled && TRACE_is_enabled();
228 bool TRACE_disable_link()
230 return trace_disable_link && TRACE_is_enabled();
233 bool TRACE_disable_speed()
235 return trace_disable_power && TRACE_is_enabled();
240 return trace_buffer && TRACE_is_enabled();
243 bool TRACE_disable_destroy ()
245 return trace_disable_destroy && TRACE_is_enabled();
250 return trace_basic && TRACE_is_enabled();
253 bool TRACE_display_sizes ()
255 return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
258 std::string TRACE_get_comment()
260 return xbt_cfg_get_string(OPT_TRACING_COMMENT);
263 std::string TRACE_get_comment_file()
265 return xbt_cfg_get_string(OPT_TRACING_COMMENT_FILE);
268 int TRACE_precision ()
270 return xbt_cfg_get_int(OPT_TRACING_PRECISION);
273 std::string TRACE_get_filename()
275 return xbt_cfg_get_string(OPT_TRACING_FILENAME);
278 void TRACE_global_init()
280 static bool is_initialised = false;
284 is_initialised = true;
285 /* name of the tracefile */
286 xbt_cfg_register_string (OPT_TRACING_FILENAME, "simgrid.trace", nullptr, "Trace file created by the instrumented SimGrid.");
287 xbt_cfg_register_boolean(OPT_TRACING, "no", nullptr, "Enable Tracing.");
288 xbt_cfg_register_boolean(OPT_TRACING_PLATFORM, "no", nullptr, "Register the platform in the trace as a hierarchy.");
289 xbt_cfg_register_boolean(OPT_TRACING_TOPOLOGY, "yes", nullptr, "Register the platform topology in the trace as a graph.");
290 xbt_cfg_register_boolean(OPT_TRACING_SMPI, "no", nullptr, "Tracing of the SMPI interface.");
291 xbt_cfg_register_boolean(OPT_TRACING_SMPI_GROUP,"no", nullptr, "Group MPI processes by host.");
292 xbt_cfg_register_boolean(OPT_TRACING_SMPI_COMPUTING, "no", nullptr, "Generate states for timing out of SMPI parts of the application");
293 xbt_cfg_register_boolean(OPT_TRACING_SMPI_SLEEPING, "no", nullptr, "Generate states for timing out of SMPI parts of the application");
294 xbt_cfg_register_boolean(OPT_TRACING_SMPI_INTERNALS, "no", nullptr, "View internal messages sent by Collective communications in SMPI");
295 xbt_cfg_register_boolean(OPT_TRACING_CATEGORIZED, "no", nullptr, "Tracing categorized resource utilization of hosts and links.");
296 xbt_cfg_register_boolean(OPT_TRACING_UNCATEGORIZED, "no", nullptr, "Tracing uncategorized resource utilization of hosts and links.");
298 xbt_cfg_register_boolean(OPT_TRACING_ACTOR, "no", nullptr, "Tracing of actor behavior.");
299 xbt_cfg_register_boolean(OPT_TRACING_VM, "no", nullptr, "Tracing of virtual machine behavior.");
300 xbt_cfg_register_boolean(OPT_TRACING_DISABLE_LINK, "no", nullptr, "Do not trace link bandwidth and latency.");
301 xbt_cfg_register_boolean(OPT_TRACING_DISABLE_POWER, "no", nullptr, "Do not trace host power.");
302 xbt_cfg_register_boolean(OPT_TRACING_BUFFER, "yes", nullptr, "Buffer trace events to put them in temporal order.");
304 xbt_cfg_register_boolean(OPT_TRACING_DISABLE_DESTROY, "no", nullptr, "Disable platform containers destruction.");
305 xbt_cfg_register_boolean(OPT_TRACING_BASIC, "no", nullptr, "Avoid extended events (impoverished trace file).");
306 xbt_cfg_register_boolean(OPT_TRACING_DISPLAY_SIZES, "no", nullptr, "(smpi only) Extended events with message size information");
307 xbt_cfg_register_string(OPT_TRACING_FORMAT, "Paje", nullptr, "(smpi only) Switch the output format of Tracing");
308 xbt_cfg_register_boolean(OPT_TRACING_FORMAT_TI_ONEFILE, "no", nullptr, "(smpi only) For replay format only : output to one file only");
309 xbt_cfg_register_string(OPT_TRACING_COMMENT, "", nullptr, "Comment to be added on the top of the trace file.");
310 xbt_cfg_register_string(OPT_TRACING_COMMENT_FILE, "", nullptr,
311 "The contents of the file are added to the top of the trace file as comment.");
312 xbt_cfg_register_int(OPT_TRACING_PRECISION, 6, nullptr, "Numerical precision used when timestamping events "
313 "(expressed in number of digits after decimal point)");
315 simgrid::config::alias(OPT_TRACING_COMMENT_FILE, {"tracing/comment_file"});
316 simgrid::config::alias(OPT_TRACING_DISABLE_DESTROY, {"tracing/disable_destroy"});
317 simgrid::config::alias(OPT_TRACING_DISABLE_LINK, {"tracing/disable_link"});
318 simgrid::config::alias(OPT_TRACING_DISABLE_POWER, {"tracing/disable_power"});
319 simgrid::config::alias(OPT_TRACING_DISPLAY_SIZES, {"tracing/smpi/display_sizes"});
320 simgrid::config::alias(OPT_TRACING_FORMAT_TI_ONEFILE, {"tracing/smpi/format/ti_one_file"});
322 /* instrumentation can be considered configured now */
323 trace_configured = true;
326 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
328 std::string str = std::string("--cfg=") + option + " ";
330 int len = str.size();
331 printf("%s%*.*s %s\n", str.c_str(), 30 - len, 30 - len, "", desc);
332 if (longdesc != nullptr && detailed){
333 printf ("%s\n\n", longdesc);
337 void TRACE_help (int detailed)
339 printf("Description of the tracing options accepted by this simulator:\n\n");
340 print_line (OPT_TRACING, "Enable the tracing system",
341 " It activates the tracing system and register the simulation platform\n"
342 " in the trace file. You have to enable this option to others take effect.", detailed);
343 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
344 " It activates the categorized resource utilization tracing. It should\n"
345 " be enabled if tracing categories are used by this simulator.", detailed);
346 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
347 " It activates the uncategorized resource utilization tracing. Use it if\n"
348 " this simulator do not use tracing categories and resource use have to be\n"
349 " traced.", detailed);
350 print_line(OPT_TRACING_FILENAME, "Filename to register traces",
351 " A file with this name will be created to register the simulation. The file\n"
352 " is in the Paje format and can be analyzed using Paje, and PajeNG visualization\n"
353 " tools. More information can be found in these webpages:\n"
354 " http://github.com/schnorr/pajeng/\n"
355 " http://paje.sourceforge.net/",
357 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
358 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
359 " interface and generates a trace that can be analyzed using Gantt-like\n"
360 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
361 " state, and point-to-point communications can be analyzed with arrows.", detailed);
362 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
363 " This option only has effect if this simulator is SMPI-based. The processes\n"
364 " are grouped by the hosts where they were executed.", detailed);
365 print_line (OPT_TRACING_SMPI_COMPUTING, "Generates a \" Computing \" State",
366 " This option aims at tracing computations in the application, outside SMPI\n"
367 " to allow further study of simulated or real computation time", detailed);
368 print_line (OPT_TRACING_SMPI_SLEEPING, "Generates a \" Sleeping \" State",
369 " This option aims at tracing sleeps in the application, outside SMPI\n"
370 " to allow further study of simulated or real sleep time", detailed);
371 print_line (OPT_TRACING_SMPI_INTERNALS, "Generates tracing events corresponding",
372 " to point-to-point messages sent by collective communications", detailed);
373 print_line(OPT_TRACING_ACTOR, "Trace actor behavior",
374 " This option traces the behavior of all categorized actors, grouping them\n"
375 " by hosts. This option can be used to track actor location if the simulator\n"
376 " does actor migration.",
378 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
379 " This option put some events in a time-ordered buffer using the insertion\n"
380 " sort algorithm. The process of acquiring and releasing locks to access this\n"
381 " buffer and the cost of the sorting algorithm make this process slow. The\n"
382 " simulator performance can be severely impacted if this option is activated,\n"
383 " but you are sure to get a trace file with events sorted.", detailed);
384 print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
385 " Disable the destruction of containers at the end of simulation. This can be\n"
386 " used with simulators that have a different notion of time (different from\n"
387 " the simulated time).", detailed);
388 print_line (OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
389 " Some visualization tools are not able to parse correctly the Paje file format.\n"
390 " Use this option if you are using one of these tools to visualize the simulation\n"
391 " trace. Keep in mind that the trace might be incomplete, without all the\n"
392 " information that would be registered otherwise.", detailed);
393 print_line (OPT_TRACING_DISPLAY_SIZES, "Only works for SMPI now. Add message size information",
394 " Message size (in bytes) is added to links, and to states. For collectives,\n"
395 " the displayed value is the more relevant to the collective (total sent by\n"
396 " the process, usually)", detailed);
397 print_line (OPT_TRACING_FORMAT, "Only works for SMPI now. Switch output format",
398 " Default format is Paje. Time independent traces are also supported,\n"
399 " to output traces that can later be used by the trace replay tool", detailed);
400 print_line (OPT_TRACING_FORMAT_TI_ONEFILE, "Only works for SMPI now, and TI output format",
401 " By default, each process outputs to a separate file, inside a filename_files folder\n"
402 " By setting this option to yes, all processes will output to only one file\n"
403 " This is meant to avoid opening thousands of files with large simulations", detailed);
404 print_line (OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
405 " Use this to add a comment line to the top of the trace file.", detailed);
406 print_line (OPT_TRACING_COMMENT_FILE, "File contents added to trace file as comment.",
407 " Use this to add the contents of a file to the top of the trace file as comment.", detailed);
408 print_line (OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
409 " This option (enabled by default) can be used to disable the tracing of\n"
410 " the platform topology in the trace file. Sometimes, such task is really\n"
411 " time consuming, since it must get the route from each host to other hosts\n"
412 " within the same Autonomous System (AS).", detailed);