Logo AND Algorithmique Numérique Distribuée

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