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");
88 /* other trace initialization */
89 created_categories = xbt_dict_new();
90 TRACE_msg_task_alloc();
98 if (!TRACE_is_active())
101 /* close the trace file */
104 /* generate uncategorized graph configuration for triva */
105 if (TRACE_get_triva_uncat_conf()){
106 TRACE_generate_triva_uncat_conf();
109 /* generate categorized graph configuration for triva */
110 if (TRACE_get_triva_cat_conf()){
111 TRACE_generate_triva_cat_conf();
115 TRACE_desactivate ();
116 DEBUG0("Tracing system is shutdown");
120 void TRACE_activate (void)
122 xbt_assert0 (trace_active==0, "Tracing is already active.");
124 DEBUG0 ("Tracing is on");
127 void TRACE_desactivate (void)
130 DEBUG0 ("Tracing is off");
133 int TRACE_is_active (void)
138 int TRACE_is_enabled(void)
140 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
143 int TRACE_is_configured(void)
145 return trace_configured;
148 int TRACE_smpi_is_enabled(void)
150 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
153 int TRACE_smpi_is_grouped(void)
155 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
158 int TRACE_categorized (void)
160 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
163 int TRACE_uncategorized (void)
165 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
168 int TRACE_msg_task_is_enabled(void)
170 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
173 int TRACE_msg_process_is_enabled(void)
175 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
178 int TRACE_msg_volume_is_enabled(void)
180 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
183 char *TRACE_get_filename(void)
185 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
188 char *TRACE_get_platform_method(void)
190 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
193 char *TRACE_get_triva_uncat_conf (void)
195 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
198 char *TRACE_get_triva_cat_conf (void)
200 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
203 void TRACE_global_init(int *argc, char **argv)
205 /* name of the tracefile */
206 char *default_tracing_filename = xbt_strdup("simgrid.trace");
207 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
208 "Trace file created by the instrumented SimGrid.",
209 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
213 int default_tracing = 0;
214 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
216 xbt_cfgelm_int, &default_tracing, 0, 1,
220 int default_tracing_smpi = 0;
221 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
222 "Tracing of the SMPI interface.",
223 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
227 int default_tracing_smpi_grouped = 0;
228 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
229 "Group MPI processes by host.",
230 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
235 int default_tracing_platform = 0;
236 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
237 "Tracing of categorized platform (host and link) utilization.",
238 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
241 /* tracing uncategorized resource utilization */
242 int default_tracing_uncategorized = 0;
243 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
244 "Tracing of uncategorized resource (host and link) utilization.",
245 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
248 /* platform method */
249 char *default_tracing_platform_method = xbt_strdup("a");
250 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
251 "Tracing method used to register categorized resource behavior.",
252 xbt_cfgelm_string, &default_tracing_platform_method, 1,
256 int default_tracing_msg_task = 0;
257 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
258 "Tracing of MSG task behavior.",
259 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
263 int default_tracing_msg_process = 0;
264 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
265 "Tracing of MSG process behavior.",
266 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
269 /* msg volume (experimental) */
270 int default_tracing_msg_volume = 0;
271 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
272 "Tracing of MSG communication volume (experimental).",
273 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
276 /* Triva graph configuration for uncategorized tracing */
277 char *default_triva_uncat_conf_file = xbt_strdup ("");
278 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
279 "Triva Graph configuration file for uncategorized resource utilization traces.",
280 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
283 /* Triva graph configuration for uncategorized tracing */
284 char *default_triva_cat_conf_file = xbt_strdup ("");
285 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
286 "Triva Graph configuration file for categorized resource utilization traces.",
287 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
290 /* instrumentation can be considered configured now */
291 trace_configured = 1;
294 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
296 char str[INSTR_DEFAULT_STR_SIZE];
297 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
299 int len = strlen (str);
300 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
301 if (!!longdesc && detailed){
302 printf ("%s\n\n", longdesc);
306 void TRACE_help (int detailed)
309 "Description of the tracing options accepted by this simulator:\n\n");
310 print_line (OPT_TRACING, "Enable the tracing system",
311 " It activates the tracing system and register the simulation platform\n"
312 " in the trace file. You have to enable this option to others take effect.",
314 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
315 " It activates the categorized resource utilization tracing. It should\n"
316 " be enabled if tracing categories are used by this simulator.",
318 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
319 " It activates the uncategorized resource utilization tracing. Use it if\n"
320 " this simulator do not use tracing categories and resource use have to be\n"
323 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
324 " It changes the way resource utilization (categorized or not) is traced\n"
325 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
326 " by the CPU/network model of a given resource. Depending on the interface used\n"
327 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
328 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
329 " without losing details of resource utilization. Method 'c' generates even\n"
330 " smaller files by doing time integration during the simulation, but it loses\n"
331 " precision. If this last method is used, the smallest timeslice used in the\n"
332 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
333 " unsure, do not change this option.",
335 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
336 " A file with this name will be created to register the simulation. The file\n"
337 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
338 " tools. More information can be found in these webpages:\n"
339 " http://triva.gforge.inria.fr/\n"
340 " http://paje.sourceforge.net/",
342 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
343 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
344 " interface and generates a trace that can be analyzed using Gantt-like\n"
345 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
346 " state, and point-to-point communications can be analyzed with arrows.",
348 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
349 " This option only has effect if this simulator is SMPI-based. The processes\n"
350 " are grouped by the hosts where they were executed.",
352 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
353 " This option only has effect if this simulator is MSG-based. It traces the\n"
354 " behavior of all categorized MSG tasks, grouping them by hosts.",
356 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
357 " This option only has effect if this simulator is MSG-based. It traces the\n"
358 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
359 " can be used to track process location if this simulator has process migration.",
361 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
362 " This experimental option only has effect if this simulator is MSG-based.\n"
363 " It traces the communication volume of MSG send/receive.",
365 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
366 " This option can be used in all types of simulators build with SimGrid\n"
367 " to generate a uncategorized resource utilization graph to be used as\n"
368 " configuration for the Triva visualization analysis. This option\n"
369 " can be used with tracing/categorized:1 and tracing:1 options to\n"
370 " analyze an unmodified simulator before changing it to contain\n"
373 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
374 " This option can be used if this simulator uses tracing categories\n"
375 " in its code. The file specified by this option holds a graph configuration\n"
376 " file for the Triva visualization tool that can be used to analyze a categorized\n"
377 " resource utilization.",
381 void TRACE_generate_triva_uncat_conf (void)
383 char *output = TRACE_get_triva_uncat_conf ();
384 if (output && strlen(output) > 0){
385 FILE *file = fopen (output, "w");
386 xbt_assert1 (file != NULL,
387 "Unable to open file (%s) for writing triva graph "
388 "configuration (uncategorized).", output);
398 " type = separation;\n"
400 " values = (power_used);\n"
405 " dst = destination;\n"
406 " size = bandwidth;\n"
409 " type = separation;\n"
410 " size = bandwidth;\n"
411 " values = (bandwidth_used);\n"
414 " graphviz-algorithm = neato;\n"
421 void TRACE_generate_triva_cat_conf (void)
423 char *output = TRACE_get_triva_cat_conf();
424 if (output && strlen(output) > 0){
425 //check if we do have categories declared
426 if (xbt_dict_length(created_categories) == 0){
427 INFO0("No categories declared, ignoring generation of triva graph configuration");
430 xbt_dict_cursor_t cursor=NULL;
432 FILE *file = fopen (output, "w");
433 xbt_assert1 (file != NULL,
434 "Unable to open file (%s) for writing triva graph "
435 "configuration (categorized).", output);
445 " type = separation;\n"
448 xbt_dict_foreach(created_categories,cursor,key,data) {
449 fprintf(file, "%s, ",key);
457 " dst = destination;\n"
458 " size = bandwidth;\n"
461 " type = separation;\n"
462 " size = bandwidth;\n"
464 xbt_dict_foreach(created_categories,cursor,key,data) {
465 fprintf(file, "%s, ",key);
471 " graphviz-algorithm = neato;\n"
479 #undef OPT_TRACING_SMPI
480 #undef OPT_TRACING_SMPI_GROUP
481 #undef OPT_TRACING_CATEGORIZED
482 #undef OPT_TRACING_UNCATEGORIZED
483 #undef OPT_TRACING_MSG_TASK
484 #undef OPT_TRACING_MSG_PROCESS
485 #undef OPT_TRACING_MSG_VOLUME
486 #undef OPT_TRACING_FILENAME
487 #undef OPT_TRACING_PLATFORM_METHOD
488 #undef OPT_TRIVA_UNCAT_CONF
489 #undef OPT_TRIVA_CAT_CONF
491 #endif /* HAVE_TRACING */