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_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_task_enabled;
36 static int trace_msg_process_enabled;
37 static int trace_buffer;
38 static int trace_onelink_only;
40 static int trace_configured = 0;
41 static int trace_active = 0;
43 xbt_dict_t created_categories; //declared in instr_interface.c
45 static void TRACE_getopts(void)
47 trace_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
48 trace_platform = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
49 trace_smpi_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
50 trace_smpi_grouped = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
51 trace_categorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
52 trace_uncategorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
53 trace_msg_task_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
54 trace_msg_process_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
55 trace_buffer = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_BUFFER);
56 trace_onelink_only = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_ONELINK_ONLY);
63 // tracing system must be:
64 // - enabled (with --cfg=tracing:1)
65 // - already configured (TRACE_global_init already called)
66 if (!(TRACE_is_enabled() && TRACE_is_configured())){
70 XBT_DEBUG("Tracing starts");
72 /* open the trace file */
76 xbt_assert (trace_active==0, "Tracing is already active.");
78 XBT_DEBUG ("Tracing is on");
80 /* other trace initialization */
81 created_categories = xbt_dict_new();
92 /* generate uncategorized graph configuration for triva */
93 if (TRACE_get_triva_uncat_conf()){
94 TRACE_generate_triva_uncat_conf();
97 /* generate categorized graph configuration for triva */
98 if (TRACE_get_triva_cat_conf()){
99 TRACE_generate_triva_cat_conf();
102 /* dump trace buffer */
103 TRACE_last_timestamp_to_dump = surf_get_clock();
104 TRACE_paje_dump_buffer(1);
106 /* destroy all data structures of tracing (and free) */
107 destroyAllContainers();
109 /* close the trace file */
112 /* de-activate trace */
114 XBT_DEBUG ("Tracing is off");
115 XBT_DEBUG("Tracing system is shutdown");
119 int TRACE_needs_platform (void)
121 return TRACE_msg_process_is_enabled() ||
122 TRACE_msg_task_is_enabled() ||
123 TRACE_categorized() ||
124 TRACE_uncategorized() ||
126 (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
129 int TRACE_is_enabled(void)
131 return trace_enabled;
134 int TRACE_platform(void)
136 return trace_platform;
139 int TRACE_is_configured(void)
141 return trace_configured;
144 int TRACE_smpi_is_enabled(void)
146 return (xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI) ||
147 TRACE_smpi_is_grouped())&&
151 int TRACE_smpi_is_grouped(void)
153 return trace_smpi_grouped;
156 int TRACE_categorized (void)
158 return trace_categorized;
161 int TRACE_uncategorized (void)
163 return trace_uncategorized;
166 int TRACE_msg_task_is_enabled(void)
168 return trace_msg_task_enabled && TRACE_is_enabled();
171 int TRACE_msg_process_is_enabled(void)
173 return trace_msg_process_enabled && TRACE_is_enabled();
176 int TRACE_buffer (void)
178 return trace_buffer && TRACE_is_enabled();
181 int TRACE_onelink_only (void)
183 return trace_onelink_only && TRACE_is_enabled();
186 char *TRACE_get_filename(void)
188 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
191 char *TRACE_get_triva_uncat_conf (void)
193 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
196 char *TRACE_get_triva_cat_conf (void)
198 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
201 void TRACE_global_init(int *argc, char **argv)
203 /* name of the tracefile */
204 char *default_tracing_filename = xbt_strdup("simgrid.trace");
205 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
206 "Trace file created by the instrumented SimGrid.",
207 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
211 int default_tracing = 0;
212 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
214 xbt_cfgelm_int, &default_tracing, 0, 1,
217 /* tracing platform*/
218 int default_tracing_platform = 0;
219 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
220 "Enable Tracing Platform.",
221 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
225 int default_tracing_smpi = 0;
226 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
227 "Tracing of the SMPI interface.",
228 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
232 int default_tracing_smpi_grouped = 0;
233 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
234 "Group MPI processes by host.",
235 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
240 int default_tracing_categorized = 0;
241 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
242 "Tracing of categorized platform (host and link) utilization.",
243 xbt_cfgelm_int, &default_tracing_categorized, 0, 1,
246 /* tracing uncategorized resource utilization */
247 int default_tracing_uncategorized = 0;
248 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
249 "Tracing of uncategorized resource (host and link) utilization.",
250 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
254 int default_tracing_msg_task = 0;
255 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
256 "Tracing of MSG task behavior.",
257 xbt_cfgelm_int, &default_tracing_msg_task, 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 = 0;
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 /* Triva graph configuration for uncategorized tracing */
282 char *default_triva_uncat_conf_file = xbt_strdup ("");
283 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
284 "Triva Graph configuration file for uncategorized resource utilization traces.",
285 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
288 /* Triva graph configuration for uncategorized tracing */
289 char *default_triva_cat_conf_file = xbt_strdup ("");
290 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
291 "Triva Graph configuration file for categorized resource utilization traces.",
292 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
295 /* instrumentation can be considered configured now */
296 trace_configured = 1;
299 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
301 char str[INSTR_DEFAULT_STR_SIZE];
302 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
304 int len = strlen (str);
305 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
306 if (!!longdesc && detailed){
307 printf ("%s\n\n", longdesc);
311 void TRACE_help (int detailed)
314 "Description of the tracing options accepted by this simulator:\n\n");
315 print_line (OPT_TRACING, "Enable the tracing system",
316 " It activates the tracing system and register the simulation platform\n"
317 " in the trace file. You have to enable this option to others take effect.",
319 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
320 " It activates the categorized resource utilization tracing. It should\n"
321 " be enabled if tracing categories are used by this simulator.",
323 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
324 " It activates the uncategorized resource utilization tracing. Use it if\n"
325 " this simulator do not use tracing categories and resource use have to be\n"
328 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
329 " A file with this name will be created to register the simulation. The file\n"
330 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
331 " tools. More information can be found in these webpages:\n"
332 " http://triva.gforge.inria.fr/\n"
333 " http://paje.sourceforge.net/",
335 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
336 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
337 " interface and generates a trace that can be analyzed using Gantt-like\n"
338 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
339 " state, and point-to-point communications can be analyzed with arrows.",
341 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
342 " This option only has effect if this simulator is SMPI-based. The processes\n"
343 " are grouped by the hosts where they were executed.",
345 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
346 " This option only has effect if this simulator is MSG-based. It traces the\n"
347 " behavior of all categorized MSG tasks, grouping them by hosts.",
349 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
350 " This option only has effect if this simulator is MSG-based. It traces the\n"
351 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
352 " can be used to track process location if this simulator has process migration.",
354 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
355 " This option put some events in a time-ordered buffer using the insertion\n"
356 " sort algorithm. The process of acquiring and releasing locks to access this\n"
357 " buffer and the cost of the sorting algorithm make this process slow. The\n"
358 " simulator performance can be severely impacted if this option is activated,\n"
359 " but you are sure to get a trace file with events sorted.",
361 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
362 " This option changes the way SimGrid register its platform on the trace file.\n"
363 " Normally, the tracing considers all routes (no matter their size) on the\n"
364 " platform file to re-create the resource topology. If this option is activated,\n"
365 " only the routes with one link are used to register the topology within an AS.\n"
366 " Routes among AS continue to be traced as usual.",
368 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
369 " This option can be used in all types of simulators build with SimGrid\n"
370 " to generate a uncategorized resource utilization graph to be used as\n"
371 " configuration for the Triva visualization analysis. This option\n"
372 " can be used with tracing/categorized:1 and tracing:1 options to\n"
373 " analyze an unmodified simulator before changing it to contain\n"
376 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
377 " This option can be used if this simulator uses tracing categories\n"
378 " in its code. The file specified by this option holds a graph configuration\n"
379 " file for the Triva visualization tool that can be used to analyze a categorized\n"
380 " resource utilization.",
384 void TRACE_generate_triva_uncat_conf (void)
386 char *output = TRACE_get_triva_uncat_conf ();
387 if (output && strlen(output) > 0){
388 xbt_dict_cursor_t cursor=NULL;
391 FILE *file = fopen (output, "w");
392 xbt_assert (file != NULL,
393 "Unable to open file (%s) for writing triva graph "
394 "configuration (uncategorized).", output);
397 fprintf (file, "{\n");
399 //register NODE types
400 fprintf (file, " node = (");
401 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
402 fprintf (file, "%s, ", name);
405 //register EDGE types
409 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
410 fprintf (file, "%s, ", name);
416 //configuration for all nodes
421 " values = (power_used);\n"
425 " size = bandwidth;\n"
426 " values = (bandwidth_used);\n"
429 fprintf (file, "}\n");
434 void TRACE_generate_triva_cat_conf (void)
436 char *output = TRACE_get_triva_cat_conf();
437 if (output && strlen(output) > 0){
438 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
439 char *name, *name2, *value, *value2;
441 //check if we do have categories declared
442 if (xbt_dict_length(created_categories) == 0){
443 XBT_INFO("No categories declared, ignoring generation of triva graph configuration");
447 FILE *file = fopen (output, "w");
448 xbt_assert (file != NULL,
449 "Unable to open file (%s) for writing triva graph "
450 "configuration (categorized).", output);
453 fprintf (file, "{\n");
455 //register NODE types
456 fprintf (file, " node = (");
457 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
458 fprintf (file, "%s, ", name);
461 //register EDGE types
465 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
466 fprintf (file, "%s, ", name);
472 //configuration for all nodes
478 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
479 fprintf (file, "p%s, ", name2);
486 " size = bandwidth;\n"
488 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
489 fprintf (file, "b%s, ", name2);
495 fprintf (file, "}\n");
501 #undef OPT_TRACING_PLATFORM
502 #undef OPT_TRACING_SMPI
503 #undef OPT_TRACING_SMPI_GROUP
504 #undef OPT_TRACING_CATEGORIZED
505 #undef OPT_TRACING_UNCATEGORIZED
506 #undef OPT_TRACING_MSG_TASK
507 #undef OPT_TRACING_MSG_PROCESS
508 #undef OPT_TRACING_FILENAME
509 #undef OPT_TRACING_BUFFER
510 #undef OPT_TRACING_ONELINK_ONLY
511 #undef OPT_TRACING_DISABLE_DESTROY
512 #undef OPT_TRIVA_UNCAT_CONF
513 #undef OPT_TRIVA_CAT_CONF
515 #endif /* HAVE_TRACING */