Logo AND Algorithmique Numérique Distribuée

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