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_PROCESS "tracing/msg/process"
22 #define OPT_TRACING_FILENAME "tracing/filename"
23 #define OPT_TRACING_BUFFER "tracing/buffer"
24 #define OPT_TRACING_ONELINK_ONLY "tracing/onelink_only"
25 #define OPT_TRACING_DISABLE_DESTROY "tracing/disable_destroy"
26 #define OPT_TRIVA_UNCAT_CONF "triva/uncategorized"
27 #define OPT_TRIVA_CAT_CONF "triva/categorized"
29 static int trace_enabled;
30 static int trace_platform;
31 static int trace_smpi_enabled;
32 static int trace_smpi_grouped;
33 static int trace_categorized;
34 static int trace_uncategorized;
35 static int trace_msg_process_enabled;
36 static int trace_buffer;
37 static int trace_onelink_only;
38 static int trace_disable_destroy;
40 static int trace_configured = 0;
41 static int trace_active = 0;
43 static void TRACE_getopts(void)
45 trace_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
46 trace_platform = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
47 trace_smpi_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
48 trace_smpi_grouped = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
49 trace_categorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
50 trace_uncategorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
51 trace_msg_process_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
52 trace_buffer = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_BUFFER);
53 trace_onelink_only = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_ONELINK_ONLY);
54 trace_disable_destroy = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_DISABLE_DESTROY);
61 // tracing system must be:
62 // - enabled (with --cfg=tracing:1)
63 // - already configured (TRACE_global_init already called)
64 if (!(TRACE_is_enabled() && TRACE_is_configured())){
68 XBT_DEBUG("Tracing starts");
70 /* open the trace file */
74 if (trace_active == 1){
75 THROWF (tracing_error, 0, "Tracing is already active");
78 XBT_DEBUG ("Tracing is on");
80 /* other trace initialization */
81 created_categories = xbt_dict_new_homogeneous(xbt_free);
82 declared_marks = xbt_dict_new_homogeneous (xbt_free);
83 user_host_variables = xbt_dict_new_homogeneous (xbt_free);
84 user_link_variables = xbt_dict_new_homogeneous (xbt_free);
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 PJ_container_free_all();
112 PJ_container_release();
114 TRACE_surf_release();
115 TRACE_smpi_release();
116 xbt_dict_free(&created_categories);
118 /* close the trace file */
121 /* de-activate trace */
123 XBT_DEBUG ("Tracing is off");
124 XBT_DEBUG("Tracing system is shutdown");
128 int TRACE_needs_platform (void)
130 return TRACE_msg_process_is_enabled() ||
131 TRACE_categorized() ||
132 TRACE_uncategorized() ||
134 (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
137 int TRACE_is_enabled(void)
139 return trace_enabled;
142 int TRACE_platform(void)
144 return trace_platform;
147 int TRACE_is_configured(void)
149 return trace_configured;
152 int TRACE_smpi_is_enabled(void)
154 return (trace_smpi_enabled || TRACE_smpi_is_grouped())
155 && TRACE_is_enabled();
158 int TRACE_smpi_is_grouped(void)
160 return trace_smpi_grouped;
163 int TRACE_categorized (void)
165 return trace_categorized;
168 int TRACE_uncategorized (void)
170 return trace_uncategorized;
173 int TRACE_msg_process_is_enabled(void)
175 return trace_msg_process_enabled && TRACE_is_enabled();
178 int TRACE_buffer (void)
180 return trace_buffer && TRACE_is_enabled();
183 int TRACE_onelink_only (void)
185 return trace_onelink_only && TRACE_is_enabled();
188 int TRACE_disable_destroy (void)
190 return trace_disable_destroy && TRACE_is_enabled();
193 char *TRACE_get_filename(void)
195 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
198 char *TRACE_get_triva_uncat_conf (void)
200 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
203 char *TRACE_get_triva_cat_conf (void)
205 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
208 void TRACE_global_init(int *argc, char **argv)
210 /* name of the tracefile */
211 char *default_tracing_filename = xbt_strdup("simgrid.trace");
212 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
213 "Trace file created by the instrumented SimGrid.",
214 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
218 int default_tracing = 0;
219 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
221 xbt_cfgelm_int, &default_tracing, 0, 1,
224 /* register platform in the trace */
225 int default_tracing_platform = 0;
226 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
227 "Register the platform in the trace as a graph.",
228 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
232 int default_tracing_smpi = 0;
233 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
234 "Tracing of the SMPI interface.",
235 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
239 int default_tracing_smpi_grouped = 0;
240 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
241 "Group MPI processes by host.",
242 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
246 /* tracing categorized resource utilization traces */
247 int default_tracing_categorized = 0;
248 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
249 "Tracing categorized resource utilization of hosts and links.",
250 xbt_cfgelm_int, &default_tracing_categorized, 0, 1,
253 /* tracing uncategorized resource utilization */
254 int default_tracing_uncategorized = 0;
255 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
256 "Tracing uncategorized resource utilization of hosts and links.",
257 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
261 int default_tracing_msg_process = 0;
262 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
263 "Tracing of MSG process behavior.",
264 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
268 int default_buffer = 1;
269 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_BUFFER,
270 "Buffer trace events to put them in temporal order.",
271 xbt_cfgelm_int, &default_buffer, 0, 1,
274 /* tracing one link only */
275 int default_onelink_only = 0;
276 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_ONELINK_ONLY,
277 "Use only routes with one link to trace platform.",
278 xbt_cfgelm_int, &default_onelink_only, 0, 1,
281 /* disable destroy */
282 int default_disable_destroy = 0;
283 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_DISABLE_DESTROY,
284 "Disable platform containers destruction.",
285 xbt_cfgelm_int, &default_disable_destroy, 0, 1,
288 /* Triva graph configuration for uncategorized tracing */
289 char *default_triva_uncat_conf_file = xbt_strdup ("");
290 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
291 "Triva Graph configuration file for uncategorized resource utilization traces.",
292 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
295 /* Triva graph configuration for uncategorized tracing */
296 char *default_triva_cat_conf_file = xbt_strdup ("");
297 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
298 "Triva Graph configuration file for categorized resource utilization traces.",
299 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
302 /* instrumentation can be considered configured now */
303 trace_configured = 1;
306 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
308 char str[INSTR_DEFAULT_STR_SIZE];
309 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
311 int len = strlen (str);
312 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
313 if (!!longdesc && detailed){
314 printf ("%s\n\n", longdesc);
318 void TRACE_help (int detailed)
321 "Description of the tracing options accepted by this simulator:\n\n");
322 print_line (OPT_TRACING, "Enable the tracing system",
323 " It activates the tracing system and register the simulation platform\n"
324 " in the trace file. You have to enable this option to others take effect.",
326 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
327 " It activates the categorized resource utilization tracing. It should\n"
328 " be enabled if tracing categories are used by this simulator.",
330 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
331 " It activates the uncategorized resource utilization tracing. Use it if\n"
332 " this simulator do not use tracing categories and resource use have to be\n"
335 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
336 " A file with this name will be created to register the simulation. The file\n"
337 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
338 " tools. More information can be found in these webpages:\n"
339 " http://triva.gforge.inria.fr/\n"
340 " http://paje.sourceforge.net/",
342 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
343 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
344 " interface and generates a trace that can be analyzed using Gantt-like\n"
345 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
346 " state, and point-to-point communications can be analyzed with arrows.",
348 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
349 " This option only has effect if this simulator is SMPI-based. The processes\n"
350 " are grouped by the hosts where they were executed.",
352 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
353 " This option only has effect if this simulator is MSG-based. It traces the\n"
354 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
355 " can be used to track process location if this simulator has process migration.",
357 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
358 " This option put some events in a time-ordered buffer using the insertion\n"
359 " sort algorithm. The process of acquiring and releasing locks to access this\n"
360 " buffer and the cost of the sorting algorithm make this process slow. The\n"
361 " simulator performance can be severely impacted if this option is activated,\n"
362 " but you are sure to get a trace file with events sorted.",
364 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
365 " This option changes the way SimGrid register its platform on the trace file.\n"
366 " Normally, the tracing considers all routes (no matter their size) on the\n"
367 " platform file to re-create the resource topology. If this option is activated,\n"
368 " only the routes with one link are used to register the topology within an AS.\n"
369 " Routes among AS continue to be traced as usual.",
371 print_line (OPT_TRACING_DISABLE_DESTROY, "Disable platform containers destruction",
372 " Disable the destruction of containers at the end of simulation. This can be\n"
373 " used with simulators that have a different notion of time (different from\n"
374 " the simulated time).",
376 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
377 " This option can be used in all types of simulators build with SimGrid\n"
378 " to generate a uncategorized resource utilization graph to be used as\n"
379 " configuration for the Triva visualization analysis. This option\n"
380 " can be used with tracing/categorized:1 and tracing:1 options to\n"
381 " analyze an unmodified simulator before changing it to contain\n"
384 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
385 " This option can be used if this simulator uses tracing categories\n"
386 " in its code. The file specified by this option holds a graph configuration\n"
387 " file for the Triva visualization tool that can be used to analyze a categorized\n"
388 " resource utilization.",
392 void TRACE_generate_triva_uncat_conf (void)
394 char *output = TRACE_get_triva_uncat_conf ();
395 if (output && strlen(output) > 0){
396 xbt_dict_cursor_t cursor=NULL;
399 FILE *file = fopen (output, "w");
401 THROWF (system_error, 1, "Unable to open file (%s) for writing triva graph "
402 "configuration (uncategorized).", output);
406 fprintf (file, "{\n");
408 //register NODE types
409 fprintf (file, " node = (");
410 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
411 fprintf (file, "%s, ", name);
414 //register EDGE types
418 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
419 fprintf (file, "%s, ", name);
425 //configuration for all nodes
430 " values = (power_used);\n"
434 " size = bandwidth;\n"
435 " values = (bandwidth_used);\n"
438 fprintf (file, "}\n");
443 void TRACE_generate_triva_cat_conf (void)
445 char *output = TRACE_get_triva_cat_conf();
446 if (output && strlen(output) > 0){
447 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
448 char *name, *name2, *value, *value2;
450 //check if we do have categories declared
451 if (xbt_dict_is_empty(created_categories)){
452 XBT_INFO("No categories declared, ignoring generation of triva graph configuration");
456 FILE *file = fopen (output, "w");
458 THROWF (system_error, 1, "Unable to open file (%s) for writing triva graph "
459 "configuration (categorized).", output);
463 fprintf (file, "{\n");
465 //register NODE types
466 fprintf (file, " node = (");
467 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
468 fprintf (file, "%s, ", name);
471 //register EDGE types
475 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
476 fprintf (file, "%s, ", name);
482 //configuration for all nodes
488 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
489 fprintf (file, "p%s, ", name2);
496 " size = bandwidth;\n"
498 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
499 fprintf (file, "b%s, ", name2);
505 fprintf (file, "}\n");
511 #undef OPT_TRACING_PLATFORM
512 #undef OPT_TRACING_SMPI
513 #undef OPT_TRACING_SMPI_GROUP
514 #undef OPT_TRACING_CATEGORIZED
515 #undef OPT_TRACING_UNCATEGORIZED
516 #undef OPT_TRACING_MSG_PROCESS
517 #undef OPT_TRACING_FILENAME
518 #undef OPT_TRACING_BUFFER
519 #undef OPT_TRACING_ONELINK_ONLY
520 #undef OPT_TRACING_DISABLE_DESTROY
521 #undef OPT_TRIVA_UNCAT_CONF
522 #undef OPT_TRIVA_CAT_CONF
524 #endif /* HAVE_TRACING */