1 /* Copyright (c) 2010-2015. 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 "src/instr/instr_private.h"
8 #include "simgrid/sg_config.h"
11 XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)");
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
14 #define OPT_TRACING_BASIC "tracing/basic"
15 #define OPT_TRACING_BUFFER "tracing/buffer"
16 #define OPT_TRACING_CATEGORIZED "tracing/categorized"
17 #define OPT_TRACING_COMMENT_FILE "tracing/comment_file"
18 #define OPT_TRACING_COMMENT "tracing/comment"
19 #define OPT_TRACING_DISABLE_DESTROY "tracing/disable_destroy"
20 #define OPT_TRACING_DISABLE_LINK "tracing/disable_link"
21 #define OPT_TRACING_DISABLE_POWER "tracing/disable_power"
22 #define OPT_TRACING_DISPLAY_SIZES "tracing/smpi/display_sizes"
23 #define OPT_TRACING_FILENAME "tracing/filename"
24 #define OPT_TRACING_FORMAT_TI_ONEFILE "tracing/smpi/format/ti_one_file"
25 #define OPT_TRACING_FORMAT "tracing/smpi/format"
26 #define OPT_TRACING_MSG_PROCESS "tracing/msg/process"
27 #define OPT_TRACING_MSG_VM "tracing/msg/vm"
28 #define OPT_TRACING_ONELINK_ONLY "tracing/onelink_only"
29 #define OPT_TRACING_PLATFORM "tracing/platform"
30 #define OPT_TRACING_PRECISION "tracing/precision"
31 #define OPT_TRACING_SMPI_COMPUTING "tracing/smpi/computing"
32 #define OPT_TRACING_SMPI_GROUP "tracing/smpi/group"
33 #define OPT_TRACING_SMPI_INTERNALS "tracing/smpi/internals"
34 #define OPT_TRACING_SMPI_SLEEPING "tracing/smpi/sleeping"
35 #define OPT_TRACING_SMPI "tracing/smpi"
36 #define OPT_TRACING_TOPOLOGY "tracing/platform/topology"
37 #define OPT_TRACING "tracing"
38 #define OPT_TRACING_UNCATEGORIZED "tracing/uncategorized"
39 #define OPT_VIVA_CAT_CONF "viva/categorized"
40 #define OPT_VIVA_UNCAT_CONF "viva/uncategorized"
42 static int trace_enabled = 0;
43 static int trace_platform;
44 static int trace_platform_topology;
45 static int trace_smpi_enabled;
46 static int trace_smpi_grouped;
47 static int trace_smpi_computing;
48 static int trace_smpi_sleeping;
49 static int trace_view_internals;
50 static int trace_categorized;
51 static int trace_uncategorized;
52 static int trace_msg_process_enabled;
53 static int trace_msg_vm_enabled;
54 static int trace_buffer;
55 static int trace_onelink_only;
56 static int trace_disable_destroy;
57 static int trace_basic;
58 static int trace_display_sizes = 0;
59 static int trace_disable_link;
60 static int trace_disable_power;
61 static int trace_precision;
63 static int trace_configured = 0;
64 static int trace_active = 0;
66 static void TRACE_getopts(void)
68 trace_enabled = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING);
69 trace_platform = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_PLATFORM);
70 trace_platform_topology = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_TOPOLOGY);
71 trace_smpi_enabled = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_SMPI);
72 trace_smpi_grouped = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_SMPI_GROUP);
73 trace_smpi_computing = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_SMPI_COMPUTING);
74 trace_smpi_sleeping = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_SMPI_SLEEPING);
75 trace_view_internals = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_SMPI_INTERNALS);
76 trace_categorized = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_CATEGORIZED);
77 trace_uncategorized = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_UNCATEGORIZED);
78 trace_msg_process_enabled = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_MSG_PROCESS);
79 trace_msg_vm_enabled = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_MSG_VM);
80 trace_buffer = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_BUFFER);
81 trace_onelink_only = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_ONELINK_ONLY);
82 trace_disable_destroy = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_DISABLE_DESTROY);
83 trace_basic = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_BASIC);
84 trace_display_sizes = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_DISPLAY_SIZES);
85 trace_disable_link = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_DISABLE_LINK);
86 trace_disable_power = xbt_cfg_get_boolean(_sg_cfg_set, OPT_TRACING_DISABLE_POWER);
87 trace_precision = xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_PRECISION);
90 static xbt_dynar_t TRACE_start_functions = NULL;
91 void TRACE_add_start_function(void (*func) ())
93 if (TRACE_start_functions == NULL)
94 TRACE_start_functions = xbt_dynar_new(sizeof(void (*)()), NULL);
95 xbt_dynar_push(TRACE_start_functions, &func);
100 if (TRACE_is_configured())
103 // tracing system must be:
104 // - enabled (with --cfg=tracing:yes)
105 // - already configured (TRACE_global_init already called)
106 if (TRACE_is_enabled()) {
108 XBT_DEBUG("Tracing starts");
109 /* init the tracing module to generate the right output */
110 /* open internal buffer */
113 /* open the trace file(s) */
114 const char* format = sg_cfg_get_string(OPT_TRACING_FORMAT);
115 XBT_DEBUG("Tracing format %s\n", format);
116 if(!strcmp(format, "Paje")){
119 }else if (!strcmp(format, "TI")){
123 xbt_die("Unknown trace format :%s ", format);
127 if (trace_active == 1) {
128 THROWF(tracing_error, 0, "Tracing is already active");
131 XBT_DEBUG("Tracing is on");
133 /* other trace initialization */
134 created_categories = xbt_dict_new_homogeneous(xbt_free_f);
135 declared_marks = xbt_dict_new_homogeneous(xbt_free_f);
136 user_host_variables = xbt_dict_new_homogeneous(xbt_free_f);
137 user_vm_variables = xbt_dict_new_homogeneous(xbt_free_f);
138 user_link_variables = xbt_dict_new_homogeneous(xbt_free_f);
140 if (TRACE_start_functions != NULL) {
143 xbt_dynar_foreach(TRACE_start_functions, iter, func) {
148 xbt_dynar_free(&TRACE_start_functions);
152 static xbt_dynar_t TRACE_end_functions = NULL;
153 void TRACE_add_end_function(void (*func) (void))
155 if (TRACE_end_functions == NULL)
156 TRACE_end_functions = xbt_dynar_new(sizeof(void (*)(void)), NULL);
157 xbt_dynar_push(TRACE_end_functions, &func);
168 TRACE_generate_viva_uncat_conf();
169 TRACE_generate_viva_cat_conf();
171 /* dump trace buffer */
172 TRACE_last_timestamp_to_dump = surf_get_clock();
173 TRACE_paje_dump_buffer(1);
175 /* destroy all data structures of tracing (and free) */
176 PJ_container_free_all();
178 PJ_container_release();
181 if (TRACE_end_functions != NULL) {
184 xbt_dynar_foreach(TRACE_end_functions, iter, func) {
189 xbt_dict_free(&user_link_variables);
190 xbt_dict_free(&user_host_variables);
191 xbt_dict_free(&user_vm_variables);
192 xbt_dict_free(&declared_marks);
193 xbt_dict_free(&created_categories);
195 /* close the trace files */
196 const char* format = sg_cfg_get_string(OPT_TRACING_FORMAT);
197 XBT_DEBUG("Tracing format %s\n", format);
198 if(!strcmp(format, "Paje")){
200 }else if (!strcmp(format, "TI")){
203 xbt_die("Unknown trace format :%s ", format);
205 /* close internal buffer */
207 /* de-activate trace */
209 XBT_DEBUG("Tracing is off");
210 XBT_DEBUG("Tracing system is shutdown");
212 xbt_dynar_free(&TRACE_start_functions); /* useful when exiting early */
213 xbt_dynar_free(&TRACE_end_functions);
217 int TRACE_needs_platform (void)
219 return TRACE_msg_process_is_enabled() || TRACE_msg_vm_is_enabled() || TRACE_categorized() ||
220 TRACE_uncategorized() || TRACE_platform () || (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
223 int TRACE_is_enabled(void)
225 return trace_enabled;
228 int TRACE_platform(void)
230 return trace_platform;
233 int TRACE_platform_topology(void)
235 return trace_platform_topology;
238 int TRACE_is_configured(void)
240 return trace_configured;
243 int TRACE_smpi_is_enabled(void)
245 return (trace_smpi_enabled || TRACE_smpi_is_grouped()) && TRACE_is_enabled();
248 int TRACE_smpi_is_grouped(void)
250 return trace_smpi_grouped;
253 int TRACE_smpi_is_computing(void)
255 return trace_smpi_computing;
258 int TRACE_smpi_is_sleeping(void)
260 return trace_smpi_sleeping;
263 int TRACE_smpi_view_internals(void)
265 return trace_view_internals;
268 int TRACE_categorized (void)
270 return trace_categorized;
273 int TRACE_uncategorized (void)
275 return trace_uncategorized;
278 int TRACE_msg_process_is_enabled(void)
280 return trace_msg_process_enabled && TRACE_is_enabled();
283 int TRACE_msg_vm_is_enabled(void)
285 return trace_msg_vm_enabled && TRACE_is_enabled();
288 int TRACE_disable_link(void)
290 return trace_disable_link && TRACE_is_enabled();
293 int TRACE_disable_speed(void)
295 return trace_disable_power && TRACE_is_enabled();
298 int TRACE_buffer (void)
300 return trace_buffer && TRACE_is_enabled();
303 int TRACE_onelink_only (void)
305 return trace_onelink_only && TRACE_is_enabled();
308 int TRACE_disable_destroy (void)
310 return trace_disable_destroy && TRACE_is_enabled();
313 int TRACE_basic (void)
315 return trace_basic && TRACE_is_enabled();
318 int TRACE_display_sizes (void)
320 return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
323 char *TRACE_get_comment (void)
325 return xbt_cfg_get_string(_sg_cfg_set, OPT_TRACING_COMMENT);
328 char *TRACE_get_comment_file (void)
330 return xbt_cfg_get_string(_sg_cfg_set, OPT_TRACING_COMMENT_FILE);
333 int TRACE_precision (void)
335 return xbt_cfg_get_int(_sg_cfg_set, OPT_TRACING_PRECISION);
338 char *TRACE_get_filename(void)
340 return xbt_cfg_get_string(_sg_cfg_set, OPT_TRACING_FILENAME);
343 char *TRACE_get_viva_uncat_conf (void)
345 return xbt_cfg_get_string(_sg_cfg_set, OPT_VIVA_UNCAT_CONF);
348 char *TRACE_get_viva_cat_conf (void)
350 return xbt_cfg_get_string(_sg_cfg_set, OPT_VIVA_CAT_CONF);
353 void TRACE_global_init(int *argc, char **argv)
355 static int is_initialised = 0;
356 if (is_initialised) return;
359 /* name of the tracefile */
360 xbt_cfg_register_string (&_sg_cfg_set, OPT_TRACING_FILENAME, "Trace file created by the instrumented SimGrid.", "simgrid.trace", NULL);
361 xbt_cfg_register_boolean(&_sg_cfg_set, OPT_TRACING, "Enable Tracing.", "no", NULL);
362 xbt_cfg_register_boolean(&_sg_cfg_set, OPT_TRACING_PLATFORM, "Register the platform in the trace as a hierarchy.", "no", NULL);
363 xbt_cfg_register_boolean(&_sg_cfg_set, OPT_TRACING_TOPOLOGY, "Register the platform topology in the trace as a graph.", "yes", NULL);
364 xbt_cfg_register_boolean(&_sg_cfg_set, OPT_TRACING_SMPI, "Tracing of the SMPI interface.", "no", NULL);
365 xbt_cfg_register_boolean(&_sg_cfg_set, OPT_TRACING_SMPI_GROUP, "Group MPI processes by host.", "no", NULL);
366 xbt_cfg_register_boolean(&_sg_cfg_set, OPT_TRACING_SMPI_COMPUTING,
367 "Generate states for timing out of SMPI parts of the application", "no", NULL);
370 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_SMPI_SLEEPING,
371 "Generate states for timing out of SMPI parts of the application", xbt_cfgelm_boolean, 1, 1, NULL);
372 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_SMPI_SLEEPING, "no");
375 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_SMPI_INTERNALS,
376 "View internal messages sent by Collective communications in SMPI", xbt_cfgelm_boolean, 1, 1, NULL);
377 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_SMPI_INTERNALS, "no");
379 /* tracing categorized resource utilization traces */
380 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_CATEGORIZED,
381 "Tracing categorized resource utilization of hosts and links.", xbt_cfgelm_boolean, 1, 1, NULL);
382 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_CATEGORIZED, "no");
384 /* tracing uncategorized resource utilization */
385 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_UNCATEGORIZED,
386 "Tracing uncategorized resource utilization of hosts and links.", xbt_cfgelm_boolean, 1, 1, NULL);
387 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_UNCATEGORIZED, "no");
390 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_MSG_PROCESS, "Tracing of MSG process behavior.",
391 xbt_cfgelm_boolean, 1, 1, NULL);
392 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_MSG_PROCESS, "no");
395 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_MSG_VM, "Tracing of MSG process behavior.",
396 xbt_cfgelm_boolean, 1, 1, NULL);
397 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_MSG_VM, "no");
399 /* disable tracing link */
400 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISABLE_LINK, "Do not trace link bandwidth and latency.",
401 xbt_cfgelm_boolean, 1, 1, NULL);
402 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_DISABLE_LINK, "no");
404 /* disable tracing link */
405 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISABLE_POWER, "Do not trace host power.", xbt_cfgelm_boolean, 1, 1, NULL);
406 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_DISABLE_POWER, "no");
409 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_BUFFER, "Buffer trace events to put them in temporal order.",
410 xbt_cfgelm_boolean, 1, 1, NULL);
411 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_BUFFER, "yes");
413 /* tracing one link only */
414 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_ONELINK_ONLY, "Use only routes with one link to trace platform.",
415 xbt_cfgelm_boolean, 1, 1, NULL);
416 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_ONELINK_ONLY, "no");
418 /* disable destroy */
419 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction.",
420 xbt_cfgelm_boolean, 1, 1, NULL);
421 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_DISABLE_DESTROY, "no");
423 /* basic -- Avoid extended events (impoverished trace file) */
424 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
425 xbt_cfgelm_boolean, 1, 1, NULL);
426 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_BASIC, "no");
428 /* display_sizes -- Extended events with message size information */
429 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_DISPLAY_SIZES,
430 "(smpi only for now) Extended events with message size information", xbt_cfgelm_boolean, 1, 1, NULL);
431 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_DISPLAY_SIZES, "no");
433 /* format -- Switch the ouput format of Tracing */
434 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_FORMAT, "(smpi only for now) Switch the output format of Tracing",
435 xbt_cfgelm_string, 1, 1, NULL);
436 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_FORMAT, "Paje");
438 /* format -- Switch the ouput format of Tracing */
439 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_FORMAT_TI_ONEFILE,
440 "(smpi only for now) For replay format only : output to one file only",
441 xbt_cfgelm_boolean, 1, 1, NULL);
442 xbt_cfg_setdefault_boolean(_sg_cfg_set, OPT_TRACING_FORMAT_TI_ONEFILE, "no");
445 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
446 xbt_cfgelm_string, 1, 1, NULL);
447 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_COMMENT, "");
450 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_COMMENT_FILE,
451 "The contents of the file are added to the top of the trace file as comment.",
452 xbt_cfgelm_string, 1, 1, NULL);
453 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_TRACING_COMMENT_FILE, "");
455 /* trace timestamp precision */
456 xbt_cfg_register(&_sg_cfg_set, OPT_TRACING_PRECISION, "Numerical precision used when timestamping events (hence "
457 "this value is expressed in number of digits after decimal point)", xbt_cfgelm_int, 1, 1, NULL);
458 xbt_cfg_setdefault_int(_sg_cfg_set, OPT_TRACING_PRECISION, 6);
460 /* Viva graph configuration for uncategorized tracing */
461 xbt_cfg_register(&_sg_cfg_set, OPT_VIVA_UNCAT_CONF,
462 "Viva Graph configuration file for uncategorized resource utilization traces.",
463 xbt_cfgelm_string, 1, 1, NULL);
464 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_VIVA_UNCAT_CONF, "");
466 /* Viva graph configuration for uncategorized tracing */
467 xbt_cfg_register(&_sg_cfg_set, OPT_VIVA_CAT_CONF,
468 "Viva Graph configuration file for categorized resource utilization traces.",
469 xbt_cfgelm_string, 1, 1, NULL);
470 xbt_cfg_setdefault_string(_sg_cfg_set, OPT_VIVA_CAT_CONF, "");
472 /* instrumentation can be considered configured now */
473 trace_configured = 1;
476 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
478 char str[INSTR_DEFAULT_STR_SIZE];
479 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
481 int len = strlen (str);
482 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
483 if (!!longdesc && detailed){
484 printf ("%s\n\n", longdesc);
488 void TRACE_help (int detailed)
490 printf("Description of the tracing options accepted by this simulator:\n\n");
491 print_line (OPT_TRACING, "Enable the tracing system",
492 " It activates the tracing system and register the simulation platform\n"
493 " in the trace file. You have to enable this option to others take effect.", detailed);
494 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
495 " It activates the categorized resource utilization tracing. It should\n"
496 " be enabled if tracing categories are used by this simulator.", detailed);
497 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
498 " It activates the uncategorized resource utilization tracing. Use it if\n"
499 " this simulator do not use tracing categories and resource use have to be\n"
500 " traced.", detailed);
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/", detailed);
508 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
509 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
510 " interface and generates a trace that can be analyzed using Gantt-like\n"
511 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
512 " state, and point-to-point communications can be analyzed with arrows.", detailed);
513 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
514 " This option only has effect if this simulator is SMPI-based. The processes\n"
515 " are grouped by the hosts where they were executed.", detailed);
516 print_line (OPT_TRACING_SMPI_COMPUTING, "Generates a \" Computing \" State",
517 " This option aims at tracing computations in the application, outside SMPI\n"
518 " to allow further study of simulated or real computation time", detailed);
519 print_line (OPT_TRACING_SMPI_SLEEPING, "Generates a \" Sleeping \" State",
520 " This option aims at tracing sleeps in the application, outside SMPI\n"
521 " to allow further study of simulated or real sleep time", detailed);
522 print_line (OPT_TRACING_SMPI_INTERNALS, "Generates tracing events corresponding",
523 " to point-to-point messages sent by collective communications", detailed);
524 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
525 " This option only has effect if this simulator is MSG-based. It traces the\n"
526 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
527 " can be used to track process location if this simulator has process migration.", detailed);
528 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
529 " This option put some events in a time-ordered buffer using the insertion\n"
530 " sort algorithm. The process of acquiring and releasing locks to access this\n"
531 " buffer and the cost of the sorting algorithm make this process slow. The\n"
532 " simulator performance can be severely impacted if this option is activated,\n"
533 " but you are sure to get a trace file with events sorted.", detailed);
534 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
535 " This option changes the way SimGrid register its platform on the trace file.\n"
536 " Normally, the tracing considers all routes (no matter their size) on the\n"
537 " platform file to re-create the resource topology. If this option is activated,\n"
538 " only the routes with one link are used to register the topology within an AS.\n"
539 " Routes among AS continue to be traced as usual.", detailed);
540 print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
541 " Disable the destruction of containers at the end of simulation. This can be\n"
542 " used with simulators that have a different notion of time (different from\n"
543 " the simulated time).", detailed);
544 print_line (OPT_TRACING_BASIC, "Avoid extended events (impoverished trace file).",
545 " Some visualization tools are not able to parse correctly the Paje file format.\n"
546 " Use this option if you are using one of these tools to visualize the simulation\n"
547 " trace. Keep in mind that the trace might be incomplete, without all the\n"
548 " information that would be registered otherwise.", detailed);
549 print_line (OPT_TRACING_DISPLAY_SIZES, "Only works for SMPI now. Add message size information",
550 " Message size (in bytes) is added to links, and to states. For collectives,\n"
551 " the displayed value is the more relevant to the collective (total sent by\n"
552 " the process, usually)", detailed);
553 print_line (OPT_TRACING_FORMAT, "Only works for SMPI now. Switch output format",
554 " Default format is Paje. Time independent traces are also supported,\n"
555 " to output traces that can later be used by the trace replay tool", detailed);
556 print_line (OPT_TRACING_FORMAT_TI_ONEFILE, "Only works for SMPI now, and TI output format",
557 " By default, each process outputs to a separate file, inside a filename_files folder\n"
558 " By setting this option to yes, all processes will output to only one file\n"
559 " This is meant to avoid opening thousands of files with large simulations", detailed);
560 print_line (OPT_TRACING_COMMENT, "Comment to be added on the top of the trace file.",
561 " Use this to add a comment line to the top of the trace file.", detailed);
562 print_line (OPT_TRACING_COMMENT_FILE, "File contents added to trace file as comment.",
563 " Use this to add the contents of a file to the top of the trace file as comment.", detailed);
564 print_line (OPT_VIVA_UNCAT_CONF, "Generate a graph configuration for Viva",
565 " This option can be used in all types of simulators build with SimGrid\n"
566 " to generate a uncategorized resource utilization graph to be used as\n"
567 " configuration for the Viva visualization tool. This option\n"
568 " can be used with tracing/categorized:1 and tracing:1 options to\n"
569 " analyze an unmodified simulator before changing it to contain\n"
570 " categories.", detailed);
571 print_line (OPT_VIVA_CAT_CONF, "Generate an uncategorized graph configuration for Viva",
572 " This option can be used if this simulator uses tracing categories\n"
573 " in its code. The file specified by this option holds a graph configuration\n"
574 " file for the Viva visualization tool that can be used to analyze a categorized\n"
575 " resource utilization.", detailed);
576 print_line (OPT_TRACING_TOPOLOGY, "Register the platform topology as a graph",
577 " This option (enabled by default) can be used to disable the tracing of\n"
578 " the platform topology in the trace file. Sometimes, such task is really\n"
579 " time consuming, since it must get the route from each host ot other hosts\n"
580 " within the same Autonomous System (AS).", detailed);
583 static void output_types (const char *name, xbt_dynar_t types, FILE *file)
586 fprintf (file, " %s = (", name);
587 for (i = xbt_dynar_length(types); i > 0; i--) {
588 char *type = *(char**)xbt_dynar_get_ptr(types, i - 1);
589 fprintf (file, "\"%s\"", type);
593 fprintf (file, ");\n");
596 xbt_dynar_free (&types);
599 static void output_categories (const char *name, xbt_dynar_t cats, FILE *file)
602 fprintf (file, " values = (");
603 for (i = xbt_dynar_length(cats); i > 0; i--) {
604 char *cat = *(char**)xbt_dynar_get_ptr(cats, i - 1);
605 fprintf (file, "\"%s%s\"", name, cat);
609 fprintf (file, ");\n");
612 xbt_dynar_free (&cats);
615 static void uncat_configuration (FILE *file)
617 //register NODE and EDGE types
618 output_types ("node", TRACE_get_node_types(), file);
619 output_types ("edge", TRACE_get_edge_types(), file);
620 fprintf (file, "\n");
622 //configuration for all nodes
625 " type = \"square\";\n"
626 " size = \"power\";\n"
627 " values = (\"power_used\");\n"
630 " type = \"rhombus\";\n"
631 " size = \"bandwidth\";\n"
632 " values = (\"bandwidth_used\");\n"
637 static void cat_configuration (FILE *file)
639 //register NODE and EDGE types
640 output_types ("node", TRACE_get_node_types(), file);
641 output_types ("edge", TRACE_get_edge_types(), file);
642 fprintf (file, "\n");
644 //configuration for all nodes
647 " type = \"square\";\n"
648 " size = \"power\";\n");
649 output_categories ("p", TRACE_get_categories(), file);
653 " type = \"rhombus\";\n"
654 " size = \"bandwidth\";\n");
655 output_categories ("b", TRACE_get_categories(), file);
656 fprintf (file, " };\n");
660 static void generate_uncat_configuration (const char *output, const char *name, int brackets)
662 if (output && strlen(output) > 0){
663 FILE *file = fopen (output, "w");
665 THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph "
666 "configuration (uncategorized).", output, name);
669 if (brackets) fprintf (file, "{\n");
670 uncat_configuration (file);
671 if (brackets) fprintf (file, "}\n");
676 static void generate_cat_configuration (const char *output, const char *name, int brackets)
678 if (output && strlen(output) > 0){
679 //check if we do have categories declared
680 if (xbt_dict_is_empty(created_categories)){
681 XBT_INFO("No categories declared, ignoring generation of %s graph configuration", name);
685 FILE *file = fopen (output, "w");
687 THROWF (system_error, 1, "Unable to open file (%s) for writing %s graph "
688 "configuration (categorized).", output, name);
691 if (brackets) fprintf (file, "{\n");
692 cat_configuration (file);
693 if (brackets) fprintf (file, "}\n");
698 void TRACE_generate_viva_uncat_conf (void)
700 generate_uncat_configuration (TRACE_get_viva_uncat_conf (), "viva", 0);
703 void TRACE_generate_viva_cat_conf (void)
705 generate_cat_configuration (TRACE_get_viva_cat_conf(), "viva", 0);
708 static int previous_trace_state = -1;
710 void instr_pause_tracing (void)
712 previous_trace_state = trace_enabled;
713 if (!TRACE_is_enabled()){
714 XBT_DEBUG ("Tracing is already paused, therefore do nothing.");
716 XBT_DEBUG ("Tracing is being paused.");
719 XBT_DEBUG ("Tracing is paused.");
722 void instr_resume_tracing (void)
724 if (TRACE_is_enabled()){
725 XBT_DEBUG ("Tracing is already running while trying to resume, therefore do nothing.");
727 XBT_DEBUG ("Tracing is being resumed.");
730 if (previous_trace_state != -1){
731 trace_enabled = previous_trace_state;
735 XBT_DEBUG ("Tracing is resumed.");
736 previous_trace_state = -1;
740 #undef OPT_TRACING_PLATFORM
741 #undef OPT_TRACING_TOPOLOGY
742 #undef OPT_TRACING_SMPI
743 #undef OPT_TRACING_SMPI_GROUP
744 #undef OPT_TRACING_CATEGORIZED
745 #undef OPT_TRACING_UNCATEGORIZED
746 #undef OPT_TRACING_MSG_PROCESS
747 #undef OPT_TRACING_FILENAME
748 #undef OPT_TRACING_BUFFER
749 #undef OPT_TRACING_ONELINK_ONLY
750 #undef OPT_TRACING_DISABLE_DESTROY
751 #undef OPT_TRACING_BASIC
752 #undef OPT_TRACING_COMMENT
753 #undef OPT_TRACING_COMMENT_FILE
754 #undef OPT_VIVA_UNCAT_CONF
755 #undef OPT_VIVA_CAT_CONF