Logo AND Algorithmique Numérique Distribuée

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