Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #202 from Takishipp/clear_fct
[simgrid.git] / src / instr / instr_config.cpp
1 /* Copyright (c) 2010-2015. 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 "surf/surf.h"
9 #include <vector>
10
11 XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)");
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
13
14 #define OPT_TRACING_BASIC                "tracing/basic"
15 #define OPT_TRACING_BUFFER               "tracing/buffer"
16 #define OPT_TRACING_CATEGORIZED          "tracing/categorized"
17 #define OPT_TRACING_COMMENT_FILE         "tracing/comment-file"
18 #define OPT_TRACING_COMMENT              "tracing/comment"
19 #define OPT_TRACING_DISABLE_DESTROY      "tracing/disable-destroy"
20 #define OPT_TRACING_DISABLE_LINK         "tracing/disable-link"
21 #define OPT_TRACING_DISABLE_POWER        "tracing/disable-power"
22 #define OPT_TRACING_DISPLAY_SIZES        "tracing/smpi/display-sizes"
23 #define OPT_TRACING_FILENAME             "tracing/filename"
24 #define OPT_TRACING_FORMAT_TI_ONEFILE    "tracing/smpi/format/ti-one-file"
25 #define OPT_TRACING_FORMAT               "tracing/smpi/format"
26 #define OPT_TRACING_MSG_PROCESS          "tracing/msg/process"
27 #define OPT_TRACING_MSG_VM               "tracing/msg/vm"
28 #define OPT_TRACING_ONELINK_ONLY         "tracing/onelink-only"
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 #define OPT_VIVA_CAT_CONF                "viva/categorized"
40 #define OPT_VIVA_UNCAT_CONF              "viva/uncategorized"
41
42 static bool trace_enabled = false;
43 static bool trace_platform;
44 static bool trace_platform_topology;
45 static bool trace_smpi_enabled;
46 static bool trace_smpi_grouped;
47 static bool trace_smpi_computing;
48 static bool trace_smpi_sleeping;
49 static bool trace_view_internals;
50 static bool trace_categorized;
51 static bool trace_uncategorized;
52 static bool trace_msg_process_enabled;
53 static bool trace_msg_vm_enabled;
54 static bool trace_buffer;
55 static bool trace_onelink_only;
56 static bool trace_disable_destroy;
57 static bool trace_basic;
58 static bool trace_display_sizes = false;
59 static bool trace_disable_link;
60 static bool trace_disable_power;
61 static int trace_precision;
62
63 static bool trace_configured = false;
64 static bool trace_active     = false;
65
66 static type_t rootType = nullptr;        /* the root type */
67
68 instr_fmt_type_t instr_fmt_type = instr_fmt_paje;
69
70 static void TRACE_getopts()
71 {
72   trace_enabled             = xbt_cfg_get_boolean(OPT_TRACING);
73   trace_platform            = xbt_cfg_get_boolean(OPT_TRACING_PLATFORM);
74   trace_platform_topology   = xbt_cfg_get_boolean(OPT_TRACING_TOPOLOGY);
75   trace_smpi_enabled        = xbt_cfg_get_boolean(OPT_TRACING_SMPI);
76   trace_smpi_grouped        = xbt_cfg_get_boolean(OPT_TRACING_SMPI_GROUP);
77   trace_smpi_computing      = xbt_cfg_get_boolean(OPT_TRACING_SMPI_COMPUTING);
78   trace_smpi_sleeping       = xbt_cfg_get_boolean(OPT_TRACING_SMPI_SLEEPING);
79   trace_view_internals      = xbt_cfg_get_boolean(OPT_TRACING_SMPI_INTERNALS);
80   trace_categorized         = xbt_cfg_get_boolean(OPT_TRACING_CATEGORIZED);
81   trace_uncategorized       = xbt_cfg_get_boolean(OPT_TRACING_UNCATEGORIZED);
82   trace_msg_process_enabled = xbt_cfg_get_boolean(OPT_TRACING_MSG_PROCESS);
83   trace_msg_vm_enabled      = xbt_cfg_get_boolean(OPT_TRACING_MSG_VM);
84   trace_buffer              = xbt_cfg_get_boolean(OPT_TRACING_BUFFER);
85   trace_onelink_only        = xbt_cfg_get_boolean(OPT_TRACING_ONELINK_ONLY);
86   trace_disable_destroy     = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_DESTROY);
87   trace_basic               = xbt_cfg_get_boolean(OPT_TRACING_BASIC);
88   trace_display_sizes       = xbt_cfg_get_boolean(OPT_TRACING_DISPLAY_SIZES);
89   trace_disable_link        = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_LINK);
90   trace_disable_power       = xbt_cfg_get_boolean(OPT_TRACING_DISABLE_POWER);
91   trace_precision           = xbt_cfg_get_int(OPT_TRACING_PRECISION);
92 }
93
94 int TRACE_start()
95 {
96   if (TRACE_is_configured())
97     TRACE_getopts();
98
99   // tracing system must be:
100   //    - enabled (with --cfg=tracing:yes)
101   //    - already configured (TRACE_global_init already called)
102   if (TRACE_is_enabled()) {
103
104     XBT_DEBUG("Tracing starts");
105     /* init the tracing module to generate the right output */
106
107     /* open the trace file(s) */
108     const char* format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
109     XBT_DEBUG("Tracing format %s\n", format);
110     if (not strcmp(format, "Paje")) {
111       TRACE_paje_start();
112     } else if (not strcmp(format, "TI")) {
113       instr_fmt_type = instr_fmt_TI;
114       TRACE_TI_start();
115     }else{
116       xbt_die("Unknown trace format :%s ", format);
117     }
118
119     /* activate trace */
120     if (trace_active == 1) {
121       THROWF(tracing_error, 0, "Tracing is already active");
122     }
123     trace_active = 1;
124     XBT_DEBUG("Tracing is on");
125
126     /* other trace initialization */
127     created_categories = xbt_dict_new_homogeneous(xbt_free_f);
128     declared_marks = xbt_dict_new_homogeneous(xbt_free_f);
129     user_host_variables = xbt_dict_new_homogeneous(xbt_free_f);
130     user_vm_variables = xbt_dict_new_homogeneous(xbt_free_f);
131     user_link_variables = xbt_dict_new_homogeneous(xbt_free_f);
132   }
133   return 0;
134 }
135
136 int TRACE_end()
137 {
138   int retval;
139   if (not trace_active) {
140     retval = 1;
141   } else {
142     retval = 0;
143
144     TRACE_generate_viva_uncat_conf();
145     TRACE_generate_viva_cat_conf();
146
147     /* dump trace buffer */
148     TRACE_last_timestamp_to_dump = surf_get_clock();
149     TRACE_paje_dump_buffer(1);
150
151     /* destroy all data structures of tracing (and free) */
152     PJ_container_free_all();
153     recursiveDestroyType (PJ_type_get_root());
154     PJ_container_release();
155     rootType = nullptr;
156
157     xbt_dict_free(&user_link_variables);
158     xbt_dict_free(&user_host_variables);
159     xbt_dict_free(&user_vm_variables);
160     xbt_dict_free(&declared_marks);
161     xbt_dict_free(&created_categories);
162
163     /* close the trace files */
164     const char* format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
165     XBT_DEBUG("Tracing format %s\n", format);
166     if (not strcmp(format, "Paje")) {
167       TRACE_paje_end();
168     } else if (not strcmp(format, "TI")) {
169       TRACE_TI_end();
170     }else{
171       xbt_die("Unknown trace format :%s ", format);
172     }
173
174     /* de-activate trace */
175     trace_active = 0;
176     XBT_DEBUG("Tracing is off");
177     XBT_DEBUG("Tracing system is shutdown");
178   }
179   return retval;
180 }
181
182 bool TRACE_needs_platform ()
183 {
184   return TRACE_msg_process_is_enabled() || TRACE_msg_vm_is_enabled() || TRACE_categorized() ||
185          TRACE_uncategorized() || TRACE_platform () || (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
186 }
187
188 bool TRACE_is_enabled()
189 {
190   return trace_enabled;
191 }
192
193 bool TRACE_platform()
194 {
195   return trace_platform;
196 }
197
198 bool TRACE_platform_topology()
199 {
200   return trace_platform_topology;
201 }
202
203 bool TRACE_is_configured()
204 {
205   return trace_configured;
206 }
207
208 bool TRACE_smpi_is_enabled()
209 {
210   return (trace_smpi_enabled || TRACE_smpi_is_grouped()) && TRACE_is_enabled();
211 }
212
213 bool TRACE_smpi_is_grouped()
214 {
215   return trace_smpi_grouped;
216 }
217
218 bool TRACE_smpi_is_computing()
219 {
220   return trace_smpi_computing;
221 }
222
223 bool TRACE_smpi_is_sleeping()
224 {
225   return trace_smpi_sleeping;
226 }
227
228 bool TRACE_smpi_view_internals()
229 {
230   return trace_view_internals;
231 }
232
233 bool TRACE_categorized ()
234 {
235   return trace_categorized;
236 }
237
238 bool TRACE_uncategorized ()
239 {
240   return trace_uncategorized;
241 }
242
243 bool TRACE_msg_process_is_enabled()
244 {
245   return trace_msg_process_enabled && TRACE_is_enabled();
246 }
247
248 bool TRACE_msg_vm_is_enabled()
249 {
250   return trace_msg_vm_enabled && TRACE_is_enabled();
251 }
252
253 bool TRACE_disable_link()
254 {
255   return trace_disable_link && TRACE_is_enabled();
256 }
257
258 bool TRACE_disable_speed()
259 {
260   return trace_disable_power && TRACE_is_enabled();
261 }
262
263 bool TRACE_buffer ()
264 {
265   return trace_buffer && TRACE_is_enabled();
266 }
267
268 bool TRACE_onelink_only ()
269 {
270   return trace_onelink_only && TRACE_is_enabled();
271 }
272
273 bool TRACE_disable_destroy ()
274 {
275   return trace_disable_destroy && TRACE_is_enabled();
276 }
277
278 bool TRACE_basic ()
279 {
280   return trace_basic && TRACE_is_enabled();
281 }
282
283 bool TRACE_display_sizes ()
284 {
285    return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
286 }
287
288 char *TRACE_get_comment ()
289 {
290   return xbt_cfg_get_string(OPT_TRACING_COMMENT);
291 }
292
293 char *TRACE_get_comment_file ()
294 {
295   return xbt_cfg_get_string(OPT_TRACING_COMMENT_FILE);
296 }
297
298 int TRACE_precision ()
299 {
300   return xbt_cfg_get_int(OPT_TRACING_PRECISION);
301 }
302
303 char *TRACE_get_filename()
304 {
305   return xbt_cfg_get_string(OPT_TRACING_FILENAME);
306 }
307
308 char *TRACE_get_viva_uncat_conf ()
309 {
310   return xbt_cfg_get_string(OPT_VIVA_UNCAT_CONF);
311 }
312
313 char *TRACE_get_viva_cat_conf ()
314 {
315   return xbt_cfg_get_string(OPT_VIVA_CAT_CONF);
316 }
317
318 void TRACE_global_init()
319 {
320   static int is_initialised = 0;
321   if (is_initialised)
322     return;
323
324   is_initialised = 1;
325   /* name of the tracefile */
326   xbt_cfg_register_string (OPT_TRACING_FILENAME, "simgrid.trace", nullptr, "Trace file created by the instrumented SimGrid.");
327   xbt_cfg_register_boolean(OPT_TRACING, "no", nullptr, "Enable Tracing.");
328   xbt_cfg_register_boolean(OPT_TRACING_PLATFORM, "no", nullptr, "Register the platform in the trace as a hierarchy.");
329   xbt_cfg_register_boolean(OPT_TRACING_TOPOLOGY, "yes", nullptr, "Register the platform topology in the trace as a graph.");
330   xbt_cfg_register_boolean(OPT_TRACING_SMPI, "no", nullptr, "Tracing of the SMPI interface.");
331   xbt_cfg_register_boolean(OPT_TRACING_SMPI_GROUP,"no", nullptr, "Group MPI processes by host.");
332   xbt_cfg_register_boolean(OPT_TRACING_SMPI_COMPUTING, "no", nullptr, "Generate states for timing out of SMPI parts of the application");
333   xbt_cfg_register_boolean(OPT_TRACING_SMPI_SLEEPING, "no", nullptr, "Generate states for timing out of SMPI parts of the application");
334   xbt_cfg_register_boolean(OPT_TRACING_SMPI_INTERNALS, "no", nullptr, "View internal messages sent by Collective communications in SMPI");
335   xbt_cfg_register_boolean(OPT_TRACING_CATEGORIZED, "no", nullptr, "Tracing categorized resource utilization of hosts and links.");
336   xbt_cfg_register_boolean(OPT_TRACING_UNCATEGORIZED, "no", nullptr, "Tracing uncategorized resource utilization of hosts and links.");
337
338   xbt_cfg_register_boolean(OPT_TRACING_MSG_PROCESS, "no", nullptr, "Tracing of MSG process behavior.");
339   xbt_cfg_register_boolean(OPT_TRACING_MSG_VM, "no", nullptr, "Tracing of MSG process behavior.");
340   xbt_cfg_register_boolean(OPT_TRACING_DISABLE_LINK, "no", nullptr, "Do not trace link bandwidth and latency.");
341   xbt_cfg_register_boolean(OPT_TRACING_DISABLE_POWER, "no", nullptr, "Do not trace host power.");
342   xbt_cfg_register_boolean(OPT_TRACING_BUFFER, "yes", nullptr, "Buffer trace events to put them in temporal order.");
343
344   xbt_cfg_register_boolean(OPT_TRACING_ONELINK_ONLY, "no", nullptr, "Use only routes with one link to trace platform.");
345   xbt_cfg_register_boolean(OPT_TRACING_DISABLE_DESTROY, "no", nullptr, "Disable platform containers destruction.");
346   xbt_cfg_register_boolean(OPT_TRACING_BASIC, "no", nullptr, "Avoid extended events (impoverished trace file).");
347   xbt_cfg_register_boolean(OPT_TRACING_DISPLAY_SIZES, "no", nullptr, "(smpi only) Extended events with message size information");
348   xbt_cfg_register_string(OPT_TRACING_FORMAT, "Paje", nullptr, "(smpi only) Switch the output format of Tracing");
349   xbt_cfg_register_boolean(OPT_TRACING_FORMAT_TI_ONEFILE, "no", nullptr, "(smpi only) For replay format only : output to one file only");
350   xbt_cfg_register_string(OPT_TRACING_COMMENT, "", nullptr, "Comment to be added on the top of the trace file.");
351   xbt_cfg_register_string(OPT_TRACING_COMMENT_FILE, "", nullptr,
352       "The contents of the file are added to the top of the trace file as comment.");
353   xbt_cfg_register_int(OPT_TRACING_PRECISION, 6, nullptr, "Numerical precision used when timestamping events "
354       "(expressed in number of digits after decimal point)");
355   /* Viva graph configuration for uncategorized tracing */
356   xbt_cfg_register_string(OPT_VIVA_UNCAT_CONF, "", nullptr, "Viva Graph configuration file for uncategorized resource utilization traces.");
357   xbt_cfg_register_string(OPT_VIVA_CAT_CONF, "", nullptr, "Viva Graph configuration file for categorized resource utilization traces.");
358
359   xbt_cfg_register_alias(OPT_TRACING_COMMENT_FILE,"tracing/comment_file");
360   xbt_cfg_register_alias(OPT_TRACING_DISABLE_DESTROY, "tracing/disable_destroy");
361   xbt_cfg_register_alias(OPT_TRACING_DISABLE_LINK, "tracing/disable_link");
362   xbt_cfg_register_alias(OPT_TRACING_DISABLE_POWER, "tracing/disable_power");
363   xbt_cfg_register_alias(OPT_TRACING_DISPLAY_SIZES, "tracing/smpi/display_sizes");
364   xbt_cfg_register_alias(OPT_TRACING_FORMAT_TI_ONEFILE, "tracing/smpi/format/ti_one_file");
365   xbt_cfg_register_alias(OPT_TRACING_ONELINK_ONLY, "tracing/onelink_only");
366
367   /* instrumentation can be considered configured now */
368   trace_configured = 1;
369 }
370
371 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
372 {
373   char str[INSTR_DEFAULT_STR_SIZE];
374   snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
375
376   int len = strlen (str);
377   printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
378   if (longdesc != nullptr && detailed){
379     printf ("%s\n\n", longdesc);
380   }
381 }
382
383 void TRACE_help (int detailed)
384 {
385   printf("Description of the tracing options accepted by this simulator:\n\n");
386   print_line (OPT_TRACING, "Enable the tracing system",
387       "  It activates the tracing system and register the simulation platform\n"
388       "  in the trace file. You have to enable this option to others take effect.", detailed);
389   print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
390       "  It activates the categorized resource utilization tracing. It should\n"
391       "  be enabled if tracing categories are used by this simulator.", detailed);
392   print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
393       "  It activates the uncategorized resource utilization tracing. Use it if\n"
394       "  this simulator do not use tracing categories and resource use have to be\n"
395       "  traced.", detailed);
396   print_line (OPT_TRACING_FILENAME, "Filename to register traces",
397       "  A file with this name will be created to register the simulation. The file\n"
398       "  is in the Paje format and can be analyzed using Viva, Paje, and PajeNG visualization\n"
399       "  tools. More information can be found in these webpages:\n"
400       "     http://github.com/schnorr/viva/\n"
401       "     http://github.com/schnorr/pajeng/\n"
402       "     http://paje.sourceforge.net/", detailed);
403   print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
404       "  This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
405       "  interface and generates a trace that can be analyzed using Gantt-like\n"
406       "  visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
407       "  state, and point-to-point communications can be analyzed with arrows.", detailed);
408   print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
409       "  This option only has effect if this simulator is SMPI-based. The processes\n"
410       "  are grouped by the hosts where they were executed.", detailed);
411   print_line (OPT_TRACING_SMPI_COMPUTING, "Generates a \" Computing \" State",
412       "  This option aims at tracing computations in the application, outside SMPI\n"
413       "  to allow further study of simulated or real computation time", detailed);
414    print_line (OPT_TRACING_SMPI_SLEEPING, "Generates a \" Sleeping \" State",
415       "  This option aims at tracing sleeps in the application, outside SMPI\n"
416       "  to allow further study of simulated or real sleep time", detailed);
417   print_line (OPT_TRACING_SMPI_INTERNALS, "Generates tracing events corresponding",
418       "  to point-to-point messages sent by collective communications", detailed);
419   print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
420       "  This option only has effect if this simulator is MSG-based. It traces the\n"
421       "  behavior of all categorized MSG processes, grouping them by hosts. This option\n"
422       "  can be used to track process location if this simulator has process migration.", detailed);
423   print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
424       "  This option put some events in a time-ordered buffer using the insertion\n"
425       "  sort algorithm. The process of acquiring and releasing locks to access this\n"
426       "  buffer and the cost of the sorting algorithm make this process slow. The\n"
427       "  simulator performance can be severely impacted if this option is activated,\n"
428       "  but you are sure to get a trace file with events sorted.", detailed);
429   print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
430       "  This option changes the way SimGrid register its platform on the trace file.\n"
431       "  Normally, the tracing considers all routes (no matter their size) on the\n"
432       "  platform file to re-create the resource topology. If this option is activated,\n"
433       "  only the routes with one link are used to register the topology within an AS.\n"
434       "  Routes among AS continue to be traced as usual.", detailed);
435   print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
436       "  Disable the destruction of containers at the end of simulation. This can be\n"
437       "  used with simulators that have a different notion of time (different from\n"
438       "  the simulated time).", detailed);
439   print_line (OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
440       "  Some visualization tools are not able to parse correctly the Paje file format.\n"
441       "  Use this option if you are using one of these tools to visualize the simulation\n"
442       "  trace. Keep in mind that the trace might be incomplete, without all the\n"
443       "  information that would be registered otherwise.", detailed);
444   print_line (OPT_TRACING_DISPLAY_SIZES, "Only works for SMPI now. Add message size information",
445       "  Message size (in bytes) is added to links, and to states. For collectives,\n"
446       "  the displayed value is the more relevant to the collective (total sent by\n"
447       "  the process, usually)", detailed);
448   print_line (OPT_TRACING_FORMAT, "Only works for SMPI now. Switch output format",
449       "  Default format is Paje. Time independent traces are also supported,\n"
450       "  to output traces that can later be used by the trace replay tool", detailed);
451   print_line (OPT_TRACING_FORMAT_TI_ONEFILE, "Only works for SMPI now, and TI output format",
452       "  By default, each process outputs to a separate file, inside a filename_files folder\n"
453       "  By setting this option to yes, all processes will output to only one file\n"
454       "  This is meant to avoid opening thousands of files with large simulations", detailed);
455   print_line (OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
456       "  Use this to add a comment line to the top of the trace file.", detailed);
457   print_line (OPT_TRACING_COMMENT_FILE, "File contents added to trace file as comment.",
458       "  Use this to add the contents of a file to the top of the trace file as comment.", detailed);
459   print_line (OPT_VIVA_UNCAT_CONF, "Generate a graph configuration for Viva",
460       "  This option can be used in all types of simulators build with SimGrid\n"
461       "  to generate a uncategorized resource utilization graph to be used as\n"
462       "  configuration for the Viva visualization tool. This option\n"
463       "  can be used with tracing/categorized:1 and tracing:1 options to\n"
464       "  analyze an unmodified simulator before changing it to contain\n"
465       "  categories.", detailed);
466   print_line (OPT_VIVA_CAT_CONF, "Generate an uncategorized graph configuration for Viva",
467       "  This option can be used if this simulator uses tracing categories\n"
468       "  in its code. The file specified by this option holds a graph configuration\n"
469       "  file for the Viva visualization tool that can be used to analyze a categorized\n"
470       "  resource utilization.", detailed);
471   print_line (OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
472         "  This option (enabled by default) can be used to disable the tracing of\n"
473         "  the platform topology in the trace file. Sometimes, such task is really\n"
474         "  time consuming, since it must get the route from each host to other hosts\n"
475         "  within the same Autonomous System (AS).", detailed);
476 }
477
478 static void output_types (const char *name, xbt_dynar_t types, FILE *file)
479 {
480   unsigned int i;
481   fprintf (file, "  %s = (", name);
482   for (i = xbt_dynar_length(types); i > 0; i--) {
483     char *type = *(static_cast<char**>(xbt_dynar_get_ptr(types, i - 1)));
484     fprintf (file, "\"%s\"", type);
485     if (i - 1 > 0){
486       fprintf (file, ",");
487     }else{
488       fprintf (file, ");\n");
489     }
490   }
491   xbt_dynar_free (&types);
492 }
493
494 static void output_categories (const char *name, xbt_dynar_t cats, FILE *file)
495 {
496   unsigned int i;
497   fprintf (file, "    values = (");
498   for (i = xbt_dynar_length(cats); i > 0; i--) {
499     char *cat = *(static_cast<char**>(xbt_dynar_get_ptr(cats, i - 1)));
500     fprintf (file, "\"%s%s\"", name, cat);
501     if (i - 1 > 0){
502       fprintf (file, ",");
503     }else{
504       fprintf (file, ");\n");
505     }
506   }
507   xbt_dynar_free (&cats);
508 }
509
510 static void uncat_configuration (FILE *file)
511 {
512   //register NODE and EDGE types
513   output_types ("node", TRACE_get_node_types(), file);
514   output_types ("edge", TRACE_get_edge_types(), file);
515   fprintf (file, "\n");
516
517   //configuration for all nodes
518   fprintf (file,
519       "  host = {\n"
520       "    type = \"square\";\n"
521       "    size = \"power\";\n"
522       "    values = (\"power_used\");\n"
523       "  };\n"
524       "  link = {\n"
525       "    type = \"rhombus\";\n"
526       "    size = \"bandwidth\";\n"
527       "    values = (\"bandwidth_used\");\n"
528       "  };\n");
529   //close
530 }
531
532 static void cat_configuration (FILE *file)
533 {
534   //register NODE and EDGE types
535   output_types ("node", TRACE_get_node_types(), file);
536   output_types ("edge", TRACE_get_edge_types(), file);
537   fprintf (file, "\n");
538
539   //configuration for all nodes
540   fprintf (file,
541            "  host = {\n"
542            "    type = \"square\";\n"
543            "    size = \"power\";\n");
544   output_categories ("p", TRACE_get_categories(), file);
545   fprintf (file,
546            "  };\n"
547            "  link = {\n"
548            "    type = \"rhombus\";\n"
549            "    size = \"bandwidth\";\n");
550   output_categories ("b", TRACE_get_categories(), file);
551   fprintf (file, "  };\n");
552   //close
553 }
554
555 static void generate_uncat_configuration (const char *output, const char *name, int brackets)
556 {
557   if (output && strlen(output) > 0){
558     FILE *file = fopen (output, "w");
559     if (file == nullptr){
560       THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph configuration (uncategorized).",
561               output, name);
562     }
563
564     if (brackets)
565       fprintf (file, "{\n");
566     uncat_configuration (file);
567     if (brackets)
568       fprintf (file, "}\n");
569     fclose (file);
570   }
571 }
572
573 static void generate_cat_configuration (const char *output, const char *name, int brackets)
574 {
575   if (output && strlen(output) > 0){
576     //check if we do have categories declared
577     if (xbt_dict_is_empty(created_categories)){
578       XBT_INFO("No categories declared, ignoring generation of %s graph configuration", name);
579       return;
580     }
581
582     FILE *file = fopen (output, "w");
583     if (file == nullptr){
584       THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph "
585           "configuration (categorized).", output, name);
586     }
587
588     if (brackets) fprintf (file, "{\n");
589     cat_configuration (file);
590     if (brackets) fprintf (file, "}\n");
591     fclose (file);
592   }
593 }
594
595 void TRACE_generate_viva_uncat_conf ()
596 {
597   generate_uncat_configuration (TRACE_get_viva_uncat_conf (), "viva", 0);
598 }
599
600 void TRACE_generate_viva_cat_conf ()
601 {
602   generate_cat_configuration (TRACE_get_viva_cat_conf(), "viva", 0);
603 }
604
605 static int previous_trace_state = -1;
606
607 void instr_pause_tracing ()
608 {
609   previous_trace_state = trace_enabled;
610   if (not TRACE_is_enabled()) {
611     XBT_DEBUG ("Tracing is already paused, therefore do nothing.");
612   }else{
613     XBT_DEBUG ("Tracing is being paused.");
614   }
615   trace_enabled = 0;
616   XBT_DEBUG ("Tracing is paused.");
617 }
618
619 void instr_resume_tracing ()
620 {
621   if (TRACE_is_enabled()){
622     XBT_DEBUG ("Tracing is already running while trying to resume, therefore do nothing.");
623   }else{
624     XBT_DEBUG ("Tracing is being resumed.");
625   }
626
627   if (previous_trace_state != -1){
628     trace_enabled = previous_trace_state;
629   }else{
630     trace_enabled = 1;
631   }
632   XBT_DEBUG ("Tracing is resumed.");
633   previous_trace_state = -1;
634 }
635
636 #undef OPT_TRACING
637 #undef OPT_TRACING_PLATFORM
638 #undef OPT_TRACING_TOPOLOGY
639 #undef OPT_TRACING_SMPI
640 #undef OPT_TRACING_SMPI_GROUP
641 #undef OPT_TRACING_CATEGORIZED
642 #undef OPT_TRACING_UNCATEGORIZED
643 #undef OPT_TRACING_MSG_PROCESS
644 #undef OPT_TRACING_FILENAME
645 #undef OPT_TRACING_BUFFER
646 #undef OPT_TRACING_ONELINK_ONLY
647 #undef OPT_TRACING_DISABLE_DESTROY
648 #undef OPT_TRACING_BASIC
649 #undef OPT_TRACING_COMMENT
650 #undef OPT_TRACING_COMMENT_FILE
651 #undef OPT_VIVA_UNCAT_CONF
652 #undef OPT_VIVA_CAT_CONF