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();
92 TRACE_msg_process_alloc();
99 if (!TRACE_is_active())
102 /* close the trace file */
105 /* generate uncategorized graph configuration for triva */
106 if (TRACE_get_triva_uncat_conf()){
107 TRACE_generate_triva_uncat_conf();
110 /* generate categorized graph configuration for triva */
111 if (TRACE_get_triva_cat_conf()){
112 TRACE_generate_triva_cat_conf();
116 TRACE_desactivate ();
117 DEBUG0("Tracing system is shutdown");
121 void TRACE_activate (void)
123 xbt_assert0 (trace_active==0, "Tracing is already active.");
125 DEBUG0 ("Tracing is on");
128 void TRACE_desactivate (void)
131 DEBUG0 ("Tracing is off");
134 int TRACE_is_active (void)
139 int TRACE_is_enabled(void)
141 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
144 int TRACE_is_configured(void)
146 return trace_configured;
149 int TRACE_smpi_is_enabled(void)
151 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
154 int TRACE_smpi_is_grouped(void)
156 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
159 int TRACE_categorized (void)
161 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
164 int TRACE_uncategorized (void)
166 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
169 int TRACE_msg_task_is_enabled(void)
171 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
174 int TRACE_msg_process_is_enabled(void)
176 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
179 int TRACE_msg_volume_is_enabled(void)
181 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
184 char *TRACE_get_filename(void)
186 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
189 char *TRACE_get_platform_method(void)
191 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
194 char *TRACE_get_triva_uncat_conf (void)
196 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
199 char *TRACE_get_triva_cat_conf (void)
201 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
204 void TRACE_global_init(int *argc, char **argv)
206 /* name of the tracefile */
207 char *default_tracing_filename = xbt_strdup("simgrid.trace");
208 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
209 "Trace file created by the instrumented SimGrid.",
210 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
214 int default_tracing = 0;
215 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
217 xbt_cfgelm_int, &default_tracing, 0, 1,
221 int default_tracing_smpi = 0;
222 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
223 "Tracing of the SMPI interface.",
224 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
228 int default_tracing_smpi_grouped = 0;
229 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
230 "Group MPI processes by host.",
231 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
236 int default_tracing_platform = 0;
237 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
238 "Tracing of categorized platform (host and link) utilization.",
239 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
242 /* tracing uncategorized resource utilization */
243 int default_tracing_uncategorized = 0;
244 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
245 "Tracing of uncategorized resource (host and link) utilization.",
246 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
249 /* platform method */
250 char *default_tracing_platform_method = xbt_strdup("a");
251 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
252 "Tracing method used to register categorized resource behavior.",
253 xbt_cfgelm_string, &default_tracing_platform_method, 1,
257 int default_tracing_msg_task = 0;
258 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
259 "Tracing of MSG task behavior.",
260 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
264 int default_tracing_msg_process = 0;
265 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
266 "Tracing of MSG process behavior.",
267 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
270 /* msg volume (experimental) */
271 int default_tracing_msg_volume = 0;
272 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
273 "Tracing of MSG communication volume (experimental).",
274 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
277 /* Triva graph configuration for uncategorized tracing */
278 char *default_triva_uncat_conf_file = xbt_strdup ("");
279 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
280 "Triva Graph configuration file for uncategorized resource utilization traces.",
281 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
284 /* Triva graph configuration for uncategorized tracing */
285 char *default_triva_cat_conf_file = xbt_strdup ("");
286 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
287 "Triva Graph configuration file for categorized resource utilization traces.",
288 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
291 /* instrumentation can be considered configured now */
292 trace_configured = 1;
295 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
297 char str[INSTR_DEFAULT_STR_SIZE];
298 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
300 int len = strlen (str);
301 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
302 if (!!longdesc && detailed){
303 printf ("%s\n\n", longdesc);
307 void TRACE_help (int detailed)
310 "Description of the tracing options accepted by this simulator:\n\n");
311 print_line (OPT_TRACING, "Enable the tracing system",
312 " It activates the tracing system and register the simulation platform\n"
313 " in the trace file. You have to enable this option to others take effect.",
315 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
316 " It activates the categorized resource utilization tracing. It should\n"
317 " be enabled if tracing categories are used by this simulator.",
319 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
320 " It activates the uncategorized resource utilization tracing. Use it if\n"
321 " this simulator do not use tracing categories and resource use have to be\n"
324 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
325 " It changes the way resource utilization (categorized or not) is traced\n"
326 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
327 " by the CPU/network model of a given resource. Depending on the interface used\n"
328 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
329 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
330 " without losing details of resource utilization. Method 'c' generates even\n"
331 " smaller files by doing time integration during the simulation, but it loses\n"
332 " precision. If this last method is used, the smallest timeslice used in the\n"
333 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
334 " unsure, do not change this option.",
336 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
337 " A file with this name will be created to register the simulation. The file\n"
338 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
339 " tools. More information can be found in these webpages:\n"
340 " http://triva.gforge.inria.fr/\n"
341 " http://paje.sourceforge.net/",
343 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
344 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
345 " interface and generates a trace that can be analyzed using Gantt-like\n"
346 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
347 " state, and point-to-point communications can be analyzed with arrows.",
349 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
350 " This option only has effect if this simulator is SMPI-based. The processes\n"
351 " are grouped by the hosts where they were executed.",
353 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
354 " This option only has effect if this simulator is MSG-based. It traces the\n"
355 " behavior of all categorized MSG tasks, grouping them by hosts.",
357 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
358 " This option only has effect if this simulator is MSG-based. It traces the\n"
359 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
360 " can be used to track process location if this simulator has process migration.",
362 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
363 " This experimental option only has effect if this simulator is MSG-based.\n"
364 " It traces the communication volume of MSG send/receive.",
366 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
367 " This option can be used in all types of simulators build with SimGrid\n"
368 " to generate a uncategorized resource utilization graph to be used as\n"
369 " configuration for the Triva visualization analysis. This option\n"
370 " can be used with tracing/categorized:1 and tracing:1 options to\n"
371 " analyze an unmodified simulator before changing it to contain\n"
374 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
375 " This option can be used if this simulator uses tracing categories\n"
376 " in its code. The file specified by this option holds a graph configuration\n"
377 " file for the Triva visualization tool that can be used to analyze a categorized\n"
378 " resource utilization.",
382 void TRACE_generate_triva_uncat_conf (void)
384 char *output = TRACE_get_triva_uncat_conf ();
385 if (output && strlen(output) > 0){
386 FILE *file = fopen (output, "w");
387 xbt_assert1 (file != NULL,
388 "Unable to open file (%s) for writing triva graph "
389 "configuration (uncategorized).", output);
399 " type = separation;\n"
401 " values = (power_used);\n"
406 " dst = destination;\n"
407 " size = bandwidth;\n"
410 " type = separation;\n"
411 " size = bandwidth;\n"
412 " values = (bandwidth_used);\n"
415 " graphviz-algorithm = neato;\n"
422 void TRACE_generate_triva_cat_conf (void)
424 char *output = TRACE_get_triva_cat_conf();
425 if (output && strlen(output) > 0){
426 //check if we do have categories declared
427 if (xbt_dict_length(created_categories) == 0){
428 INFO0("No categories declared, ignoring generation of triva graph configuration");
431 xbt_dict_cursor_t cursor=NULL;
433 FILE *file = fopen (output, "w");
434 xbt_assert1 (file != NULL,
435 "Unable to open file (%s) for writing triva graph "
436 "configuration (categorized).", output);
446 " type = separation;\n"
449 xbt_dict_foreach(created_categories,cursor,key,data) {
450 fprintf(file, "%s, ",key);
458 " dst = destination;\n"
459 " size = bandwidth;\n"
462 " type = separation;\n"
463 " size = bandwidth;\n"
465 xbt_dict_foreach(created_categories,cursor,key,data) {
466 fprintf(file, "%s, ",key);
472 " graphviz-algorithm = neato;\n"
480 #undef OPT_TRACING_SMPI
481 #undef OPT_TRACING_SMPI_GROUP
482 #undef OPT_TRACING_CATEGORIZED
483 #undef OPT_TRACING_UNCATEGORIZED
484 #undef OPT_TRACING_MSG_TASK
485 #undef OPT_TRACING_MSG_PROCESS
486 #undef OPT_TRACING_MSG_VOLUME
487 #undef OPT_TRACING_FILENAME
488 #undef OPT_TRACING_PLATFORM_METHOD
489 #undef OPT_TRIVA_UNCAT_CONF
490 #undef OPT_TRIVA_CAT_CONF
492 #endif /* HAVE_TRACING */