Logo AND Algorithmique Numérique Distribuée

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