1 /* Copyright (c) 2010-2013. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/instr_private.h"
8 #include "simgrid/sg_config.h"
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");
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_DISPLAY_SIZES "tracing/smpi/display_sizes"
24 #define OPT_TRACING_FORMAT "tracing/smpi/format"
25 #define OPT_TRACING_CATEGORIZED "tracing/categorized"
26 #define OPT_TRACING_UNCATEGORIZED "tracing/uncategorized"
27 #define OPT_TRACING_MSG_PROCESS "tracing/msg/process"
28 #define OPT_TRACING_MSG_VM "tracing/msg/vm"
29 #define OPT_TRACING_FILENAME "tracing/filename"
30 #define OPT_TRACING_BUFFER "tracing/buffer"
31 #define OPT_TRACING_ONELINK_ONLY "tracing/onelink_only"
32 #define OPT_TRACING_DISABLE_DESTROY "tracing/disable_destroy"
33 #define OPT_TRACING_BASIC "tracing/basic"
34 #define OPT_TRACING_COMMENT "tracing/comment"
35 #define OPT_TRACING_COMMENT_FILE "tracing/comment_file"
36 #define OPT_VIVA_UNCAT_CONF "viva/uncategorized"
37 #define OPT_VIVA_CAT_CONF "viva/categorized"
38 #define OPT_TRACING_DISABLE_LINK "tracing/disable_link"
39 #define OPT_TRACING_DISABLE_POWER "tracing/disable_power"
41 static int trace_enabled;
42 static int trace_platform;
43 static int trace_platform_topology;
44 static int trace_smpi_enabled;
45 static int trace_smpi_grouped;
46 static int trace_smpi_computing;
47 static int trace_view_internals;
48 static int trace_categorized;
49 static int trace_uncategorized;
50 static int trace_msg_process_enabled;
51 static int trace_msg_vm_enabled;
52 static int trace_buffer;
53 static int trace_onelink_only;
54 static int trace_disable_destroy;
55 static int trace_basic;
56 static int trace_display_sizes = 0;
57 static int trace_disable_link;
58 static int trace_disable_power;
60 static int trace_configured = 0;
61 static int trace_active = 0;
65 static void TRACE_getopts(void)
67 trace_enabled = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING);
68 trace_platform = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_PLATFORM);
69 trace_platform_topology = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_TOPOLOGY);
70 trace_smpi_enabled = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_SMPI);
71 trace_smpi_grouped = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_SMPI_GROUP);
72 trace_smpi_computing = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_SMPI_COMPUTING);
73 trace_view_internals = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_SMPI_INTERNALS);
74 trace_categorized = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_CATEGORIZED);
75 trace_uncategorized = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_UNCATEGORIZED);
76 trace_msg_process_enabled = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_MSG_PROCESS);
77 trace_msg_vm_enabled = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_MSG_VM);
78 trace_buffer = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_BUFFER);
79 trace_onelink_only = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_ONELINK_ONLY);
80 trace_disable_destroy = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_DISABLE_DESTROY);
81 trace_basic = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_BASIC);
82 trace_display_sizes = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_DISPLAY_SIZES);
83 trace_disable_link = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_DISABLE_LINK);
84 trace_disable_power = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_DISABLE_POWER);
87 static xbt_dynar_t TRACE_start_functions = NULL;
88 void TRACE_add_start_function(void (*func) ())
90 if (TRACE_start_functions == NULL)
91 TRACE_start_functions = xbt_dynar_new(sizeof(void (*)()), NULL);
92 xbt_dynar_push(TRACE_start_functions, &func);
99 // tracing system must be:
100 // - enabled (with --cfg=tracing:1)
101 // - already configured (TRACE_global_init already called)
102 if (TRACE_is_enabled() && TRACE_is_configured()) {
103 XBT_DEBUG("Tracing starts");
105 /* open the trace file */
109 if (trace_active == 1) {
110 THROWF(tracing_error, 0, "Tracing is already active");
113 XBT_DEBUG("Tracing is on");
115 /* other trace initialization */
116 created_categories = xbt_dict_new_homogeneous(xbt_free);
117 declared_marks = xbt_dict_new_homogeneous(xbt_free);
118 user_host_variables = xbt_dict_new_homogeneous(xbt_free);
119 user_vm_variables = xbt_dict_new_homogeneous (xbt_free);
120 user_link_variables = xbt_dict_new_homogeneous(xbt_free);
122 if (TRACE_start_functions != NULL) {
124 unsigned int iter = xbt_dynar_length(TRACE_start_functions);
125 xbt_dynar_foreach(TRACE_start_functions, iter, func) {
130 xbt_dynar_free(&TRACE_start_functions);
134 static xbt_dynar_t TRACE_end_functions = NULL;
135 void TRACE_add_end_function(void (*func) (void))
137 if (TRACE_end_functions == NULL)
138 TRACE_end_functions = xbt_dynar_new(sizeof(void (*)(void)), NULL);
139 xbt_dynar_push(TRACE_end_functions, &func);
150 TRACE_generate_viva_uncat_conf();
151 TRACE_generate_viva_cat_conf();
153 /* dump trace buffer */
154 TRACE_last_timestamp_to_dump = surf_get_clock();
155 TRACE_paje_dump_buffer(1);
157 /* destroy all data structures of tracing (and free) */
158 PJ_container_free_all();
160 PJ_container_release();
163 if (TRACE_end_functions != NULL) {
166 xbt_dynar_foreach(TRACE_end_functions, iter, func) {
171 xbt_dict_free(&user_link_variables);
172 xbt_dict_free(&user_host_variables);
173 xbt_dict_free(&user_vm_variables);
174 xbt_dict_free(&declared_marks);
175 xbt_dict_free(&created_categories);
177 /* close the trace file */
180 /* de-activate trace */
182 XBT_DEBUG("Tracing is off");
183 XBT_DEBUG("Tracing system is shutdown");
185 xbt_dynar_free(&TRACE_start_functions); /* useful when exiting early */
186 xbt_dynar_free(&TRACE_end_functions);
190 int TRACE_needs_platform (void)
192 return TRACE_msg_process_is_enabled() ||
193 TRACE_msg_vm_is_enabled() ||
194 TRACE_categorized() ||
195 TRACE_uncategorized() ||
197 (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
200 int TRACE_is_enabled(void)
202 return trace_enabled;
205 int TRACE_platform(void)
207 return trace_platform;
210 int TRACE_platform_topology(void)
212 return trace_platform_topology;
215 int TRACE_is_configured(void)
217 return trace_configured;
220 int TRACE_smpi_is_enabled(void)
222 return (trace_smpi_enabled || TRACE_smpi_is_grouped())
223 && TRACE_is_enabled();
226 int TRACE_smpi_is_grouped(void)
228 return trace_smpi_grouped;
231 int TRACE_smpi_is_computing(void)
233 return trace_smpi_computing;
236 int TRACE_smpi_view_internals(void)
238 return trace_view_internals;
241 int TRACE_categorized (void)
243 return trace_categorized;
246 int TRACE_uncategorized (void)
248 return trace_uncategorized;
251 int TRACE_msg_process_is_enabled(void)
253 return trace_msg_process_enabled && TRACE_is_enabled();
256 int TRACE_msg_vm_is_enabled(void)
258 return trace_msg_vm_enabled && TRACE_is_enabled();
261 int TRACE_disable_link(void)
263 return trace_disable_link && TRACE_is_enabled();
266 int TRACE_disable_power(void)
268 return trace_disable_power && TRACE_is_enabled();
271 int TRACE_buffer (void)
273 return trace_buffer && TRACE_is_enabled();
276 int TRACE_onelink_only (void)
278 return trace_onelink_only && TRACE_is_enabled();
281 int TRACE_disable_destroy (void)
283 return trace_disable_destroy && TRACE_is_enabled();
286 int TRACE_basic (void)
288 return trace_basic && TRACE_is_enabled();
291 int TRACE_display_sizes (void)
293 return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
296 char *TRACE_get_comment (void)
298 return xbt_cfg_get_string(_sg_cfg_set, OPT_TRACING_COMMENT);
301 char *TRACE_get_comment_file (void)
303 return xbt_cfg_get_string(_sg_cfg_set, OPT_TRACING_COMMENT_FILE);
306 char *TRACE_get_filename(void)
308 return xbt_cfg_get_string(_sg_cfg_set, OPT_TRACING_FILENAME);
311 char *TRACE_get_viva_uncat_conf (void)
313 return xbt_cfg_get_string(_sg_cfg_set, OPT_VIVA_UNCAT_CONF);
316 char *TRACE_get_viva_cat_conf (void)
318 return xbt_cfg_get_string(_sg_cfg_set, OPT_VIVA_CAT_CONF);
321 void TRACE_global_init(int *argc, char **argv)
323 /* name of the tracefile */
324 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_FILENAME,
325 "Trace file created by the instrumented SimGrid.",
326 xbt_cfgelm_string, 1, 1, NULL, NULL);
327 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_FILENAME, "simgrid.trace");
330 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING,
332 xbt_cfgelm_int, 0, 1, NULL, NULL);
333 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING, 0);
335 /* register platform in the trace */
336 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_PLATFORM,
337 "Register the platform in the trace as a hierarchy.",
338 xbt_cfgelm_int, 0, 1, NULL, NULL);
339 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_PLATFORM, 0);
341 /* register platform in the trace */
342 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_TOPOLOGY,
343 "Register the platform topology in the trace as a graph.",
344 xbt_cfgelm_int, 0, 1, NULL, NULL);
345 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_TOPOLOGY, 1);
348 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_SMPI,
349 "Tracing of the SMPI interface.",
350 xbt_cfgelm_int, 0, 1, NULL, NULL);
351 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_SMPI, 0);
354 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_SMPI_GROUP,
355 "Group MPI processes by host.",
356 xbt_cfgelm_int, 0, 1, NULL, NULL);
357 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_SMPI_GROUP, 0);
360 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_SMPI_COMPUTING,
361 "Generate states for timing out of SMPI parts of the application",
362 xbt_cfgelm_int, 0, 1, NULL, NULL);
363 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_SMPI_COMPUTING, 0);
366 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_SMPI_INTERNALS,
367 "View internal messages sent by Collective communications in SMPI",
368 xbt_cfgelm_int, 0, 1, NULL, NULL);
369 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_SMPI_INTERNALS, 0);
371 /* tracing categorized resource utilization traces */
372 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_CATEGORIZED,
373 "Tracing categorized resource utilization of hosts and links.",
374 xbt_cfgelm_int, 0, 1, NULL, NULL);
375 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_CATEGORIZED, 0);
377 /* tracing uncategorized resource utilization */
378 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_UNCATEGORIZED,
379 "Tracing uncategorized resource utilization of hosts and links.",
380 xbt_cfgelm_int, 0, 1, NULL, NULL);
381 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_UNCATEGORIZED, 0);
384 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_MSG_PROCESS,
385 "Tracing of MSG process behavior.",
386 xbt_cfgelm_int, 0, 1, NULL, NULL);
387 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_MSG_PROCESS, 0);
390 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_MSG_VM,
391 "Tracing of MSG process behavior.",
392 xbt_cfgelm_int, 0, 1, NULL, NULL);
393 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_MSG_VM, 0);
395 /* disable tracing link */
396 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISABLE_LINK,
397 "Do not trace link bandwidth and latency.",
398 xbt_cfgelm_int, 0, 1, NULL, NULL);
399 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_DISABLE_LINK, 0);
401 /* disable tracing link */
402 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISABLE_POWER,
403 "Do not trace host power.",
404 xbt_cfgelm_int, 0, 1, NULL, NULL);
405 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_DISABLE_POWER, 0);
409 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_BUFFER,
410 "Buffer trace events to put them in temporal order.",
411 xbt_cfgelm_int, 0, 1, NULL, NULL);
412 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_BUFFER, 1);
414 /* tracing one link only */
415 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_ONELINK_ONLY,
416 "Use only routes with one link to trace platform.",
417 xbt_cfgelm_int, 0, 1, NULL, NULL);
418 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_ONELINK_ONLY, 0);
420 /* disable destroy */
421 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISABLE_DESTROY,
422 "Disable platform containers destruction.",
423 xbt_cfgelm_int, 0, 1, NULL, NULL);
424 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_DISABLE_DESTROY, 0);
426 /* basic -- Avoid extended events (impoverished trace file) */
427 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_BASIC,
428 "Avoid extended events (impoverished trace file).",
429 xbt_cfgelm_int, 0, 1, NULL, NULL);
430 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_BASIC, 0);
432 /* display_sizes -- Extended events with message size information */
433 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISPLAY_SIZES,
434 "(smpi only for now) Extended events with message size information",
435 xbt_cfgelm_int, 0, 1, NULL, NULL);
436 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_DISPLAY_SIZES, 0);
438 /* format -- Switch the ouput format of Tracing */
439 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_FORMAT,
440 "(smpi only for now) Switch the ouput format of Tracing",
441 xbt_cfgelm_string, 1, 1, NULL, NULL);
442 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_FORMAT, "Paje");
445 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_COMMENT,
446 "Comment to be added on the top of the trace file.",
447 xbt_cfgelm_string, 1, 1, NULL, NULL);
448 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_COMMENT, "");
451 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_COMMENT_FILE,
452 "The contents of the file are added to the top of the trace file as comment.",
453 xbt_cfgelm_string, 1, 1, NULL, NULL);
454 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_COMMENT_FILE, "");
456 /* Viva graph configuration for uncategorized tracing */
457 xbt_cfg_register(&_sg_cfg_set, OPT_VIVA_UNCAT_CONF,
458 "Viva Graph configuration file for uncategorized resource utilization traces.",
459 xbt_cfgelm_string, 1, 1, NULL, NULL);
460 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_VIVA_UNCAT_CONF, "");
462 /* Viva graph configuration for uncategorized tracing */
463 xbt_cfg_register(&_sg_cfg_set, OPT_VIVA_CAT_CONF,
464 "Viva Graph configuration file for categorized resource utilization traces.",
465 xbt_cfgelm_string, 1, 1, NULL, NULL);
466 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_VIVA_CAT_CONF, "");
468 /* instrumentation can be considered configured now */
469 trace_configured = 1;
472 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
474 char str[INSTR_DEFAULT_STR_SIZE];
475 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
477 int len = strlen (str);
478 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
479 if (!!longdesc && detailed){
480 printf ("%s\n\n", longdesc);
484 void TRACE_help (int detailed)
487 "Description of the tracing options accepted by this simulator:\n\n");
488 print_line (OPT_TRACING, "Enable the tracing system",
489 " It activates the tracing system and register the simulation platform\n"
490 " in the trace file. You have to enable this option to others take effect.",
492 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
493 " It activates the categorized resource utilization tracing. It should\n"
494 " be enabled if tracing categories are used by this simulator.",
496 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
497 " It activates the uncategorized resource utilization tracing. Use it if\n"
498 " this simulator do not use tracing categories and resource use have to be\n"
501 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
502 " A file with this name will be created to register the simulation. The file\n"
503 " is in the Paje format and can be analyzed using Viva, Paje, and PajeNG visualization\n"
504 " tools. More information can be found in these webpages:\n"
505 " http://github.com/schnorr/viva/\n"
506 " http://github.com/schnorr/pajeng/\n"
507 " http://paje.sourceforge.net/",
509 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
510 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
511 " interface and generates a trace that can be analyzed using Gantt-like\n"
512 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
513 " state, and point-to-point communications can be analyzed with arrows.",
515 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
516 " This option only has effect if this simulator is SMPI-based. The processes\n"
517 " are grouped by the hosts where they were executed.",
519 print_line (OPT_TRACING_SMPI_COMPUTING, "Generates a \" Computing \" State",
520 " This option aims at tracing computations in the application, outside SMPI\n"
521 " to allow further study of simulated or real computation time",
523 print_line (OPT_TRACING_SMPI_INTERNALS, "Generates tracing events corresponding",
524 " to point-to-point messages sent by collective communications",
526 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
527 " This option only has effect if this simulator is MSG-based. It traces the\n"
528 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
529 " can be used to track process location if this simulator has process migration.",
531 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
532 " This option put some events in a time-ordered buffer using the insertion\n"
533 " sort algorithm. The process of acquiring and releasing locks to access this\n"
534 " buffer and the cost of the sorting algorithm make this process slow. The\n"
535 " simulator performance can be severely impacted if this option is activated,\n"
536 " but you are sure to get a trace file with events sorted.",
538 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
539 " This option changes the way SimGrid register its platform on the trace file.\n"
540 " Normally, the tracing considers all routes (no matter their size) on the\n"
541 " platform file to re-create the resource topology. If this option is activated,\n"
542 " only the routes with one link are used to register the topology within an AS.\n"
543 " Routes among AS continue to be traced as usual.",
545 print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
546 " Disable the destruction of containers at the end of simulation. This can be\n"
547 " used with simulators that have a different notion of time (different from\n"
548 " the simulated time).",
550 print_line (OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
551 " Some visualization tools are not able to parse correctly the Paje file format.\n"
552 " Use this option if you are using one of these tools to visualize the simulation\n"
553 " trace. Keep in mind that the trace might be incomplete, without all the\n"
554 " information that would be registered otherwise.",
556 print_line (OPT_TRACING_DISPLAY_SIZES, "Only works for SMPI now. Add message size information",
557 "Message size (in bytes) is added to links, and to states. For collectives, the displayed value \n"
558 "is the more relevant to the collective (total sent by the process, usually)",
560 print_line (OPT_TRACING_FORMAT, "Only works for SMPI now. Switch output format",
561 "Default format is Paje. Time independant traces are also supported, \n"
562 "to output traces that can later be used by the trace replay tool",
564 print_line (OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
565 " Use this to add a comment line to the top of the trace file.",
567 print_line (OPT_TRACING_COMMENT_FILE, "File contents added to trace file as comment.",
568 " Use this to add the contents of a file to the top of the trace file as comment.",
570 print_line (OPT_VIVA_UNCAT_CONF, "Generate a graph configuration for Viva",
571 " This option can be used in all types of simulators build with SimGrid\n"
572 " to generate a uncategorized resource utilization graph to be used as\n"
573 " configuration for the Viva visualization tool. This option\n"
574 " can be used with tracing/categorized:1 and tracing:1 options to\n"
575 " analyze an unmodified simulator before changing it to contain\n"
578 print_line (OPT_VIVA_CAT_CONF, "Generate an uncategorized graph configuration for Viva",
579 " This option can be used if this simulator uses tracing categories\n"
580 " in its code. The file specified by this option holds a graph configuration\n"
581 " file for the Viva visualization tool that can be used to analyze a categorized\n"
582 " resource utilization.",
584 print_line (OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
585 " This option (enabled by default) can be used to disable the tracing of\n"
586 " the platform topology in the trace file. Sometimes, such task is really\n"
587 " time consuming, since it must get the route from each host ot other hosts\n"
588 " within the same Autonomous System (AS).",
592 static void output_types (const char *name, xbt_dynar_t types, FILE *file)
595 fprintf (file, " %s = (", name);
596 for (i = xbt_dynar_length(types); i > 0; i--) {
597 char *type = *(char**)xbt_dynar_get_ptr(types, i - 1);
598 fprintf (file, "\"%s\"", type);
602 fprintf (file, ");\n");
605 xbt_dynar_free (&types);
608 static void output_categories (const char *name, xbt_dynar_t cats, FILE *file)
611 fprintf (file, " values = (");
612 for (i = xbt_dynar_length(cats); i > 0; i--) {
613 char *cat = *(char**)xbt_dynar_get_ptr(cats, i - 1);
614 fprintf (file, "\"%s%s\"", name, cat);
618 fprintf (file, ");\n");
621 xbt_dynar_free (&cats);
624 static void uncat_configuration (FILE *file)
626 //register NODE and EDGE types
627 output_types ("node", TRACE_get_node_types(), file);
628 output_types ("edge", TRACE_get_edge_types(), file);
629 fprintf (file, "\n");
631 //configuration for all nodes
634 " type = \"square\";\n"
635 " size = \"power\";\n"
636 " values = (\"power_used\");\n"
639 " type = \"rhombus\";\n"
640 " size = \"bandwidth\";\n"
641 " values = (\"bandwidth_used\");\n"
646 static void cat_configuration (FILE *file)
648 //register NODE and EDGE types
649 output_types ("node", TRACE_get_node_types(), file);
650 output_types ("edge", TRACE_get_edge_types(), file);
651 fprintf (file, "\n");
653 //configuration for all nodes
656 " type = \"square\";\n"
657 " size = \"power\";\n");
658 output_categories ("p", TRACE_get_categories(), file);
662 " type = \"rhombus\";\n"
663 " size = \"bandwidth\";\n");
664 output_categories ("b", TRACE_get_categories(), file);
665 fprintf (file, " };\n");
669 static void generate_uncat_configuration (const char *output, const char *name, int brackets)
671 if (output && strlen(output) > 0){
672 FILE *file = fopen (output, "w");
674 THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph "
675 "configuration (uncategorized).", output, name);
678 if (brackets) fprintf (file, "{\n");
679 uncat_configuration (file);
680 if (brackets) fprintf (file, "}\n");
685 static void generate_cat_configuration (const char *output, const char *name, int brackets)
687 if (output && strlen(output) > 0){
688 //check if we do have categories declared
689 if (xbt_dict_is_empty(created_categories)){
690 XBT_INFO("No categories declared, ignoring generation of %s graph configuration", name);
694 FILE *file = fopen (output, "w");
696 THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph "
697 "configuration (categorized).", output, name);
700 if (brackets) fprintf (file, "{\n");
701 cat_configuration (file);
702 if (brackets) fprintf (file, "}\n");
707 void TRACE_generate_viva_uncat_conf (void)
709 generate_uncat_configuration (TRACE_get_viva_uncat_conf (), "viva", 0);
712 void TRACE_generate_viva_cat_conf (void)
714 generate_cat_configuration (TRACE_get_viva_cat_conf(), "viva", 0);
717 static int previous_trace_state = -1;
719 void instr_pause_tracing (void)
721 previous_trace_state = trace_enabled;
722 if (!TRACE_is_enabled()){
723 XBT_DEBUG ("Tracing is already paused, therefore do nothing.");
725 XBT_DEBUG ("Tracing is being paused.");
728 XBT_DEBUG ("Tracing is paused.");
731 void instr_resume_tracing (void)
733 if (TRACE_is_enabled()){
734 XBT_DEBUG ("Tracing is already running while trying to resume, therefore do nothing.");
736 XBT_DEBUG ("Tracing is being resumed.");
739 if (previous_trace_state != -1){
740 trace_enabled = previous_trace_state;
744 XBT_DEBUG ("Tracing is resumed.");
745 previous_trace_state = -1;
749 #undef OPT_TRACING_PLATFORM
750 #undef OPT_TRACING_TOPOLOGY
751 #undef OPT_TRACING_SMPI
752 #undef OPT_TRACING_SMPI_GROUP
753 #undef OPT_TRACING_CATEGORIZED
754 #undef OPT_TRACING_UNCATEGORIZED
755 #undef OPT_TRACING_MSG_PROCESS
756 #undef OPT_TRACING_FILENAME
757 #undef OPT_TRACING_BUFFER
758 #undef OPT_TRACING_ONELINK_ONLY
759 #undef OPT_TRACING_DISABLE_DESTROY
760 #undef OPT_TRACING_BASIC
761 #undef OPT_TRACING_COMMENT
762 #undef OPT_TRACING_COMMENT_FILE
763 #undef OPT_VIVA_UNCAT_CONF
764 #undef OPT_VIVA_CAT_CONF
766 #endif /* HAVE_TRACING */