Logo AND Algorithmique Numérique Distribuée

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