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_configured = 0;
30 static int trace_active = 0;
32 xbt_dict_t created_categories; //declared in instr_interface.c
36 // tracing system must be:
37 // - enabled (with --cfg=tracing:1)
38 // - already configured (TRACE_global_init already called)
39 if (!(TRACE_is_enabled() && TRACE_is_configured())){
43 XBT_DEBUG("Tracing starts");
45 /* open the trace file */
51 /* other trace initialization */
52 created_categories = xbt_dict_new();
60 if (!TRACE_is_active())
63 /* generate uncategorized graph configuration for triva */
64 if (TRACE_get_triva_uncat_conf()){
65 TRACE_generate_triva_uncat_conf();
68 /* generate categorized graph configuration for triva */
69 if (TRACE_get_triva_cat_conf()){
70 TRACE_generate_triva_cat_conf();
73 /* dump trace buffer */
74 TRACE_last_timestamp_to_dump = surf_get_clock();
75 TRACE_paje_dump_buffer(1);
77 /* destroy all data structures of tracing (and free) */
78 destroyAllContainers();
80 /* close the trace file */
85 XBT_DEBUG("Tracing system is shutdown");
89 void TRACE_activate (void)
91 xbt_assert (trace_active==0, "Tracing is already active.");
93 XBT_DEBUG ("Tracing is on");
96 void TRACE_desactivate (void)
99 XBT_DEBUG ("Tracing is off");
102 int TRACE_is_active (void)
107 int TRACE_is_enabled(void)
109 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
112 int TRACE_is_configured(void)
114 return trace_configured;
117 int TRACE_smpi_is_enabled(void)
119 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI) &&
123 int TRACE_smpi_is_grouped(void)
125 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
128 int TRACE_categorized (void)
130 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
133 int TRACE_uncategorized (void)
135 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
138 int TRACE_msg_task_is_enabled(void)
140 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK) &&
144 int TRACE_msg_process_is_enabled(void)
146 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS) &&
150 int TRACE_msg_volume_is_enabled(void)
152 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME) &&
156 int TRACE_buffer (void)
158 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_BUFFER) &&
162 int TRACE_onelink_only (void)
164 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_ONELINK_ONLY) &&
168 char *TRACE_get_filename(void)
170 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
173 char *TRACE_get_triva_uncat_conf (void)
175 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
178 char *TRACE_get_triva_cat_conf (void)
180 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
183 void TRACE_global_init(int *argc, char **argv)
185 /* name of the tracefile */
186 char *default_tracing_filename = xbt_strdup("simgrid.trace");
187 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
188 "Trace file created by the instrumented SimGrid.",
189 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
193 int default_tracing = 0;
194 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
196 xbt_cfgelm_int, &default_tracing, 0, 1,
200 int default_tracing_smpi = 0;
201 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
202 "Tracing of the SMPI interface.",
203 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
207 int default_tracing_smpi_grouped = 0;
208 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
209 "Group MPI processes by host.",
210 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
215 int default_tracing_platform = 0;
216 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
217 "Tracing of categorized platform (host and link) utilization.",
218 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
221 /* tracing uncategorized resource utilization */
222 int default_tracing_uncategorized = 0;
223 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
224 "Tracing of uncategorized resource (host and link) utilization.",
225 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
229 int default_tracing_msg_task = 0;
230 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
231 "Tracing of MSG task behavior.",
232 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
236 int default_tracing_msg_process = 0;
237 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
238 "Tracing of MSG process behavior.",
239 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
242 /* msg volume (experimental) */
243 int default_tracing_msg_volume = 0;
244 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
245 "Tracing of MSG communication volume (experimental).",
246 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
249 /* msg volume (experimental) */
250 int default_buffer = 0;
251 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_BUFFER,
252 "Buffer trace events to put them in temporal order.",
253 xbt_cfgelm_int, &default_buffer, 0, 1,
256 /* msg volume (experimental) */
257 int default_onelink_only = 0;
258 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_ONELINK_ONLY,
259 "Use only routes with one link to trace platform.",
260 xbt_cfgelm_int, &default_onelink_only, 0, 1,
263 /* Triva graph configuration for uncategorized tracing */
264 char *default_triva_uncat_conf_file = xbt_strdup ("");
265 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
266 "Triva Graph configuration file for uncategorized resource utilization traces.",
267 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
270 /* Triva graph configuration for uncategorized tracing */
271 char *default_triva_cat_conf_file = xbt_strdup ("");
272 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
273 "Triva Graph configuration file for categorized resource utilization traces.",
274 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
277 /* instrumentation can be considered configured now */
278 trace_configured = 1;
281 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
283 char str[INSTR_DEFAULT_STR_SIZE];
284 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
286 int len = strlen (str);
287 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
288 if (!!longdesc && detailed){
289 printf ("%s\n\n", longdesc);
293 void TRACE_help (int detailed)
296 "Description of the tracing options accepted by this simulator:\n\n");
297 print_line (OPT_TRACING, "Enable the tracing system",
298 " It activates the tracing system and register the simulation platform\n"
299 " in the trace file. You have to enable this option to others take effect.",
301 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
302 " It activates the categorized resource utilization tracing. It should\n"
303 " be enabled if tracing categories are used by this simulator.",
305 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
306 " It activates the uncategorized resource utilization tracing. Use it if\n"
307 " this simulator do not use tracing categories and resource use have to be\n"
310 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
311 " A file with this name will be created to register the simulation. The file\n"
312 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
313 " tools. More information can be found in these webpages:\n"
314 " http://triva.gforge.inria.fr/\n"
315 " http://paje.sourceforge.net/",
317 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
318 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
319 " interface and generates a trace that can be analyzed using Gantt-like\n"
320 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
321 " state, and point-to-point communications can be analyzed with arrows.",
323 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
324 " This option only has effect if this simulator is SMPI-based. The processes\n"
325 " are grouped by the hosts where they were executed.",
327 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
328 " This option only has effect if this simulator is MSG-based. It traces the\n"
329 " behavior of all categorized MSG tasks, grouping them by hosts.",
331 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
332 " This option only has effect if this simulator is MSG-based. It traces the\n"
333 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
334 " can be used to track process location if this simulator has process migration.",
336 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
337 " This experimental option only has effect if this simulator is MSG-based.\n"
338 " It traces the communication volume of MSG send/receive.",
340 print_line (OPT_TRACING_BUFFER, "Buffer events to put them in temporal order",
341 " This option put some events in a time-ordered buffer using the insertion\n"
342 " sort algorithm. The process of acquiring and releasing locks to access this\n"
343 " buffer and the cost of the sorting algorithm make this process slow. The\n"
344 " simulator performance can be severely impacted if this option is activated,\n"
345 " but you are sure to get a trace file with events sorted.",
347 print_line (OPT_TRACING_ONELINK_ONLY, "Consider only one link routes to trace platform",
348 " This option changes the way SimGrid register its platform on the trace file.\n"
349 " Normally, the tracing considers all routes (no matter their size) on the\n"
350 " platform file to re-create the resource topology. If this option is activated,\n"
351 " only the routes with one link are used to register the topology within an AS.\n"
352 " Routes among AS continue to be traced as usual.",
354 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
355 " This option can be used in all types of simulators build with SimGrid\n"
356 " to generate a uncategorized resource utilization graph to be used as\n"
357 " configuration for the Triva visualization analysis. This option\n"
358 " can be used with tracing/categorized:1 and tracing:1 options to\n"
359 " analyze an unmodified simulator before changing it to contain\n"
362 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
363 " This option can be used if this simulator uses tracing categories\n"
364 " in its code. The file specified by this option holds a graph configuration\n"
365 " file for the Triva visualization tool that can be used to analyze a categorized\n"
366 " resource utilization.",
370 void TRACE_generate_triva_uncat_conf (void)
372 char *output = TRACE_get_triva_uncat_conf ();
373 if (output && strlen(output) > 0){
374 xbt_dict_cursor_t cursor=NULL;
377 FILE *file = fopen (output, "w");
378 xbt_assert (file != NULL,
379 "Unable to open file (%s) for writing triva graph "
380 "configuration (uncategorized).", output);
383 fprintf (file, "{\n");
385 //register NODE types
386 fprintf (file, " node = (");
387 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
388 fprintf (file, "%s, ", name);
391 //register EDGE types
395 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
396 fprintf (file, "%s, ", name);
402 //configuration for all nodes
407 " values = (power_used);\n"
411 " size = bandwidth;\n"
412 " values = (bandwidth_used);\n"
415 fprintf (file, "}\n");
420 void TRACE_generate_triva_cat_conf (void)
422 char *output = TRACE_get_triva_cat_conf();
423 if (output && strlen(output) > 0){
424 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
425 char *name, *name2, *value, *value2;
427 //check if we do have categories declared
428 if (xbt_dict_length(created_categories) == 0){
429 XBT_INFO("No categories declared, ignoring generation of triva graph configuration");
433 FILE *file = fopen (output, "w");
434 xbt_assert (file != NULL,
435 "Unable to open file (%s) for writing triva graph "
436 "configuration (categorized).", output);
439 fprintf (file, "{\n");
441 //register NODE types
442 fprintf (file, " node = (");
443 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
444 fprintf (file, "%s, ", name);
447 //register EDGE types
451 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
452 fprintf (file, "%s, ", name);
458 //configuration for all nodes
464 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
465 fprintf (file, "p%s, ", name2);
472 " size = bandwidth;\n"
474 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
475 fprintf (file, "b%s, ", name2);
481 fprintf (file, "}\n");
487 #undef OPT_TRACING_SMPI
488 #undef OPT_TRACING_SMPI_GROUP
489 #undef OPT_TRACING_CATEGORIZED
490 #undef OPT_TRACING_UNCATEGORIZED
491 #undef OPT_TRACING_MSG_TASK
492 #undef OPT_TRACING_MSG_PROCESS
493 #undef OPT_TRACING_MSG_VOLUME
494 #undef OPT_TRACING_FILENAME
495 #undef OPT_TRACING_PLATFORM_METHOD
496 #undef OPT_TRIVA_UNCAT_CONF
497 #undef OPT_TRIVA_CAT_CONF
499 #endif /* HAVE_TRACING */