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_PLATFORM "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())
134 /* close the trace file */
137 /* generate uncategorized graph configuration for triva */
138 if (TRACE_get_triva_uncat_conf()){
139 TRACE_generate_triva_uncat_conf();
142 /* generate categorized graph configuration for triva */
143 if (TRACE_get_triva_cat_conf()){
144 TRACE_generate_triva_cat_conf();
148 TRACE_desactivate ();
149 DEBUG0("Tracing system is shutdown");
153 void TRACE_activate (void)
155 xbt_assert0 (trace_active==0, "Tracing is already active.");
157 DEBUG0 ("Tracing is on");
160 void TRACE_desactivate (void)
163 DEBUG0 ("Tracing is off");
166 int TRACE_is_active (void)
171 int TRACE_is_enabled(void)
173 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
176 int TRACE_is_configured(void)
178 return trace_configured;
181 int TRACE_smpi_is_enabled(void)
183 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
186 int TRACE_smpi_is_grouped(void)
188 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
191 int TRACE_platform_is_enabled(void)
193 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
196 int TRACE_uncategorized (void)
198 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
201 int TRACE_msg_task_is_enabled(void)
203 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
206 int TRACE_msg_process_is_enabled(void)
208 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
211 int TRACE_msg_volume_is_enabled(void)
213 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
216 char *TRACE_get_filename(void)
218 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
221 char *TRACE_get_platform_method(void)
223 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
226 char *TRACE_get_triva_uncat_conf (void)
228 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
231 char *TRACE_get_triva_cat_conf (void)
233 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
236 void TRACE_global_init(int *argc, char **argv)
238 /* name of the tracefile */
239 char *default_tracing_filename = xbt_strdup("simgrid.trace");
240 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
241 "Trace file created by the instrumented SimGrid.",
242 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
246 int default_tracing = 0;
247 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
249 xbt_cfgelm_int, &default_tracing, 0, 1,
253 int default_tracing_smpi = 0;
254 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
255 "Tracing of the SMPI interface.",
256 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
260 int default_tracing_smpi_grouped = 0;
261 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
262 "Group MPI processes by host.",
263 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
268 int default_tracing_platform = 0;
269 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
270 "Tracing of categorized platform (host and link) utilization.",
271 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
274 /* tracing uncategorized resource utilization */
275 int default_tracing_uncategorized = 0;
276 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
277 "Tracing of uncategorized resource (host and link) utilization.",
278 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
281 /* platform method */
282 char *default_tracing_platform_method = xbt_strdup("a");
283 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
284 "Tracing method used to register categorized resource behavior.",
285 xbt_cfgelm_string, &default_tracing_platform_method, 1,
289 int default_tracing_msg_task = 0;
290 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
291 "Tracing of MSG task behavior.",
292 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
296 int default_tracing_msg_process = 0;
297 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
298 "Tracing of MSG process behavior.",
299 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
302 /* msg volume (experimental) */
303 int default_tracing_msg_volume = 0;
304 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
305 "Tracing of MSG communication volume (experimental).",
306 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
309 /* Triva graph configuration for uncategorized tracing */
310 char *default_triva_uncat_conf_file = xbt_strdup ("");
311 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
312 "Triva Graph configuration file for uncategorized resource utilization traces.",
313 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
316 /* Triva graph configuration for uncategorized tracing */
317 char *default_triva_cat_conf_file = xbt_strdup ("");
318 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
319 "Triva Graph configuration file for categorized resource utilization traces.",
320 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
323 /* instrumentation can be considered configured now */
324 trace_configured = 1;
327 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
329 char str[INSTR_DEFAULT_STR_SIZE];
330 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
332 int len = strlen (str);
333 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
334 if (!!longdesc && detailed){
335 printf ("%s\n\n", longdesc);
339 void TRACE_help (int detailed)
342 "Description of the tracing options accepted by this simulator:\n\n");
343 print_line (OPT_TRACING, "Enable the tracing system",
344 " It activates the tracing system and register the simulation platform\n"
345 " in the trace file. You have to enable this option to others take effect.",
347 print_line (OPT_TRACING_PLATFORM, "Trace categorized resource utilization",
348 " It activates the categorized resource utilization tracing. It should\n"
349 " be enabled if tracing categories are used by this simulator.",
351 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
352 " It activates the uncategorized resource utilization tracing. Use it if\n"
353 " this simulator do not use tracing categories and resource use have to be\n"
356 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
357 " It changes the way resource utilization (categorized or not) is traced\n"
358 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
359 " by the CPU/network model of a given resource. Depending on the interface used\n"
360 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
361 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
362 " without losing details of resource utilization. Method 'c' generates even\n"
363 " smaller files by doing time integration during the simulation, but it loses\n"
364 " precision. If this last method is used, the smallest timeslice used in the\n"
365 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
366 " unsure, do not change this option.",
368 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
369 " A file with this name will be created to register the simulation. The file\n"
370 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
371 " tools. More information can be found in these webpages:\n"
372 " http://triva.gforge.inria.fr/\n"
373 " http://paje.sourceforge.net/",
375 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
376 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
377 " interface and generates a trace that can be analyzed using Gantt-like\n"
378 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
379 " state, and point-to-point communications can be analyzed with arrows.",
381 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
382 " This option only has effect if this simulator is SMPI-based. The processes\n"
383 " are grouped by the hosts where they were executed.",
385 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
386 " This option only has effect if this simulator is MSG-based. It traces the\n"
387 " behavior of all categorized MSG tasks, grouping them by hosts.",
389 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
390 " This option only has effect if this simulator is MSG-based. It traces the\n"
391 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
392 " can be used to track process location if this simulator has process migration.",
394 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
395 " This experimental option only has effect if this simulator is MSG-based.\n"
396 " It traces the communication volume of MSG send/receive.",
398 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
399 " This option can be used in all types of simulators build with SimGrid\n"
400 " to generate a uncategorized resource utilization graph to be used as\n"
401 " configuration for the Triva visualization analysis. This option\n"
402 " can be used with tracing/categorized:1 and tracing:1 options to\n"
403 " analyze an unmodified simulator before changing it to contain\n"
406 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
407 " This option can be used if this simulator uses tracing categories\n"
408 " in its code. The file specified by this option holds a graph configuration\n"
409 " file for the Triva visualization tool that can be used to analyze a categorized\n"
410 " resource utilization.",
414 void TRACE_generate_triva_uncat_conf (void)
416 char *output = TRACE_get_triva_uncat_conf ();
417 if (output && strlen(output) > 0){
418 FILE *file = fopen (output, "w");
419 xbt_assert1 (file != NULL,
420 "Unable to open file (%s) for writing triva graph "
421 "configuration (uncategorized).", output);
431 " type = separation;\n"
433 " values = (power_used);\n"
438 " dst = destination;\n"
439 " size = bandwidth;\n"
442 " type = separation;\n"
443 " size = bandwidth;\n"
444 " values = (bandwidth_used);\n"
447 " graphviz-algorithm = neato;\n"
454 void TRACE_generate_triva_cat_conf (void)
456 char *output = TRACE_get_triva_cat_conf();
457 if (output && strlen(output) > 0){
458 //check if we do have categories declared
459 if (xbt_dict_length(created_categories) == 0){
460 INFO0("No categories declared, ignoring generation of triva graph configuration");
463 xbt_dict_cursor_t cursor=NULL;
465 FILE *file = fopen (output, "w");
466 xbt_assert1 (file != NULL,
467 "Unable to open file (%s) for writing triva graph "
468 "configuration (categorized).", output);
478 " type = separation;\n"
481 xbt_dict_foreach(created_categories,cursor,key,data) {
482 fprintf(file, "p%s, ",key);
490 " dst = destination;\n"
491 " size = bandwidth;\n"
494 " type = separation;\n"
495 " size = bandwidth;\n"
497 xbt_dict_foreach(created_categories,cursor,key,data) {
498 fprintf(file, "b%s, ",key);
504 " graphviz-algorithm = neato;\n"
512 #undef OPT_TRACING_SMPI
513 #undef OPT_TRACING_SMPI_GROUP
514 #undef OPT_TRACING_PLATFORM
515 #undef OPT_TRACING_UNCATEGORIZED
516 #undef OPT_TRACING_MSG_TASK
517 #undef OPT_TRACING_MSG_PROCESS
518 #undef OPT_TRACING_MSG_VOLUME
519 #undef OPT_TRACING_FILENAME
520 #undef OPT_TRACING_PLATFORM_METHOD
521 #undef OPT_TRIVA_UNCAT_CONF
522 #undef OPT_TRIVA_CAT_CONF
524 #endif /* HAVE_TRACING */