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:
56 // pajeDefineEventType("source", "LINK", "source");
57 // pajeDefineEventType("destination", "LINK", "destination");
59 /* type hierarchy for:
60 * --cfg=tracing/msg/process
61 * --cfg=tracing/msg/volume
64 // if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
65 // //processes grouped by host
66 // pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
69 // if (TRACE_msg_process_is_enabled()) {
70 // pajeDefineStateType("category", "PROCESS", "category");
71 // pajeDefineStateType("presence", "PROCESS", "presence");
74 // if (TRACE_msg_volume_is_enabled()) {
75 // pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
78 /* type hierarchy for:
79 * --cfg=tracing/msg/task
82 // if (TRACE_msg_task_is_enabled()) {
83 // //tasks grouped by host
84 // pajeDefineContainerType("TASK", "HOST", "TASK");
85 // pajeDefineStateType("category", "TASK", "category");
86 // pajeDefineStateType("presence", "TASK", "presence");
91 * --cfg=tracing/smpi/group
94 // if (TRACE_smpi_is_enabled()) {
95 // if (TRACE_smpi_is_grouped()){
96 // pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
98 // pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
100 // pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
101 // pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
105 /* other trace initialization */
106 defined_types = xbt_dict_new();
107 created_categories = xbt_dict_new();
108 TRACE_msg_task_alloc();
110 TRACE_msg_process_alloc();
117 if (!TRACE_is_active())
120 /* close the trace file */
123 /* generate uncategorized graph configuration for triva */
124 if (TRACE_get_triva_uncat_conf()){
125 TRACE_generate_triva_uncat_conf();
128 /* generate categorized graph configuration for triva */
129 if (TRACE_get_triva_cat_conf()){
130 TRACE_generate_triva_cat_conf();
134 TRACE_desactivate ();
135 DEBUG0("Tracing system is shutdown");
139 void TRACE_activate (void)
141 xbt_assert0 (trace_active==0, "Tracing is already active.");
143 DEBUG0 ("Tracing is on");
146 void TRACE_desactivate (void)
149 DEBUG0 ("Tracing is off");
152 int TRACE_is_active (void)
157 int TRACE_is_enabled(void)
159 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
162 int TRACE_is_configured(void)
164 return trace_configured;
167 int TRACE_smpi_is_enabled(void)
169 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
172 int TRACE_smpi_is_grouped(void)
174 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
177 int TRACE_categorized (void)
179 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
182 int TRACE_uncategorized (void)
184 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
187 int TRACE_msg_task_is_enabled(void)
189 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
192 int TRACE_msg_process_is_enabled(void)
194 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
197 int TRACE_msg_volume_is_enabled(void)
199 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
202 char *TRACE_get_filename(void)
204 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
207 char *TRACE_get_platform_method(void)
209 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
212 char *TRACE_get_triva_uncat_conf (void)
214 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
217 char *TRACE_get_triva_cat_conf (void)
219 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
222 void TRACE_global_init(int *argc, char **argv)
224 /* name of the tracefile */
225 char *default_tracing_filename = xbt_strdup("simgrid.trace");
226 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
227 "Trace file created by the instrumented SimGrid.",
228 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
232 int default_tracing = 0;
233 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
235 xbt_cfgelm_int, &default_tracing, 0, 1,
239 int default_tracing_smpi = 0;
240 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
241 "Tracing of the SMPI interface.",
242 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
246 int default_tracing_smpi_grouped = 0;
247 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
248 "Group MPI processes by host.",
249 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
254 int default_tracing_platform = 0;
255 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
256 "Tracing of categorized platform (host and link) utilization.",
257 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
260 /* tracing uncategorized resource utilization */
261 int default_tracing_uncategorized = 0;
262 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
263 "Tracing of uncategorized resource (host and link) utilization.",
264 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
267 /* platform method */
268 char *default_tracing_platform_method = xbt_strdup("a");
269 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
270 "Tracing method used to register categorized resource behavior.",
271 xbt_cfgelm_string, &default_tracing_platform_method, 1,
275 int default_tracing_msg_task = 0;
276 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
277 "Tracing of MSG task behavior.",
278 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
282 int default_tracing_msg_process = 0;
283 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
284 "Tracing of MSG process behavior.",
285 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
288 /* msg volume (experimental) */
289 int default_tracing_msg_volume = 0;
290 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
291 "Tracing of MSG communication volume (experimental).",
292 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
295 /* Triva graph configuration for uncategorized tracing */
296 char *default_triva_uncat_conf_file = xbt_strdup ("");
297 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
298 "Triva Graph configuration file for uncategorized resource utilization traces.",
299 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
302 /* Triva graph configuration for uncategorized tracing */
303 char *default_triva_cat_conf_file = xbt_strdup ("");
304 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
305 "Triva Graph configuration file for categorized resource utilization traces.",
306 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
309 /* instrumentation can be considered configured now */
310 trace_configured = 1;
313 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
315 char str[INSTR_DEFAULT_STR_SIZE];
316 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
318 int len = strlen (str);
319 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
320 if (!!longdesc && detailed){
321 printf ("%s\n\n", longdesc);
325 void TRACE_help (int detailed)
328 "Description of the tracing options accepted by this simulator:\n\n");
329 print_line (OPT_TRACING, "Enable the tracing system",
330 " It activates the tracing system and register the simulation platform\n"
331 " in the trace file. You have to enable this option to others take effect.",
333 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
334 " It activates the categorized resource utilization tracing. It should\n"
335 " be enabled if tracing categories are used by this simulator.",
337 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
338 " It activates the uncategorized resource utilization tracing. Use it if\n"
339 " this simulator do not use tracing categories and resource use have to be\n"
342 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
343 " It changes the way resource utilization (categorized or not) is traced\n"
344 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
345 " by the CPU/network model of a given resource. Depending on the interface used\n"
346 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
347 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
348 " without losing details of resource utilization. Method 'c' generates even\n"
349 " smaller files by doing time integration during the simulation, but it loses\n"
350 " precision. If this last method is used, the smallest timeslice used in the\n"
351 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
352 " unsure, do not change this option.",
354 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
355 " A file with this name will be created to register the simulation. The file\n"
356 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
357 " tools. More information can be found in these webpages:\n"
358 " http://triva.gforge.inria.fr/\n"
359 " http://paje.sourceforge.net/",
361 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
362 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
363 " interface and generates a trace that can be analyzed using Gantt-like\n"
364 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
365 " state, and point-to-point communications can be analyzed with arrows.",
367 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
368 " This option only has effect if this simulator is SMPI-based. The processes\n"
369 " are grouped by the hosts where they were executed.",
371 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
372 " This option only has effect if this simulator is MSG-based. It traces the\n"
373 " behavior of all categorized MSG tasks, grouping them by hosts.",
375 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
376 " This option only has effect if this simulator is MSG-based. It traces the\n"
377 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
378 " can be used to track process location if this simulator has process migration.",
380 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
381 " This experimental option only has effect if this simulator is MSG-based.\n"
382 " It traces the communication volume of MSG send/receive.",
384 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
385 " This option can be used in all types of simulators build with SimGrid\n"
386 " to generate a uncategorized resource utilization graph to be used as\n"
387 " configuration for the Triva visualization analysis. This option\n"
388 " can be used with tracing/categorized:1 and tracing:1 options to\n"
389 " analyze an unmodified simulator before changing it to contain\n"
392 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
393 " This option can be used if this simulator uses tracing categories\n"
394 " in its code. The file specified by this option holds a graph configuration\n"
395 " file for the Triva visualization tool that can be used to analyze a categorized\n"
396 " resource utilization.",
400 void TRACE_generate_triva_uncat_conf (void)
402 char *output = TRACE_get_triva_uncat_conf ();
403 if (output && strlen(output) > 0){
404 FILE *file = fopen (output, "w");
405 xbt_assert1 (file != NULL,
406 "Unable to open file (%s) for writing triva graph "
407 "configuration (uncategorized).", output);
417 " type = separation;\n"
419 " values = (power_used);\n"
424 " dst = destination;\n"
425 " size = bandwidth;\n"
428 " type = separation;\n"
429 " size = bandwidth;\n"
430 " values = (bandwidth_used);\n"
433 " graphviz-algorithm = neato;\n"
440 void TRACE_generate_triva_cat_conf (void)
442 char *output = TRACE_get_triva_cat_conf();
443 if (output && strlen(output) > 0){
444 //check if we do have categories declared
445 if (xbt_dict_length(created_categories) == 0){
446 INFO0("No categories declared, ignoring generation of triva graph configuration");
449 xbt_dict_cursor_t cursor=NULL;
451 FILE *file = fopen (output, "w");
452 xbt_assert1 (file != NULL,
453 "Unable to open file (%s) for writing triva graph "
454 "configuration (categorized).", output);
464 " type = separation;\n"
467 xbt_dict_foreach(created_categories,cursor,key,data) {
468 fprintf(file, "%s, ",key);
476 " dst = destination;\n"
477 " size = bandwidth;\n"
480 " type = separation;\n"
481 " size = bandwidth;\n"
483 xbt_dict_foreach(created_categories,cursor,key,data) {
484 fprintf(file, "%s, ",key);
490 " graphviz-algorithm = neato;\n"
498 #undef OPT_TRACING_SMPI
499 #undef OPT_TRACING_SMPI_GROUP
500 #undef OPT_TRACING_CATEGORIZED
501 #undef OPT_TRACING_UNCATEGORIZED
502 #undef OPT_TRACING_MSG_TASK
503 #undef OPT_TRACING_MSG_PROCESS
504 #undef OPT_TRACING_MSG_VOLUME
505 #undef OPT_TRACING_FILENAME
506 #undef OPT_TRACING_PLATFORM_METHOD
507 #undef OPT_TRIVA_UNCAT_CONF
508 #undef OPT_TRIVA_CAT_CONF
510 #endif /* HAVE_TRACING */