1 /* Copyright (c) 2010. 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. */
8 #include "instr/instr_private.h"
12 XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)");
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
15 #define OPT_TRACING "tracing"
16 #define OPT_TRACING_PLATFORM "tracing/platform"
17 #define OPT_TRACING_SMPI "tracing/smpi"
18 #define OPT_TRACING_SMPI_GROUP "tracing/smpi/group"
19 #define OPT_TRACING_CATEGORIZED "tracing/categorized"
20 #define OPT_TRACING_UNCATEGORIZED "tracing/uncategorized"
21 #define OPT_TRACING_MSG_TASK "tracing/msg/task"
22 #define OPT_TRACING_MSG_PROCESS "tracing/msg/process"
23 #define OPT_TRACING_FILENAME "tracing/filename"
24 #define OPT_TRACING_BUFFER "tracing/buffer"
25 #define OPT_TRACING_ONELINK_ONLY "tracing/onelink_only"
26 #define OPT_TRACING_DISABLE_DESTROY "tracing/disable_destroy"
27 #define OPT_TRIVA_UNCAT_CONF "triva/uncategorized"
28 #define OPT_TRIVA_CAT_CONF "triva/categorized"
30 static int trace_enabled;
31 static int trace_platform;
32 static int trace_smpi_enabled;
33 static int trace_smpi_grouped;
34 static int trace_categorized;
35 static int trace_uncategorized;
36 static int trace_msg_task_enabled;
37 static int trace_msg_process_enabled;
38 static int trace_buffer;
39 static int trace_onelink_only;
40 static int trace_disable_destroy;
42 static int trace_configured = 0;
43 static int trace_active = 0;
45 xbt_dict_t created_categories; //declared in instr_interface.c
47 static void TRACE_getopts(void)
49 trace_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
50 trace_platform = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
51 trace_smpi_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
52 trace_smpi_grouped = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
53 trace_categorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
54 trace_uncategorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
55 trace_msg_task_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
56 trace_msg_process_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
57 trace_buffer = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_BUFFER);
58 trace_onelink_only = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_ONELINK_ONLY);
59 trace_disable_destroy = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_DISABLE_DESTROY);
66 // tracing system must be:
67 // - enabled (with --cfg=tracing:1)
68 // - already configured (TRACE_global_init already called)
69 if (!(TRACE_is_enabled() && TRACE_is_configured())){
73 XBT_DEBUG("Tracing starts");
75 /* open the trace file */
79 xbt_assert (trace_active==0, "Tracing is already active.");
81 XBT_DEBUG ("Tracing is on");
83 /* other trace initialization */
84 created_categories = xbt_dict_new();
95 /* generate uncategorized graph configuration for triva */
96 if (TRACE_get_triva_uncat_conf()){
97 TRACE_generate_triva_uncat_conf();
100 /* generate categorized graph configuration for triva */
101 if (TRACE_get_triva_cat_conf()){
102 TRACE_generate_triva_cat_conf();
105 /* dump trace buffer */
106 TRACE_last_timestamp_to_dump = surf_get_clock();
107 TRACE_paje_dump_buffer(1);
109 /* destroy all data structures of tracing (and free) */
110 destroyAllContainers();
112 /* close the trace file */
115 /* de-activate trace */
117 XBT_DEBUG ("Tracing is off");
118 XBT_DEBUG("Tracing system is shutdown");
122 int TRACE_needs_platform (void)
124 return TRACE_msg_process_is_enabled() ||
125 TRACE_msg_task_is_enabled() ||
126 TRACE_categorized() ||
127 TRACE_uncategorized() ||
129 (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
132 int TRACE_is_enabled(void)
134 return trace_enabled;
137 int TRACE_platform(void)
139 return trace_platform;
142 int TRACE_is_configured(void)
144 return trace_configured;
147 int TRACE_smpi_is_enabled(void)
149 return (xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI) ||
150 TRACE_smpi_is_grouped())&&
154 int TRACE_smpi_is_grouped(void)
156 return trace_smpi_grouped;
159 int TRACE_categorized (void)
161 return trace_categorized;
164 int TRACE_uncategorized (void)
166 return trace_uncategorized;
169 int TRACE_msg_task_is_enabled(void)
171 return trace_msg_task_enabled && TRACE_is_enabled();
174 int TRACE_msg_process_is_enabled(void)
176 return trace_msg_process_enabled && TRACE_is_enabled();
179 int TRACE_buffer (void)
181 return trace_buffer && TRACE_is_enabled();
184 int TRACE_onelink_only (void)
186 return trace_onelink_only && TRACE_is_enabled();
189 int TRACE_disable_destroy (void)
191 return trace_disable_destroy && TRACE_is_enabled();
194 char *TRACE_get_filename(void)
196 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
199 char *TRACE_get_triva_uncat_conf (void)
201 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
204 char *TRACE_get_triva_cat_conf (void)
206 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
209 void TRACE_global_init(int *argc, char **argv)
211 /* name of the tracefile */
212 char *default_tracing_filename = xbt_strdup("simgrid.trace");
213 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
214 "Trace file created by the instrumented SimGrid.",
215 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
219 int default_tracing = 0;
220 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
222 xbt_cfgelm_int, &default_tracing, 0, 1,
225 /* tracing platform*/
226 int default_tracing_platform = 0;
227 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
228 "Enable Tracing Platform.",
229 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
233 int default_tracing_smpi = 0;
234 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
235 "Tracing of the SMPI interface.",
236 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
240 int default_tracing_smpi_grouped = 0;
241 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
242 "Group MPI processes by host.",
243 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
248 int default_tracing_categorized = 0;
249 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
250 "Tracing of categorized platform (host and link) utilization.",
251 xbt_cfgelm_int, &default_tracing_categorized, 0, 1,
254 /* tracing uncategorized resource utilization */
255 int default_tracing_uncategorized = 0;
256 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
257 "Tracing of uncategorized resource (host and link) utilization.",
258 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
262 int default_tracing_msg_task = 0;
263 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
264 "Tracing of MSG task behavior.",
265 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
269 int default_tracing_msg_process = 0;
270 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
271 "Tracing of MSG process behavior.",
272 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
276 int default_buffer = 0;
277 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_BUFFER,
278 "Buffer trace events to put them in temporal order.",
279 xbt_cfgelm_int, &default_buffer, 0, 1,
282 /* tracing one link only */
283 int default_onelink_only = 0;
284 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_ONELINK_ONLY,
285 "Use only routes with one link to trace platform.",
286 xbt_cfgelm_int, &default_onelink_only, 0, 1,
289 /* disable destroy */
290 int default_disable_destroy = 0;
291 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_DISABLE_DESTROY,
292 "Disable platform containers destruction.",
293 xbt_cfgelm_int, &default_disable_destroy, 0, 1,
296 /* Triva graph configuration for uncategorized tracing */
297 char *default_triva_uncat_conf_file = xbt_strdup ("");
298 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
299 "Triva Graph configuration file for uncategorized resource utilization traces.",
300 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
303 /* Triva graph configuration for uncategorized tracing */
304 char *default_triva_cat_conf_file = xbt_strdup ("");
305 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
306 "Triva Graph configuration file for categorized resource utilization traces.",
307 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
310 /* instrumentation can be considered configured now */
311 trace_configured = 1;
314 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
316 char str[INSTR_DEFAULT_STR_SIZE];
317 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
319 int len = strlen (str);
320 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
321 if (!!longdesc && detailed){
322 printf ("%s\n\n", longdesc);
326 void TRACE_help (int detailed)
329 "Description of the tracing options accepted by this simulator:\n\n");
330 print_line (OPT_TRACING, "Enable the tracing system",
331 " It activates the tracing system and register the simulation platform\n"
332 " in the trace file. You have to enable this option to others take effect.",
334 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
335 " It activates the categorized resource utilization tracing. It should\n"
336 " be enabled if tracing categories are used by this simulator.",
338 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
339 " It activates the uncategorized resource utilization tracing. Use it if\n"
340 " this simulator do not use tracing categories and resource use have to be\n"
343 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
344 " A file with this name will be created to register the simulation. The file\n"
345 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
346 " tools. More information can be found in these webpages:\n"
347 " http://triva.gforge.inria.fr/\n"
348 " http://paje.sourceforge.net/",
350 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
351 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
352 " interface and generates a trace that can be analyzed using Gantt-like\n"
353 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
354 " state, and point-to-point communications can be analyzed with arrows.",
356 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
357 " This option only has effect if this simulator is SMPI-based. The processes\n"
358 " are grouped by the hosts where they were executed.",
360 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
361 " This option only has effect if this simulator is MSG-based. It traces the\n"
362 " behavior of all categorized MSG tasks, grouping them by hosts.",
364 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
365 " This option only has effect if this simulator is MSG-based. It traces the\n"
366 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
367 " can be used to track process location if this simulator has process migration.",
369 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
370 " This option put some events in a time-ordered buffer using the insertion\n"
371 " sort algorithm. The process of acquiring and releasing locks to access this\n"
372 " buffer and the cost of the sorting algorithm make this process slow. The\n"
373 " simulator performance can be severely impacted if this option is activated,\n"
374 " but you are sure to get a trace file with events sorted.",
376 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
377 " This option changes the way SimGrid register its platform on the trace file.\n"
378 " Normally, the tracing considers all routes (no matter their size) on the\n"
379 " platform file to re-create the resource topology. If this option is activated,\n"
380 " only the routes with one link are used to register the topology within an AS.\n"
381 " Routes among AS continue to be traced as usual.",
383 print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
384 " Disable the destruction of containers at the end of simulation. This can be\n"
385 " used with simulators that have a different notion of time (different from\n"
386 " the simulated time).",
388 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
389 " This option can be used in all types of simulators build with SimGrid\n"
390 " to generate a uncategorized resource utilization graph to be used as\n"
391 " configuration for the Triva visualization analysis. This option\n"
392 " can be used with tracing/categorized:1 and tracing:1 options to\n"
393 " analyze an unmodified simulator before changing it to contain\n"
396 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
397 " This option can be used if this simulator uses tracing categories\n"
398 " in its code. The file specified by this option holds a graph configuration\n"
399 " file for the Triva visualization tool that can be used to analyze a categorized\n"
400 " resource utilization.",
404 void TRACE_generate_triva_uncat_conf (void)
406 char *output = TRACE_get_triva_uncat_conf ();
407 if (output && strlen(output) > 0){
408 xbt_dict_cursor_t cursor=NULL;
411 FILE *file = fopen (output, "w");
412 xbt_assert (file != NULL,
413 "Unable to open file (%s) for writing triva graph "
414 "configuration (uncategorized).", output);
417 fprintf (file, "{\n");
419 //register NODE types
420 fprintf (file, " node = (");
421 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
422 fprintf (file, "%s, ", name);
425 //register EDGE types
429 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
430 fprintf (file, "%s, ", name);
436 //configuration for all nodes
441 " values = (power_used);\n"
445 " size = bandwidth;\n"
446 " values = (bandwidth_used);\n"
449 fprintf (file, "}\n");
454 void TRACE_generate_triva_cat_conf (void)
456 char *output = TRACE_get_triva_cat_conf();
457 if (output && strlen(output) > 0){
458 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
459 char *name, *name2, *value, *value2;
461 //check if we do have categories declared
462 if (xbt_dict_is_empty(created_categories)){
463 XBT_INFO("No categories declared, ignoring generation of triva graph configuration");
467 FILE *file = fopen (output, "w");
468 xbt_assert (file != NULL,
469 "Unable to open file (%s) for writing triva graph "
470 "configuration (categorized).", output);
473 fprintf (file, "{\n");
475 //register NODE types
476 fprintf (file, " node = (");
477 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
478 fprintf (file, "%s, ", name);
481 //register EDGE types
485 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
486 fprintf (file, "%s, ", name);
492 //configuration for all nodes
498 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
499 fprintf (file, "p%s, ", name2);
506 " size = bandwidth;\n"
508 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
509 fprintf (file, "b%s, ", name2);
515 fprintf (file, "}\n");
521 #undef OPT_TRACING_PLATFORM
522 #undef OPT_TRACING_SMPI
523 #undef OPT_TRACING_SMPI_GROUP
524 #undef OPT_TRACING_CATEGORIZED
525 #undef OPT_TRACING_UNCATEGORIZED
526 #undef OPT_TRACING_MSG_TASK
527 #undef OPT_TRACING_MSG_PROCESS
528 #undef OPT_TRACING_FILENAME
529 #undef OPT_TRACING_BUFFER
530 #undef OPT_TRACING_ONELINK_ONLY
531 #undef OPT_TRACING_DISABLE_DESTROY
532 #undef OPT_TRIVA_UNCAT_CONF
533 #undef OPT_TRIVA_CAT_CONF
535 #endif /* HAVE_TRACING */