Logo AND Algorithmique Numérique Distribuée

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