Logo AND Algorithmique Numérique Distribuée

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