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_PLATFORM_METHOD "tracing/platform/method"
25 #define OPT_TRIVA_UNCAT_CONF "triva/uncategorized"
26 #define OPT_TRIVA_CAT_CONF "triva/categorized"
28 static int trace_configured = 0;
29 static int trace_active = 0;
31 extern xbt_dict_t created_categories; //declared in instr_interface.c
32 extern xbt_dict_t defined_types; //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 DEBUG0("Tracing starts");
45 /* open the trace file */
51 /* base type hierarchy:
54 pajeDefineContainerType("PLATFORM", "0", "platform");
55 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
56 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
57 pajeDefineVariableType("power", "HOST", "power");
58 pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
59 pajeDefineVariableType("latency", "LINK", "latency");
60 pajeDefineEventType("source", "LINK", "source");
61 pajeDefineEventType("destination", "LINK", "destination");
63 /* type hierarchy for:
64 * --cfg=tracing/uncategorized
66 if (TRACE_uncategorized()){
67 pajeDefineVariableTypeWithColor("power_used", "HOST", "power_used", "0.5 0.5 0.5");
68 pajeDefineVariableTypeWithColor("bandwidth_used", "LINK", "bandwidth_used", "0.5 0.5 0.5");
71 /* type hierarchy for:
72 * --cfg=tracing/msg/process
73 * --cfg=tracing/msg/volume
75 if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
76 //processes grouped by host
77 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
80 if (TRACE_msg_process_is_enabled()) {
81 pajeDefineStateType("category", "PROCESS", "category");
82 pajeDefineStateType("presence", "PROCESS", "presence");
85 if (TRACE_msg_volume_is_enabled()) {
86 pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
89 /* type hierarchy for:
90 * --cfg=tracing/msg/task
92 if (TRACE_msg_task_is_enabled()) {
93 //tasks grouped by host
94 pajeDefineContainerType("TASK", "HOST", "TASK");
95 pajeDefineStateType("category", "TASK", "category");
96 pajeDefineStateType("presence", "TASK", "presence");
101 * --cfg=tracing/smpi/group
103 if (TRACE_smpi_is_enabled()) {
104 if (TRACE_smpi_is_grouped()){
105 pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
107 pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
109 pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
110 pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
114 /* creating the platform */
115 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0",
118 /* other trace initialization */
119 defined_types = xbt_dict_new();
120 created_categories = xbt_dict_new();
121 TRACE_msg_task_alloc();
123 TRACE_msg_process_alloc();
130 if (!TRACE_is_active())
133 /* close the trace file */
136 /* generate uncategorized graph configuration for triva */
137 if (TRACE_get_triva_uncat_conf()){
138 TRACE_generate_triva_uncat_conf();
141 /* generate categorized graph configuration for triva */
142 if (TRACE_get_triva_cat_conf()){
143 TRACE_generate_triva_cat_conf();
147 TRACE_desactivate ();
148 DEBUG0("Tracing system is shutdown");
152 void TRACE_activate (void)
154 xbt_assert0 (trace_active==0, "Tracing is already active.");
156 DEBUG0 ("Tracing is on");
159 void TRACE_desactivate (void)
162 DEBUG0 ("Tracing is off");
165 int TRACE_is_active (void)
170 int TRACE_is_enabled(void)
172 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
175 int TRACE_is_configured(void)
177 return trace_configured;
180 int TRACE_smpi_is_enabled(void)
182 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
185 int TRACE_smpi_is_grouped(void)
187 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
190 int TRACE_categorized (void)
192 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
195 int TRACE_uncategorized (void)
197 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
200 int TRACE_msg_task_is_enabled(void)
202 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
205 int TRACE_msg_process_is_enabled(void)
207 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
210 int TRACE_msg_volume_is_enabled(void)
212 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
215 char *TRACE_get_filename(void)
217 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
220 char *TRACE_get_platform_method(void)
222 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
225 char *TRACE_get_triva_uncat_conf (void)
227 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
230 char *TRACE_get_triva_cat_conf (void)
232 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
235 void TRACE_global_init(int *argc, char **argv)
237 /* name of the tracefile */
238 char *default_tracing_filename = xbt_strdup("simgrid.trace");
239 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
240 "Trace file created by the instrumented SimGrid.",
241 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
245 int default_tracing = 0;
246 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
248 xbt_cfgelm_int, &default_tracing, 0, 1,
252 int default_tracing_smpi = 0;
253 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
254 "Tracing of the SMPI interface.",
255 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
259 int default_tracing_smpi_grouped = 0;
260 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
261 "Group MPI processes by host.",
262 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
267 int default_tracing_platform = 0;
268 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
269 "Tracing of categorized platform (host and link) utilization.",
270 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
273 /* tracing uncategorized resource utilization */
274 int default_tracing_uncategorized = 0;
275 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
276 "Tracing of uncategorized resource (host and link) utilization.",
277 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
280 /* platform method */
281 char *default_tracing_platform_method = xbt_strdup("a");
282 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
283 "Tracing method used to register categorized resource behavior.",
284 xbt_cfgelm_string, &default_tracing_platform_method, 1,
288 int default_tracing_msg_task = 0;
289 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
290 "Tracing of MSG task behavior.",
291 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
295 int default_tracing_msg_process = 0;
296 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
297 "Tracing of MSG process behavior.",
298 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
301 /* msg volume (experimental) */
302 int default_tracing_msg_volume = 0;
303 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
304 "Tracing of MSG communication volume (experimental).",
305 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
308 /* Triva graph configuration for uncategorized tracing */
309 char *default_triva_uncat_conf_file = xbt_strdup ("");
310 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
311 "Triva Graph configuration file for uncategorized resource utilization traces.",
312 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
315 /* Triva graph configuration for uncategorized tracing */
316 char *default_triva_cat_conf_file = xbt_strdup ("");
317 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
318 "Triva Graph configuration file for categorized resource utilization traces.",
319 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
322 /* instrumentation can be considered configured now */
323 trace_configured = 1;
326 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
328 char str[INSTR_DEFAULT_STR_SIZE];
329 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
331 int len = strlen (str);
332 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
333 if (!!longdesc && detailed){
334 printf ("%s\n\n", longdesc);
338 void TRACE_help (int detailed)
341 "Description of the tracing options accepted by this simulator:\n\n");
342 print_line (OPT_TRACING, "Enable the tracing system",
343 " It activates the tracing system and register the simulation platform\n"
344 " in the trace file. You have to enable this option to others take effect.",
346 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
347 " It activates the categorized resource utilization tracing. It should\n"
348 " be enabled if tracing categories are used by this simulator.",
350 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
351 " It activates the uncategorized resource utilization tracing. Use it if\n"
352 " this simulator do not use tracing categories and resource use have to be\n"
355 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
356 " It changes the way resource utilization (categorized or not) is traced\n"
357 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
358 " by the CPU/network model of a given resource. Depending on the interface used\n"
359 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
360 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
361 " without losing details of resource utilization. Method 'c' generates even\n"
362 " smaller files by doing time integration during the simulation, but it loses\n"
363 " precision. If this last method is used, the smallest timeslice used in the\n"
364 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
365 " unsure, do not change this option.",
367 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
368 " A file with this name will be created to register the simulation. The file\n"
369 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
370 " tools. More information can be found in these webpages:\n"
371 " http://triva.gforge.inria.fr/\n"
372 " http://paje.sourceforge.net/",
374 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
375 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
376 " interface and generates a trace that can be analyzed using Gantt-like\n"
377 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
378 " state, and point-to-point communications can be analyzed with arrows.",
380 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
381 " This option only has effect if this simulator is SMPI-based. The processes\n"
382 " are grouped by the hosts where they were executed.",
384 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
385 " This option only has effect if this simulator is MSG-based. It traces the\n"
386 " behavior of all categorized MSG tasks, grouping them by hosts.",
388 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
389 " This option only has effect if this simulator is MSG-based. It traces the\n"
390 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
391 " can be used to track process location if this simulator has process migration.",
393 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
394 " This experimental option only has effect if this simulator is MSG-based.\n"
395 " It traces the communication volume of MSG send/receive.",
397 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
398 " This option can be used in all types of simulators build with SimGrid\n"
399 " to generate a uncategorized resource utilization graph to be used as\n"
400 " configuration for the Triva visualization analysis. This option\n"
401 " can be used with tracing/categorized:1 and tracing:1 options to\n"
402 " analyze an unmodified simulator before changing it to contain\n"
405 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
406 " This option can be used if this simulator uses tracing categories\n"
407 " in its code. The file specified by this option holds a graph configuration\n"
408 " file for the Triva visualization tool that can be used to analyze a categorized\n"
409 " resource utilization.",
413 void TRACE_generate_triva_uncat_conf (void)
415 char *output = TRACE_get_triva_uncat_conf ();
416 if (output && strlen(output) > 0){
417 FILE *file = fopen (output, "w");
418 xbt_assert1 (file != NULL,
419 "Unable to open file (%s) for writing triva graph "
420 "configuration (uncategorized).", output);
430 " type = separation;\n"
432 " values = (power_used);\n"
437 " dst = destination;\n"
438 " size = bandwidth;\n"
441 " type = separation;\n"
442 " size = bandwidth;\n"
443 " values = (bandwidth_used);\n"
446 " graphviz-algorithm = neato;\n"
453 void TRACE_generate_triva_cat_conf (void)
455 char *output = TRACE_get_triva_cat_conf();
456 if (output && strlen(output) > 0){
457 //check if we do have categories declared
458 if (xbt_dict_length(created_categories) == 0){
459 INFO0("No categories declared, ignoring generation of triva graph configuration");
462 xbt_dict_cursor_t cursor=NULL;
464 FILE *file = fopen (output, "w");
465 xbt_assert1 (file != NULL,
466 "Unable to open file (%s) for writing triva graph "
467 "configuration (categorized).", output);
477 " type = separation;\n"
480 xbt_dict_foreach(created_categories,cursor,key,data) {
481 fprintf(file, "p%s, ",key);
489 " dst = destination;\n"
490 " size = bandwidth;\n"
493 " type = separation;\n"
494 " size = bandwidth;\n"
496 xbt_dict_foreach(created_categories,cursor,key,data) {
497 fprintf(file, "b%s, ",key);
503 " graphviz-algorithm = neato;\n"
511 #undef OPT_TRACING_SMPI
512 #undef OPT_TRACING_SMPI_GROUP
513 #undef OPT_TRACING_CATEGORIZED
514 #undef OPT_TRACING_UNCATEGORIZED
515 #undef OPT_TRACING_MSG_TASK
516 #undef OPT_TRACING_MSG_PROCESS
517 #undef OPT_TRACING_MSG_VOLUME
518 #undef OPT_TRACING_FILENAME
519 #undef OPT_TRACING_PLATFORM_METHOD
520 #undef OPT_TRIVA_UNCAT_CONF
521 #undef OPT_TRIVA_CAT_CONF
523 #endif /* HAVE_TRACING */