Logo AND Algorithmique Numérique Distribuée

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