Logo AND Algorithmique Numérique Distribuée

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