Logo AND Algorithmique Numérique Distribuée

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