Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Comment unused function parameters.
[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 "simgrid/s4u/Engine.hpp"
8 #include "src/instr/instr_private.hpp"
9 #include "surf/surf.hpp"
10 #include "xbt/virtu.h" /* sg_cmdline */
11 #include <fstream>
12 #include <string>
13 #include <vector>
14
15 XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)");
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
17
18 std::ofstream tracing_file;
19
20 #define OPT_TRACING_BASIC                "tracing/basic"
21 #define OPT_TRACING_COMMENT_FILE         "tracing/comment-file"
22 #define OPT_TRACING_DISABLE_DESTROY      "tracing/disable-destroy"
23 #define OPT_TRACING_FORMAT_TI_ONEFILE    "tracing/smpi/format/ti-one-file"
24 #define OPT_TRACING_SMPI_INTERNALS       "tracing/smpi/internals"
25 #define OPT_TRACING_SMPI                 "tracing/smpi"
26 #define OPT_TRACING_TOPOLOGY             "tracing/platform/topology"
27
28 static simgrid::config::Flag<bool> trace_enabled{
29     "tracing", "Enable the tracing system. You have to enable this option to use other tracing options.", false};
30
31 static simgrid::config::Flag<bool> trace_actor_enabled{
32     "tracing/msg/process", // FIXME rename this flag
33     "Trace the behavior of all categorized actors, grouping them by host. "
34     "Can be used to track actor location if the simulator does actor migration.",
35     false};
36
37 static simgrid::config::Flag<bool> trace_vm_enabled{"tracing/vm", "Trace the behavior of all virtual machines.", false};
38
39 static simgrid::config::Flag<bool> trace_platform{"tracing/platform",
40                                                   "Register the platform in the trace as a hierarchy.", false};
41
42 static simgrid::config::Flag<bool> trace_platform_topology{
43     OPT_TRACING_TOPOLOGY, "Register the platform topology in the trace as a graph.", true};
44 static simgrid::config::Flag<bool> trace_smpi_enabled{OPT_TRACING_SMPI, "Tracing of the SMPI interface.", false};
45 static simgrid::config::Flag<bool> trace_smpi_grouped{"tracing/smpi/group", "Group MPI processes by host.", false};
46
47 static simgrid::config::Flag<bool> trace_smpi_computing{
48     "tracing/smpi/computing", "Generate 'Computing' states to trace the out-of-SMPI parts of the application", false};
49
50 static simgrid::config::Flag<bool> trace_smpi_sleeping{
51     "tracing/smpi/sleeping", "Generate 'Sleeping' states for the sleeps in the application that do not pertain to SMPI",
52     false};
53
54 static simgrid::config::Flag<bool> trace_view_internals{
55     "tracing/smpi/internals",
56     "Generate tracing events corresponding to point-to-point messages sent by SMPI collective communications", false};
57
58 static simgrid::config::Flag<bool> trace_categorized{
59     "tracing/categorized", "Trace categorized resource utilization of hosts and links.", false};
60
61 static simgrid::config::Flag<bool> trace_uncategorized{
62     "tracing/uncategorized",
63     "Trace uncategorized resource utilization of hosts and links. "
64     "To use if the simulator does not use tracing categories but resource utilization have to be traced.",
65     false};
66
67 static simgrid::config::Flag<bool> trace_disable_destroy{
68     OPT_TRACING_DISABLE_DESTROY, {"tracing/disable_destroy"}, "Disable platform containers destruction.", false};
69 static simgrid::config::Flag<bool> trace_basic{OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
70                                                false};
71
72 static simgrid::config::Flag<bool> trace_display_sizes{
73     "tracing/smpi/display-sizes",
74     "Add message size information (in bytes) to the to links and states (SMPI only). "
75     "For collectives, it usually corresponds to the total number of bytes sent by a process.",
76     false};
77
78 static simgrid::config::Flag<bool> trace_disable_link{"tracing/disable_link",
79                                                       "Do not trace link bandwidth and latency.", false};
80 static simgrid::config::Flag<bool> trace_disable_power{"tracing/disable_power", "Do not trace host power.", false};
81
82 static bool trace_active     = false;
83
84 simgrid::instr::TraceFormat simgrid::instr::trace_format = simgrid::instr::TraceFormat::Paje;
85
86 static void TRACE_start()
87 {
88   if (trace_active)
89     return;
90
91   // tracing system must be:
92   //    - enabled (with --cfg=tracing:yes)
93   //    - already configured (TRACE_global_init already called)
94   if (TRACE_is_enabled()) {
95     instr_define_callbacks();
96
97     XBT_DEBUG("Tracing starts");
98     /* init the tracing module to generate the right output */
99     std::string format = simgrid::config::get_value<std::string>("tracing/smpi/format");
100     XBT_DEBUG("Tracing format %s", format.c_str());
101
102     /* open the trace file(s) */
103     std::string filename = TRACE_get_filename();
104     tracing_file.open(filename.c_str(), std::ofstream::out);
105     if (tracing_file.fail()) {
106       THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
107     }
108
109     XBT_DEBUG("Filename %s is open for writing", filename.c_str());
110
111     if (format == "Paje") {
112       /* output generator version */
113       tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR
114                    << "." << SIMGRID_VERSION_PATCH << std::endl;
115       tracing_file << "#[";
116       unsigned int cpt;
117       char* str;
118       xbt_dynar_foreach (xbt_cmdline, cpt, str) {
119         tracing_file << str << " ";
120       }
121       tracing_file << "]" << std::endl;
122     }
123
124     /* output one line comment */
125     dump_comment(simgrid::config::get_value<std::string>("tracing/comment"));
126
127     /* output comment file */
128     dump_comment_file(simgrid::config::get_value<std::string>(OPT_TRACING_COMMENT_FILE));
129
130     if (format == "Paje") {
131       /* output Pajé header */
132       TRACE_header(TRACE_basic(), TRACE_display_sizes());
133     } else
134       simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
135
136     trace_active = true;
137     XBT_DEBUG("Tracing is on");
138   }
139 }
140
141 static void TRACE_end()
142 {
143   if (not trace_active)
144     return;
145
146   /* dump trace buffer */
147   TRACE_last_timestamp_to_dump = surf_get_clock();
148   TRACE_paje_dump_buffer(true);
149
150   simgrid::instr::Type* root_type = simgrid::instr::Container::get_root()->type_;
151   /* destroy all data structures of tracing (and free) */
152   delete simgrid::instr::Container::get_root();
153   delete root_type;
154
155   /* close the trace files */
156   tracing_file.close();
157   XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
158
159   /* de-activate trace */
160   trace_active = false;
161   XBT_DEBUG("Tracing is off");
162   XBT_DEBUG("Tracing system is shutdown");
163 }
164
165 bool TRACE_needs_platform ()
166 {
167   return TRACE_actor_is_enabled() || TRACE_vm_is_enabled() || TRACE_categorized() || TRACE_uncategorized() ||
168          TRACE_platform() || (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
169 }
170
171 bool TRACE_is_enabled()
172 {
173   return trace_enabled;
174 }
175
176 bool TRACE_platform()
177 {
178   return trace_platform;
179 }
180
181 bool TRACE_platform_topology()
182 {
183   return trace_platform_topology;
184 }
185
186 bool TRACE_smpi_is_enabled()
187 {
188   return (trace_smpi_enabled || TRACE_smpi_is_grouped()) && TRACE_is_enabled();
189 }
190
191 bool TRACE_smpi_is_grouped()
192 {
193   return trace_smpi_grouped;
194 }
195
196 bool TRACE_smpi_is_computing()
197 {
198   return trace_smpi_computing;
199 }
200
201 bool TRACE_smpi_is_sleeping()
202 {
203   return trace_smpi_sleeping;
204 }
205
206 bool TRACE_smpi_view_internals()
207 {
208   return trace_view_internals;
209 }
210
211 bool TRACE_categorized ()
212 {
213   return trace_categorized;
214 }
215
216 bool TRACE_uncategorized ()
217 {
218   return trace_uncategorized;
219 }
220
221 bool TRACE_actor_is_enabled()
222 {
223   return trace_actor_enabled && trace_enabled;
224 }
225
226 bool TRACE_vm_is_enabled()
227 {
228   return trace_vm_enabled && trace_enabled;
229 }
230
231 bool TRACE_disable_link()
232 {
233   return trace_disable_link && trace_enabled;
234 }
235
236 bool TRACE_disable_speed()
237 {
238   return trace_disable_power && trace_enabled;
239 }
240
241 bool TRACE_disable_destroy ()
242 {
243   return trace_disable_destroy && trace_enabled;
244 }
245
246 bool TRACE_basic ()
247 {
248   return trace_basic && trace_enabled;
249 }
250
251 bool TRACE_display_sizes ()
252 {
253   return trace_display_sizes && trace_smpi_enabled && trace_enabled;
254 }
255
256 int TRACE_precision ()
257 {
258   return simgrid::config::get_value<int>("tracing/precision");
259 }
260
261 std::string TRACE_get_filename()
262 {
263   return simgrid::config::get_value<std::string>("tracing/filename");
264 }
265
266 void TRACE_global_init()
267 {
268   static bool is_initialised = false;
269   if (is_initialised)
270     return;
271
272   is_initialised = true;
273
274   /* name of the tracefile */
275   simgrid::config::declare_flag<std::string>("tracing/filename", "Trace file created by the instrumented SimGrid.",
276                                              "simgrid.trace");
277   simgrid::config::declare_flag<std::string>(
278       "tracing/smpi/format", "Select trace output format used by SMPI. The default is the 'Paje' format. "
279                              "The 'TI' (Time-Independent) format allows for trace replay.",
280       "Paje");
281
282   simgrid::config::declare_flag<bool>(OPT_TRACING_FORMAT_TI_ONEFILE,
283                                       "(smpi only) For replay format only : output to one file only", false);
284   simgrid::config::alias(OPT_TRACING_FORMAT_TI_ONEFILE, {"tracing/smpi/format/ti_one_file"});
285   simgrid::config::declare_flag<std::string>("tracing/comment", "Add a comment line to the top of the trace file.", "");
286   simgrid::config::declare_flag<std::string>(OPT_TRACING_COMMENT_FILE,
287                                              "Add the contents of a file as comments to the top of the trace.", "");
288   simgrid::config::alias(OPT_TRACING_COMMENT_FILE, {"tracing/comment_file"});
289   simgrid::config::declare_flag<int>("tracing/precision", "Numerical precision used when timestamping events "
290                                                           "(expressed in number of digits after decimal point)",
291                                      6);
292
293   /* Connect callbacks */
294   simgrid::s4u::on_platform_creation.connect(TRACE_start);
295   simgrid::s4u::on_deadlock.connect(TRACE_end);
296   simgrid::s4u::on_simulation_end.connect(TRACE_end);
297 }
298
299 static void print_line(const char* option, const char* desc, const char* longdesc)
300 {
301   std::string str = std::string("--cfg=") + option + " ";
302
303   int len = str.size();
304   printf("%s%*.*s %s\n", str.c_str(), 30 - len, 30 - len, "", desc);
305   if (longdesc != nullptr) {
306     printf ("%s\n\n", longdesc);
307   }
308 }
309
310 void TRACE_help()
311 {
312   printf("Description of the tracing options accepted by this simulator:\n\n");
313   print_line(OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
314              "  This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
315              "  interface and generates a trace that can be analyzed using Gantt-like\n"
316              "  visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
317              "  state, and point-to-point communications can be analyzed with arrows.");
318   print_line(OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
319              "  Disable the destruction of containers at the end of simulation. This can be\n"
320              "  used with simulators that have a different notion of time (different from\n"
321              "  the simulated time).");
322   print_line(OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
323              "  Some visualization tools are not able to parse correctly the Paje file format.\n"
324              "  Use this option if you are using one of these tools to visualize the simulation\n"
325              "  trace. Keep in mind that the trace might be incomplete, without all the\n"
326              "  information that would be registered otherwise.");
327   print_line(OPT_TRACING_FORMAT_TI_ONEFILE, "Only works for SMPI now, and TI output format",
328              "  By default, each process outputs to a separate file, inside a filename_files folder\n"
329              "  By setting this option to yes, all processes will output to only one file\n"
330              "  This is meant to avoid opening thousands of files with large simulations");
331   print_line(OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
332              "  This option (enabled by default) can be used to disable the tracing of\n"
333              "  the platform topology in the trace file. Sometimes, such task is really\n"
334              "  time consuming, since it must get the route from each host to other hosts\n"
335              "  within the same Autonomous System (AS).");
336 }