Logo AND Algorithmique Numérique Distribuée

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