Logo AND Algorithmique Numérique Distribuée

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