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 xbt_dict_t created_categories; //declared in instr_interface.c
35 // tracing system must be:
36 // - enabled (with --cfg=tracing:1)
37 // - already configured (TRACE_global_init already called)
38 if (!(TRACE_is_enabled() && TRACE_is_configured())){
42 DEBUG0("Tracing starts");
44 /* open the trace file */
50 /* base type hierarchy:
55 // pajeDefineEventType("source", "LINK", "source");
56 // pajeDefineEventType("destination", "LINK", "destination");
58 /* type hierarchy for:
59 * --cfg=tracing/msg/process
60 * --cfg=tracing/msg/volume
63 // if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
64 // //processes grouped by host
65 // pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
68 // if (TRACE_msg_process_is_enabled()) {
69 // pajeDefineStateType("category", "PROCESS", "category");
70 // pajeDefineStateType("presence", "PROCESS", "presence");
73 // if (TRACE_msg_volume_is_enabled()) {
74 // pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
77 /* type hierarchy for:
78 * --cfg=tracing/msg/task
81 // if (TRACE_msg_task_is_enabled()) {
82 // //tasks grouped by host
83 // pajeDefineContainerType("TASK", "HOST", "TASK");
84 // pajeDefineStateType("category", "TASK", "category");
85 // pajeDefineStateType("presence", "TASK", "presence");
90 * --cfg=tracing/smpi/group
93 // if (TRACE_smpi_is_enabled()) {
94 // if (TRACE_smpi_is_grouped()){
95 // pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
97 // pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
99 // pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
100 // pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
104 /* other trace initialization */
105 created_categories = xbt_dict_new();
106 TRACE_msg_task_alloc();
108 TRACE_msg_process_alloc();
115 if (!TRACE_is_active())
118 /* close the trace file */
121 /* generate uncategorized graph configuration for triva */
122 if (TRACE_get_triva_uncat_conf()){
123 TRACE_generate_triva_uncat_conf();
126 /* generate categorized graph configuration for triva */
127 if (TRACE_get_triva_cat_conf()){
128 TRACE_generate_triva_cat_conf();
132 TRACE_desactivate ();
133 DEBUG0("Tracing system is shutdown");
137 void TRACE_activate (void)
139 xbt_assert0 (trace_active==0, "Tracing is already active.");
141 DEBUG0 ("Tracing is on");
144 void TRACE_desactivate (void)
147 DEBUG0 ("Tracing is off");
150 int TRACE_is_active (void)
155 int TRACE_is_enabled(void)
157 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
160 int TRACE_is_configured(void)
162 return trace_configured;
165 int TRACE_smpi_is_enabled(void)
167 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
170 int TRACE_smpi_is_grouped(void)
172 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
175 int TRACE_categorized (void)
177 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
180 int TRACE_uncategorized (void)
182 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
185 int TRACE_msg_task_is_enabled(void)
187 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
190 int TRACE_msg_process_is_enabled(void)
192 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
195 int TRACE_msg_volume_is_enabled(void)
197 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
200 char *TRACE_get_filename(void)
202 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
205 char *TRACE_get_platform_method(void)
207 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
210 char *TRACE_get_triva_uncat_conf (void)
212 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
215 char *TRACE_get_triva_cat_conf (void)
217 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
220 void TRACE_global_init(int *argc, char **argv)
222 /* name of the tracefile */
223 char *default_tracing_filename = xbt_strdup("simgrid.trace");
224 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
225 "Trace file created by the instrumented SimGrid.",
226 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
230 int default_tracing = 0;
231 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
233 xbt_cfgelm_int, &default_tracing, 0, 1,
237 int default_tracing_smpi = 0;
238 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
239 "Tracing of the SMPI interface.",
240 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
244 int default_tracing_smpi_grouped = 0;
245 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
246 "Group MPI processes by host.",
247 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
252 int default_tracing_platform = 0;
253 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
254 "Tracing of categorized platform (host and link) utilization.",
255 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
258 /* tracing uncategorized resource utilization */
259 int default_tracing_uncategorized = 0;
260 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
261 "Tracing of uncategorized resource (host and link) utilization.",
262 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
265 /* platform method */
266 char *default_tracing_platform_method = xbt_strdup("a");
267 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
268 "Tracing method used to register categorized resource behavior.",
269 xbt_cfgelm_string, &default_tracing_platform_method, 1,
273 int default_tracing_msg_task = 0;
274 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
275 "Tracing of MSG task behavior.",
276 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
280 int default_tracing_msg_process = 0;
281 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
282 "Tracing of MSG process behavior.",
283 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
286 /* msg volume (experimental) */
287 int default_tracing_msg_volume = 0;
288 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
289 "Tracing of MSG communication volume (experimental).",
290 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
293 /* Triva graph configuration for uncategorized tracing */
294 char *default_triva_uncat_conf_file = xbt_strdup ("");
295 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
296 "Triva Graph configuration file for uncategorized resource utilization traces.",
297 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
300 /* Triva graph configuration for uncategorized tracing */
301 char *default_triva_cat_conf_file = xbt_strdup ("");
302 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
303 "Triva Graph configuration file for categorized resource utilization traces.",
304 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
307 /* instrumentation can be considered configured now */
308 trace_configured = 1;
311 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
313 char str[INSTR_DEFAULT_STR_SIZE];
314 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
316 int len = strlen (str);
317 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
318 if (!!longdesc && detailed){
319 printf ("%s\n\n", longdesc);
323 void TRACE_help (int detailed)
326 "Description of the tracing options accepted by this simulator:\n\n");
327 print_line (OPT_TRACING, "Enable the tracing system",
328 " It activates the tracing system and register the simulation platform\n"
329 " in the trace file. You have to enable this option to others take effect.",
331 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
332 " It activates the categorized resource utilization tracing. It should\n"
333 " be enabled if tracing categories are used by this simulator.",
335 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
336 " It activates the uncategorized resource utilization tracing. Use it if\n"
337 " this simulator do not use tracing categories and resource use have to be\n"
340 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
341 " It changes the way resource utilization (categorized or not) is traced\n"
342 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
343 " by the CPU/network model of a given resource. Depending on the interface used\n"
344 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
345 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
346 " without losing details of resource utilization. Method 'c' generates even\n"
347 " smaller files by doing time integration during the simulation, but it loses\n"
348 " precision. If this last method is used, the smallest timeslice used in the\n"
349 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
350 " unsure, do not change this option.",
352 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
353 " A file with this name will be created to register the simulation. The file\n"
354 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
355 " tools. More information can be found in these webpages:\n"
356 " http://triva.gforge.inria.fr/\n"
357 " http://paje.sourceforge.net/",
359 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
360 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
361 " interface and generates a trace that can be analyzed using Gantt-like\n"
362 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
363 " state, and point-to-point communications can be analyzed with arrows.",
365 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
366 " This option only has effect if this simulator is SMPI-based. The processes\n"
367 " are grouped by the hosts where they were executed.",
369 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
370 " This option only has effect if this simulator is MSG-based. It traces the\n"
371 " behavior of all categorized MSG tasks, grouping them by hosts.",
373 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
374 " This option only has effect if this simulator is MSG-based. It traces the\n"
375 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
376 " can be used to track process location if this simulator has process migration.",
378 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
379 " This experimental option only has effect if this simulator is MSG-based.\n"
380 " It traces the communication volume of MSG send/receive.",
382 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
383 " This option can be used in all types of simulators build with SimGrid\n"
384 " to generate a uncategorized resource utilization graph to be used as\n"
385 " configuration for the Triva visualization analysis. This option\n"
386 " can be used with tracing/categorized:1 and tracing:1 options to\n"
387 " analyze an unmodified simulator before changing it to contain\n"
390 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
391 " This option can be used if this simulator uses tracing categories\n"
392 " in its code. The file specified by this option holds a graph configuration\n"
393 " file for the Triva visualization tool that can be used to analyze a categorized\n"
394 " resource utilization.",
398 void TRACE_generate_triva_uncat_conf (void)
400 char *output = TRACE_get_triva_uncat_conf ();
401 if (output && strlen(output) > 0){
402 FILE *file = fopen (output, "w");
403 xbt_assert1 (file != NULL,
404 "Unable to open file (%s) for writing triva graph "
405 "configuration (uncategorized).", output);
415 " type = separation;\n"
417 " values = (power_used);\n"
422 " dst = destination;\n"
423 " size = bandwidth;\n"
426 " type = separation;\n"
427 " size = bandwidth;\n"
428 " values = (bandwidth_used);\n"
431 " graphviz-algorithm = neato;\n"
438 void TRACE_generate_triva_cat_conf (void)
440 char *output = TRACE_get_triva_cat_conf();
441 if (output && strlen(output) > 0){
442 //check if we do have categories declared
443 if (xbt_dict_length(created_categories) == 0){
444 INFO0("No categories declared, ignoring generation of triva graph configuration");
447 xbt_dict_cursor_t cursor=NULL;
449 FILE *file = fopen (output, "w");
450 xbt_assert1 (file != NULL,
451 "Unable to open file (%s) for writing triva graph "
452 "configuration (categorized).", output);
462 " type = separation;\n"
465 xbt_dict_foreach(created_categories,cursor,key,data) {
466 fprintf(file, "%s, ",key);
474 " dst = destination;\n"
475 " size = bandwidth;\n"
478 " type = separation;\n"
479 " size = bandwidth;\n"
481 xbt_dict_foreach(created_categories,cursor,key,data) {
482 fprintf(file, "%s, ",key);
488 " graphviz-algorithm = neato;\n"
496 #undef OPT_TRACING_SMPI
497 #undef OPT_TRACING_SMPI_GROUP
498 #undef OPT_TRACING_CATEGORIZED
499 #undef OPT_TRACING_UNCATEGORIZED
500 #undef OPT_TRACING_MSG_TASK
501 #undef OPT_TRACING_MSG_PROCESS
502 #undef OPT_TRACING_MSG_VOLUME
503 #undef OPT_TRACING_FILENAME
504 #undef OPT_TRACING_PLATFORM_METHOD
505 #undef OPT_TRIVA_UNCAT_CONF
506 #undef OPT_TRIVA_CAT_CONF
508 #endif /* HAVE_TRACING */