Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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_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"
39
40 static simgrid::config::Flag<bool> trace_enabled{OPT_TRACING, "Enable Tracing.", false};
41 static simgrid::config::Flag<bool> trace_platform{OPT_TRACING_PLATFORM,
42                                                   "Register the platform in the trace as a hierarchy.", false};
43 static simgrid::config::Flag<bool> trace_platform_topology{
44     OPT_TRACING_TOPOLOGY, "Register the platform topology in the trace as a graph.", true};
45 static simgrid::config::Flag<bool> trace_smpi_enabled{OPT_TRACING_SMPI, "Tracing of the SMPI interface.", false};
46 static simgrid::config::Flag<bool> trace_smpi_grouped{OPT_TRACING_SMPI_GROUP, "Group MPI processes by host.", false};
47 static simgrid::config::Flag<bool> trace_smpi_computing{
48     OPT_TRACING_SMPI_COMPUTING, "Generate states for timing out of SMPI parts of the application", false};
49 static simgrid::config::Flag<bool> trace_smpi_sleeping{
50     OPT_TRACING_SMPI_SLEEPING, "Generate states for timing out of SMPI parts of the application", false};
51 static simgrid::config::Flag<bool> trace_view_internals{
52     OPT_TRACING_SMPI_INTERNALS, "View internal messages sent by Collective communications in SMPI", false};
53 static simgrid::config::Flag<bool> trace_categorized{
54     OPT_TRACING_CATEGORIZED, "Tracing categorized resource utilization of hosts and links.", false};
55 static simgrid::config::Flag<bool> trace_uncategorized{
56     OPT_TRACING_UNCATEGORIZED, "Tracing uncategorized resource utilization of hosts and links.", false};
57 static simgrid::config::Flag<bool> trace_actor_enabled{OPT_TRACING_ACTOR, "Tracing of actor behavior.", false};
58 static simgrid::config::Flag<bool> trace_vm_enabled{OPT_TRACING_VM, "Tracing of virtual machine behavior.", false};
59 static simgrid::config::Flag<bool> trace_buffer{OPT_TRACING_BUFFER,
60                                                 "Buffer trace events to put them in temporal order.", true};
61 static simgrid::config::Flag<bool> trace_disable_destroy{
62     OPT_TRACING_DISABLE_DESTROY, {"tracing/disable_destroy"}, "Disable platform containers destruction.", false};
63 static simgrid::config::Flag<bool> trace_basic{OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
64                                                false};
65 static simgrid::config::Flag<bool> trace_display_sizes{OPT_TRACING_DISPLAY_SIZES,
66                                                        {"tracing/smpi/display_sizes"},
67                                                        "(smpi only) Extended events with message size information",
68                                                        false};
69 static simgrid::config::Flag<bool> trace_disable_link{
70     OPT_TRACING_DISABLE_LINK, {"tracing/disable_link"}, "Do not trace link bandwidth and latency.", false};
71 static simgrid::config::Flag<bool> trace_disable_power{
72     OPT_TRACING_DISABLE_POWER, {"tracing/disable_power"}, "Do not trace host power.", false};
73
74 static bool trace_active     = false;
75
76 simgrid::instr::TraceFormat simgrid::instr::trace_format = simgrid::instr::TraceFormat::Paje;
77
78 int TRACE_start()
79 {
80   // tracing system must be:
81   //    - enabled (with --cfg=tracing:yes)
82   //    - already configured (TRACE_global_init already called)
83   if (TRACE_is_enabled()) {
84     instr_routing_define_callbacks();
85
86     XBT_DEBUG("Tracing starts");
87     /* init the tracing module to generate the right output */
88
89     /* open the trace file(s) */
90     std::string format = simgrid::config::get_value<std::string>(OPT_TRACING_FORMAT);
91     XBT_DEBUG("Tracing format %s\n", format.c_str());
92     if (format == "Paje") {
93       TRACE_paje_start();
94     } else if (format == "TI") {
95       simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
96       TRACE_TI_start();
97     }else{
98       xbt_die("Unknown trace format :%s ", format.c_str());
99     }
100
101     /* activate trace */
102     if (trace_active) {
103       THROWF(tracing_error, 0, "Tracing is already active");
104     }
105     trace_active = true;
106     XBT_DEBUG("Tracing is on");
107   }
108   return 0;
109 }
110
111 int TRACE_end()
112 {
113   int retval;
114   if (not trace_active) {
115     retval = 1;
116   } else {
117     retval = 0;
118
119     /* dump trace buffer */
120     TRACE_last_timestamp_to_dump = surf_get_clock();
121     TRACE_paje_dump_buffer(true);
122
123     simgrid::instr::Type* root_type = simgrid::instr::Container::getRoot()->type_;
124     /* destroy all data structures of tracing (and free) */
125     delete simgrid::instr::Container::getRoot();
126     delete root_type;
127
128     /* close the trace files */
129     std::string format = simgrid::config::get_value<std::string>(OPT_TRACING_FORMAT);
130     XBT_DEBUG("Tracing format %s\n", format.c_str());
131     if (format == "Paje") {
132       TRACE_paje_end();
133     } else if (format == "TI") {
134       TRACE_TI_end();
135     }else{
136       xbt_die("Unknown trace format :%s ", format.c_str());
137     }
138
139     /* de-activate trace */
140     trace_active = false;
141     XBT_DEBUG("Tracing is off");
142     XBT_DEBUG("Tracing system is shutdown");
143   }
144   return retval;
145 }
146
147 bool TRACE_needs_platform ()
148 {
149   return TRACE_actor_is_enabled() || TRACE_vm_is_enabled() || TRACE_categorized() || TRACE_uncategorized() ||
150          TRACE_platform() || (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
151 }
152
153 bool TRACE_is_enabled()
154 {
155   return trace_enabled;
156 }
157
158 bool TRACE_platform()
159 {
160   return trace_platform;
161 }
162
163 bool TRACE_platform_topology()
164 {
165   return trace_platform_topology;
166 }
167
168 bool TRACE_smpi_is_enabled()
169 {
170   return (trace_smpi_enabled || TRACE_smpi_is_grouped()) && TRACE_is_enabled();
171 }
172
173 bool TRACE_smpi_is_grouped()
174 {
175   return trace_smpi_grouped;
176 }
177
178 bool TRACE_smpi_is_computing()
179 {
180   return trace_smpi_computing;
181 }
182
183 bool TRACE_smpi_is_sleeping()
184 {
185   return trace_smpi_sleeping;
186 }
187
188 bool TRACE_smpi_view_internals()
189 {
190   return trace_view_internals;
191 }
192
193 bool TRACE_categorized ()
194 {
195   return trace_categorized;
196 }
197
198 bool TRACE_uncategorized ()
199 {
200   return trace_uncategorized;
201 }
202
203 bool TRACE_actor_is_enabled()
204 {
205   return trace_actor_enabled && trace_enabled;
206 }
207
208 bool TRACE_vm_is_enabled()
209 {
210   return trace_vm_enabled && trace_enabled;
211 }
212
213 bool TRACE_disable_link()
214 {
215   return trace_disable_link && trace_enabled;
216 }
217
218 bool TRACE_disable_speed()
219 {
220   return trace_disable_power && trace_enabled;
221 }
222
223 bool TRACE_buffer ()
224 {
225   return trace_buffer && trace_enabled;
226 }
227
228 bool TRACE_disable_destroy ()
229 {
230   return trace_disable_destroy && trace_enabled;
231 }
232
233 bool TRACE_basic ()
234 {
235   return trace_basic && trace_enabled;
236 }
237
238 bool TRACE_display_sizes ()
239 {
240   return trace_display_sizes && trace_smpi_enabled && trace_enabled;
241 }
242
243 std::string TRACE_get_comment()
244 {
245   return simgrid::config::get_value<std::string>(OPT_TRACING_COMMENT);
246 }
247
248 std::string TRACE_get_comment_file()
249 {
250   return simgrid::config::get_value<std::string>(OPT_TRACING_COMMENT_FILE);
251 }
252
253 int TRACE_precision ()
254 {
255   return simgrid::config::get_value<int>(OPT_TRACING_PRECISION);
256 }
257
258 std::string TRACE_get_filename()
259 {
260   return simgrid::config::get_value<std::string>(OPT_TRACING_FILENAME);
261 }
262
263 void TRACE_global_init()
264 {
265   static bool is_initialised = false;
266   if (is_initialised)
267     return;
268
269   is_initialised = true;
270   /* name of the tracefile */
271   simgrid::config::declare_flag<std::string>(OPT_TRACING_FILENAME, "Trace file created by the instrumented SimGrid.",
272                                              "simgrid.trace");
273   simgrid::config::declare_flag<std::string>(OPT_TRACING_FORMAT, "(smpi only) Switch the output format of Tracing",
274                                              "Paje");
275   simgrid::config::declare_flag<bool>(OPT_TRACING_FORMAT_TI_ONEFILE,
276                                       "(smpi only) For replay format only : output to one file only", false);
277   simgrid::config::alias(OPT_TRACING_FORMAT_TI_ONEFILE, {"tracing/smpi/format/ti_one_file"});
278   simgrid::config::declare_flag<std::string>(OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
279                                              "");
280   simgrid::config::declare_flag<std::string>(
281       OPT_TRACING_COMMENT_FILE, "The contents of the file are added to the top of the trace file as comment.", "");
282   simgrid::config::alias(OPT_TRACING_COMMENT_FILE, {"tracing/comment_file"});
283   simgrid::config::declare_flag<int>(OPT_TRACING_PRECISION, "Numerical precision used when timestamping events "
284                                                             "(expressed in number of digits after decimal point)",
285                                      6);
286 }
287
288 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
289 {
290   std::string str = std::string("--cfg=") + option + " ";
291
292   int len = str.size();
293   printf("%s%*.*s %s\n", str.c_str(), 30 - len, 30 - len, "", desc);
294   if (longdesc != nullptr && detailed){
295     printf ("%s\n\n", longdesc);
296   }
297 }
298
299 void TRACE_help (int detailed)
300 {
301   printf("Description of the tracing options accepted by this simulator:\n\n");
302   print_line (OPT_TRACING, "Enable the tracing system",
303       "  It activates the tracing system and register the simulation platform\n"
304       "  in the trace file. You have to enable this option to others take effect.", detailed);
305   print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
306       "  It activates the categorized resource utilization tracing. It should\n"
307       "  be enabled if tracing categories are used by this simulator.", detailed);
308   print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
309       "  It activates the uncategorized resource utilization tracing. Use it if\n"
310       "  this simulator do not use tracing categories and resource use have to be\n"
311       "  traced.", detailed);
312   print_line(OPT_TRACING_FILENAME, "Filename to register traces",
313              "  A file with this name will be created to register the simulation. The file\n"
314              "  is in the Paje format and can be analyzed using Paje, and PajeNG visualization\n"
315              "  tools. More information can be found in these webpages:\n"
316              "     http://github.com/schnorr/pajeng/\n"
317              "     http://paje.sourceforge.net/",
318              detailed);
319   print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
320       "  This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
321       "  interface and generates a trace that can be analyzed using Gantt-like\n"
322       "  visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
323       "  state, and point-to-point communications can be analyzed with arrows.", detailed);
324   print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
325       "  This option only has effect if this simulator is SMPI-based. The processes\n"
326       "  are grouped by the hosts where they were executed.", detailed);
327   print_line (OPT_TRACING_SMPI_COMPUTING, "Generates a \" Computing \" State",
328       "  This option aims at tracing computations in the application, outside SMPI\n"
329       "  to allow further study of simulated or real computation time", detailed);
330    print_line (OPT_TRACING_SMPI_SLEEPING, "Generates a \" Sleeping \" State",
331       "  This option aims at tracing sleeps in the application, outside SMPI\n"
332       "  to allow further study of simulated or real sleep time", detailed);
333   print_line (OPT_TRACING_SMPI_INTERNALS, "Generates tracing events corresponding",
334       "  to point-to-point messages sent by collective communications", detailed);
335   print_line(OPT_TRACING_ACTOR, "Trace actor behavior",
336              "  This option traces the behavior of all categorized actors, grouping them\n"
337              "  by hosts. This option can be used to track actor location if the simulator\n"
338              "  does actor migration.",
339              detailed);
340   print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
341       "  This option put some events in a time-ordered buffer using the insertion\n"
342       "  sort algorithm. The process of acquiring and releasing locks to access this\n"
343       "  buffer and the cost of the sorting algorithm make this process slow. The\n"
344       "  simulator performance can be severely impacted if this option is activated,\n"
345       "  but you are sure to get a trace file with events sorted.", detailed);
346   print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
347       "  Disable the destruction of containers at the end of simulation. This can be\n"
348       "  used with simulators that have a different notion of time (different from\n"
349       "  the simulated time).", detailed);
350   print_line (OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
351       "  Some visualization tools are not able to parse correctly the Paje file format.\n"
352       "  Use this option if you are using one of these tools to visualize the simulation\n"
353       "  trace. Keep in mind that the trace might be incomplete, without all the\n"
354       "  information that would be registered otherwise.", detailed);
355   print_line (OPT_TRACING_DISPLAY_SIZES, "Only works for SMPI now. Add message size information",
356       "  Message size (in bytes) is added to links, and to states. For collectives,\n"
357       "  the displayed value is the more relevant to the collective (total sent by\n"
358       "  the process, usually)", detailed);
359   print_line (OPT_TRACING_FORMAT, "Only works for SMPI now. Switch output format",
360       "  Default format is Paje. Time independent traces are also supported,\n"
361       "  to output traces that can later be used by the trace replay tool", detailed);
362   print_line (OPT_TRACING_FORMAT_TI_ONEFILE, "Only works for SMPI now, and TI output format",
363       "  By default, each process outputs to a separate file, inside a filename_files folder\n"
364       "  By setting this option to yes, all processes will output to only one file\n"
365       "  This is meant to avoid opening thousands of files with large simulations", detailed);
366   print_line (OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
367       "  Use this to add a comment line to the top of the trace file.", detailed);
368   print_line (OPT_TRACING_COMMENT_FILE, "File contents added to trace file as comment.",
369       "  Use this to add the contents of a file to the top of the trace file as comment.", detailed);
370   print_line (OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
371         "  This option (enabled by default) can be used to disable the tracing of\n"
372         "  the platform topology in the trace file. Sometimes, such task is really\n"
373         "  time consuming, since it must get the route from each host to other hosts\n"
374         "  within the same Autonomous System (AS).", detailed);
375 }