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();
122 TRACE_category_alloc();
124 TRACE_msg_process_alloc();
131 if (!TRACE_is_active())
135 /* close the trace file */
138 /* generate uncategorized graph configuration for triva */
139 if (TRACE_get_triva_uncat_conf()){
140 TRACE_generate_triva_uncat_conf();
143 /* generate categorized graph configuration for triva */
144 if (TRACE_get_triva_cat_conf()){
145 TRACE_generate_triva_cat_conf();
149 TRACE_desactivate ();
150 DEBUG0("Tracing system is shutdown");
154 void TRACE_activate (void)
156 xbt_assert0 (trace_active==0, "Tracing is already active.");
158 DEBUG0 ("Tracing is on");
161 void TRACE_desactivate (void)
164 DEBUG0 ("Tracing is off");
167 int TRACE_is_active (void)
172 int TRACE_is_enabled(void)
174 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
177 int TRACE_is_configured(void)
179 return trace_configured;
182 int TRACE_smpi_is_enabled(void)
184 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
187 int TRACE_smpi_is_grouped(void)
189 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
192 int TRACE_platform_is_enabled(void)
194 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
197 int TRACE_uncategorized (void)
199 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
202 int TRACE_msg_task_is_enabled(void)
204 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
207 int TRACE_msg_process_is_enabled(void)
209 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
212 int TRACE_msg_volume_is_enabled(void)
214 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
217 char *TRACE_get_filename(void)
219 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
222 char *TRACE_get_platform_method(void)
224 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
227 char *TRACE_get_triva_uncat_conf (void)
229 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
232 char *TRACE_get_triva_cat_conf (void)
234 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
237 void TRACE_global_init(int *argc, char **argv)
239 /* name of the tracefile */
240 char *default_tracing_filename = xbt_strdup("simgrid.trace");
241 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
242 "Trace file created by the instrumented SimGrid.",
243 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
247 int default_tracing = 0;
248 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
250 xbt_cfgelm_int, &default_tracing, 0, 1,
254 int default_tracing_smpi = 0;
255 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
256 "Tracing of the SMPI interface.",
257 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
261 int default_tracing_smpi_grouped = 0;
262 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
263 "Group MPI processes by host.",
264 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
269 int default_tracing_platform = 0;
270 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
271 "Tracing of categorized platform (host and link) utilization.",
272 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
275 /* tracing uncategorized resource utilization */
276 int default_tracing_uncategorized = 0;
277 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
278 "Tracing of uncategorized resource (host and link) utilization.",
279 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
282 /* platform method */
283 char *default_tracing_platform_method = xbt_strdup("a");
284 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
285 "Tracing method used to register categorized resource behavior.",
286 xbt_cfgelm_string, &default_tracing_platform_method, 1,
290 int default_tracing_msg_task = 0;
291 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
292 "Tracing of MSG task behavior.",
293 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
297 int default_tracing_msg_process = 0;
298 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
299 "Tracing of MSG process behavior.",
300 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
303 /* msg volume (experimental) */
304 int default_tracing_msg_volume = 0;
305 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
306 "Tracing of MSG communication volume (experimental).",
307 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
310 /* Triva graph configuration for uncategorized tracing */
311 char *default_triva_uncat_conf_file = xbt_strdup ("");
312 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
313 "Triva Graph configuration file for uncategorized resource utilization traces.",
314 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
317 /* Triva graph configuration for uncategorized tracing */
318 char *default_triva_cat_conf_file = xbt_strdup ("");
319 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
320 "Triva Graph configuration file for categorized resource utilization traces.",
321 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
324 /* instrumentation can be considered configured now */
325 trace_configured = 1;
328 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
330 char str[INSTR_DEFAULT_STR_SIZE];
331 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
333 int len = strlen (str);
334 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
335 if (!!longdesc && detailed){
336 printf ("%s\n\n", longdesc);
340 void TRACE_help (int detailed)
343 "Description of the tracing options accepted by this simulator:\n\n");
344 print_line (OPT_TRACING, "Enable the tracing system",
345 " It activates the tracing system and register the simulation platform\n"
346 " in the trace file. You have to enable this option to others take effect.",
348 print_line (OPT_TRACING_PLATFORM, "Trace categorized resource utilization",
349 " It activates the categorized resource utilization tracing. It should\n"
350 " be enabled if tracing categories are used by this simulator.",
352 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
353 " It activates the uncategorized resource utilization tracing. Use it if\n"
354 " this simulator do not use tracing categories and resource use have to be\n"
357 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
358 " It changes the way resource utilization (categorized or not) is traced\n"
359 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
360 " by the CPU/network model of a given resource. Depending on the interface used\n"
361 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
362 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
363 " without losing details of resource utilization. Method 'c' generates even\n"
364 " smaller files by doing time integration during the simulation, but it loses\n"
365 " precision. If this last method is used, the smallest timeslice used in the\n"
366 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
367 " unsure, do not change this option.",
369 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
370 " A file with this name will be created to register the simulation. The file\n"
371 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
372 " tools. More information can be found in these webpages:\n"
373 " http://triva.gforge.inria.fr/\n"
374 " http://paje.sourceforge.net/",
376 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
377 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
378 " interface and generates a trace that can be analyzed using Gantt-like\n"
379 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
380 " state, and point-to-point communications can be analyzed with arrows.",
382 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
383 " This option only has effect if this simulator is SMPI-based. The processes\n"
384 " are grouped by the hosts where they were executed.",
386 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
387 " This option only has effect if this simulator is MSG-based. It traces the\n"
388 " behavior of all categorized MSG tasks, grouping them by hosts.",
390 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
391 " This option only has effect if this simulator is MSG-based. It traces the\n"
392 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
393 " can be used to track process location if this simulator has process migration.",
395 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
396 " This experimental option only has effect if this simulator is MSG-based.\n"
397 " It traces the communication volume of MSG send/receive.",
399 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
400 " This option can be used in all types of simulators build with SimGrid\n"
401 " to generate a uncategorized resource utilization graph to be used as\n"
402 " configuration for the Triva visualization analysis. This option\n"
403 " can be used with tracing/categorized:1 and tracing:1 options to\n"
404 " analyze an unmodified simulator before changing it to contain\n"
407 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
408 " This option can be used if this simulator uses tracing categories\n"
409 " in its code. The file specified by this option holds a graph configuration\n"
410 " file for the Triva visualization tool that can be used to analyze a categorized\n"
411 " resource utilization.",
415 void TRACE_generate_triva_uncat_conf (void)
417 char *output = TRACE_get_triva_uncat_conf ();
418 if (output && strlen(output) > 0){
419 FILE *file = fopen (output, "w");
420 xbt_assert1 (file != NULL,
421 "Unable to open file (%s) for writing triva graph "
422 "configuration (uncategorized).", output);
432 " type = separation;\n"
434 " values = (power_used);\n"
439 " dst = destination;\n"
440 " size = bandwidth;\n"
443 " type = separation;\n"
444 " size = bandwidth;\n"
445 " values = (bandwidth_used);\n"
448 " graphviz-algorithm = neato;\n"
455 void TRACE_generate_triva_cat_conf (void)
457 char *output = TRACE_get_triva_cat_conf();
458 if (output && strlen(output) > 0){
459 //check if we do have categories declared
460 if (xbt_dict_length(created_categories) == 0){
461 INFO0("No categories declared, ignoring generation of triva graph configuration");
464 xbt_dict_cursor_t cursor=NULL;
466 FILE *file = fopen (output, "w");
467 xbt_assert1 (file != NULL,
468 "Unable to open file (%s) for writing triva graph "
469 "configuration (categorized).", output);
479 " type = separation;\n"
482 xbt_dict_foreach(created_categories,cursor,key,data) {
483 fprintf(file, "p%s, ",key);
491 " dst = destination;\n"
492 " size = bandwidth;\n"
495 " type = separation;\n"
496 " size = bandwidth;\n"
498 xbt_dict_foreach(created_categories,cursor,key,data) {
499 fprintf(file, "b%s, ",key);
505 " graphviz-algorithm = neato;\n"
513 #undef OPT_TRACING_SMPI
514 #undef OPT_TRACING_SMPI_GROUP
515 #undef OPT_TRACING_PLATFORM
516 #undef OPT_TRACING_UNCATEGORIZED
517 #undef OPT_TRACING_MSG_TASK
518 #undef OPT_TRACING_MSG_PROCESS
519 #undef OPT_TRACING_MSG_VOLUME
520 #undef OPT_TRACING_FILENAME
521 #undef OPT_TRACING_PLATFORM_METHOD
522 #undef OPT_TRIVA_UNCAT_CONF
523 #undef OPT_TRIVA_CAT_CONF
525 #endif /* HAVE_TRACING */