Logo AND Algorithmique Numérique Distribuée

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