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_SMPI "tracing/smpi"
17 #define OPT_TRACING_SMPI_GROUP "tracing/smpi/group"
18 #define OPT_TRACING_CATEGORIZED "tracing/categorized"
19 #define OPT_TRACING_UNCATEGORIZED "tracing/uncategorized"
20 #define OPT_TRACING_MSG_TASK "tracing/msg/task"
21 #define OPT_TRACING_MSG_PROCESS "tracing/msg/process"
22 #define OPT_TRACING_MSG_VOLUME "tracing/msg/volume"
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_smpi_enabled;
31 static int trace_smpi_grouped;
32 static int trace_categorized;
33 static int trace_uncategorized;
34 static int trace_msg_task_enabled;
35 static int trace_msg_process_enabled;
36 static int trace_msg_volume_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_smpi_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
49 trace_smpi_grouped = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
50 trace_categorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
51 trace_uncategorized = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
52 trace_msg_task_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
53 trace_msg_process_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
54 trace_msg_volume_enabled = xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
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 */
78 /* other trace initialization */
79 created_categories = xbt_dict_new();
87 if (!TRACE_is_active())
90 /* generate uncategorized graph configuration for triva */
91 if (TRACE_get_triva_uncat_conf()){
92 TRACE_generate_triva_uncat_conf();
95 /* generate categorized graph configuration for triva */
96 if (TRACE_get_triva_cat_conf()){
97 TRACE_generate_triva_cat_conf();
100 /* dump trace buffer */
101 TRACE_last_timestamp_to_dump = surf_get_clock();
102 TRACE_paje_dump_buffer(1);
104 /* destroy all data structures of tracing (and free) */
105 destroyAllContainers();
107 /* close the trace file */
111 TRACE_desactivate ();
112 XBT_DEBUG("Tracing system is shutdown");
116 void TRACE_activate (void)
118 xbt_assert (trace_active==0, "Tracing is already active.");
120 XBT_DEBUG ("Tracing is on");
123 void TRACE_desactivate (void)
126 XBT_DEBUG ("Tracing is off");
129 int TRACE_is_active (void)
134 int TRACE_needs_platform (void)
136 return TRACE_categorized() ||
137 TRACE_uncategorized() ||
138 (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped());
141 int TRACE_is_enabled(void)
143 return trace_enabled;
146 int TRACE_is_configured(void)
148 return trace_configured;
151 int TRACE_smpi_is_enabled(void)
153 return trace_smpi_enabled && TRACE_is_enabled();
156 int TRACE_smpi_is_grouped(void)
158 return trace_smpi_grouped;
161 int TRACE_categorized (void)
163 return trace_categorized;
166 int TRACE_uncategorized (void)
168 return trace_uncategorized;
171 int TRACE_msg_task_is_enabled(void)
173 return trace_msg_task_enabled && TRACE_is_enabled();
176 int TRACE_msg_process_is_enabled(void)
178 return trace_msg_process_enabled && TRACE_is_enabled();
181 int TRACE_msg_volume_is_enabled(void)
183 return trace_msg_volume_enabled && TRACE_is_enabled();
186 int TRACE_buffer (void)
188 return trace_buffer && TRACE_is_enabled();
191 int TRACE_onelink_only (void)
193 return trace_onelink_only && TRACE_is_enabled();
196 char *TRACE_get_filename(void)
198 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
201 char *TRACE_get_triva_uncat_conf (void)
203 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
206 char *TRACE_get_triva_cat_conf (void)
208 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
211 void TRACE_global_init(int *argc, char **argv)
213 /* name of the tracefile */
214 char *default_tracing_filename = xbt_strdup("simgrid.trace");
215 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
216 "Trace file created by the instrumented SimGrid.",
217 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
221 int default_tracing = 0;
222 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
224 xbt_cfgelm_int, &default_tracing, 0, 1,
228 int default_tracing_smpi = 0;
229 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
230 "Tracing of the SMPI interface.",
231 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
235 int default_tracing_smpi_grouped = 0;
236 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
237 "Group MPI processes by host.",
238 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
243 int default_tracing_platform = 0;
244 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
245 "Tracing of categorized platform (host and link) utilization.",
246 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
249 /* tracing uncategorized resource utilization */
250 int default_tracing_uncategorized = 0;
251 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
252 "Tracing of uncategorized resource (host and link) utilization.",
253 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
257 int default_tracing_msg_task = 0;
258 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
259 "Tracing of MSG task behavior.",
260 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
264 int default_tracing_msg_process = 0;
265 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
266 "Tracing of MSG process behavior.",
267 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
270 /* msg volume (experimental) */
271 int default_tracing_msg_volume = 0;
272 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
273 "Tracing of MSG communication volume (experimental).",
274 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
277 /* msg volume (experimental) */
278 int default_buffer = 0;
279 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_BUFFER,
280 "Buffer trace events to put them in temporal order.",
281 xbt_cfgelm_int, &default_buffer, 0, 1,
284 /* msg volume (experimental) */
285 int default_onelink_only = 0;
286 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_ONELINK_ONLY,
287 "Use only routes with one link to trace platform.",
288 xbt_cfgelm_int, &default_onelink_only, 0, 1,
291 /* Triva graph configuration for uncategorized tracing */
292 char *default_triva_uncat_conf_file = xbt_strdup ("");
293 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
294 "Triva Graph configuration file for uncategorized resource utilization traces.",
295 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
298 /* Triva graph configuration for uncategorized tracing */
299 char *default_triva_cat_conf_file = xbt_strdup ("");
300 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
301 "Triva Graph configuration file for categorized resource utilization traces.",
302 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
305 /* instrumentation can be considered configured now */
306 trace_configured = 1;
309 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
311 char str[INSTR_DEFAULT_STR_SIZE];
312 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
314 int len = strlen (str);
315 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
316 if (!!longdesc && detailed){
317 printf ("%s\n\n", longdesc);
321 void TRACE_help (int detailed)
324 "Description of the tracing options accepted by this simulator:\n\n");
325 print_line (OPT_TRACING, "Enable the tracing system",
326 " It activates the tracing system and register the simulation platform\n"
327 " in the trace file. You have to enable this option to others take effect.",
329 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
330 " It activates the categorized resource utilization tracing. It should\n"
331 " be enabled if tracing categories are used by this simulator.",
333 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
334 " It activates the uncategorized resource utilization tracing. Use it if\n"
335 " this simulator do not use tracing categories and resource use have to be\n"
338 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
339 " A file with this name will be created to register the simulation. The file\n"
340 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
341 " tools. More information can be found in these webpages:\n"
342 " http://triva.gforge.inria.fr/\n"
343 " http://paje.sourceforge.net/",
345 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
346 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
347 " interface and generates a trace that can be analyzed using Gantt-like\n"
348 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
349 " state, and point-to-point communications can be analyzed with arrows.",
351 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
352 " This option only has effect if this simulator is SMPI-based. The processes\n"
353 " are grouped by the hosts where they were executed.",
355 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
356 " This option only has effect if this simulator is MSG-based. It traces the\n"
357 " behavior of all categorized MSG tasks, grouping them by hosts.",
359 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
360 " This option only has effect if this simulator is MSG-based. It traces the\n"
361 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
362 " can be used to track process location if this simulator has process migration.",
364 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
365 " This experimental option only has effect if this simulator is MSG-based.\n"
366 " It traces the communication volume of MSG send/receive.",
368 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
369 " This option put some events in a time-ordered buffer using the insertion\n"
370 " sort algorithm. The process of acquiring and releasing locks to access this\n"
371 " buffer and the cost of the sorting algorithm make this process slow. The\n"
372 " simulator performance can be severely impacted if this option is activated,\n"
373 " but you are sure to get a trace file with events sorted.",
375 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
376 " This option changes the way SimGrid register its platform on the trace file.\n"
377 " Normally, the tracing considers all routes (no matter their size) on the\n"
378 " platform file to re-create the resource topology. If this option is activated,\n"
379 " only the routes with one link are used to register the topology within an AS.\n"
380 " Routes among AS continue to be traced as usual.",
382 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
383 " This option can be used in all types of simulators build with SimGrid\n"
384 " to generate a uncategorized resource utilization graph to be used as\n"
385 " configuration for the Triva visualization analysis. This option\n"
386 " can be used with tracing/categorized:1 and tracing:1 options to\n"
387 " analyze an unmodified simulator before changing it to contain\n"
390 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
391 " This option can be used if this simulator uses tracing categories\n"
392 " in its code. The file specified by this option holds a graph configuration\n"
393 " file for the Triva visualization tool that can be used to analyze a categorized\n"
394 " resource utilization.",
398 void TRACE_generate_triva_uncat_conf (void)
400 char *output = TRACE_get_triva_uncat_conf ();
401 if (output && strlen(output) > 0){
402 xbt_dict_cursor_t cursor=NULL;
405 FILE *file = fopen (output, "w");
406 xbt_assert (file != NULL,
407 "Unable to open file (%s) for writing triva graph "
408 "configuration (uncategorized).", output);
411 fprintf (file, "{\n");
413 //register NODE types
414 fprintf (file, " node = (");
415 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
416 fprintf (file, "%s, ", name);
419 //register EDGE types
423 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
424 fprintf (file, "%s, ", name);
430 //configuration for all nodes
435 " values = (power_used);\n"
439 " size = bandwidth;\n"
440 " values = (bandwidth_used);\n"
443 fprintf (file, "}\n");
448 void TRACE_generate_triva_cat_conf (void)
450 char *output = TRACE_get_triva_cat_conf();
451 if (output && strlen(output) > 0){
452 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
453 char *name, *name2, *value, *value2;
455 //check if we do have categories declared
456 if (xbt_dict_length(created_categories) == 0){
457 XBT_INFO("No categories declared, ignoring generation of triva graph configuration");
461 FILE *file = fopen (output, "w");
462 xbt_assert (file != NULL,
463 "Unable to open file (%s) for writing triva graph "
464 "configuration (categorized).", output);
467 fprintf (file, "{\n");
469 //register NODE types
470 fprintf (file, " node = (");
471 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
472 fprintf (file, "%s, ", name);
475 //register EDGE types
479 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
480 fprintf (file, "%s, ", name);
486 //configuration for all nodes
492 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
493 fprintf (file, "p%s, ", name2);
500 " size = bandwidth;\n"
502 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
503 fprintf (file, "b%s, ", name2);
509 fprintf (file, "}\n");
515 #undef OPT_TRACING_SMPI
516 #undef OPT_TRACING_SMPI_GROUP
517 #undef OPT_TRACING_CATEGORIZED
518 #undef OPT_TRACING_UNCATEGORIZED
519 #undef OPT_TRACING_MSG_TASK
520 #undef OPT_TRACING_MSG_PROCESS
521 #undef OPT_TRACING_MSG_VOLUME
522 #undef OPT_TRACING_FILENAME
523 #undef OPT_TRACING_PLATFORM_METHOD
524 #undef OPT_TRIVA_UNCAT_CONF
525 #undef OPT_TRIVA_CAT_CONF
527 #endif /* HAVE_TRACING */