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 /* other trace initialization */
51 created_categories = xbt_dict_new();
59 if (!TRACE_is_active())
62 /* generate uncategorized graph configuration for triva */
63 if (TRACE_get_triva_uncat_conf()){
64 TRACE_generate_triva_uncat_conf();
67 /* generate categorized graph configuration for triva */
68 if (TRACE_get_triva_cat_conf()){
69 TRACE_generate_triva_cat_conf();
72 /* dump trace buffer */
73 TRACE_last_timestamp_to_dump = surf_get_clock();
74 TRACE_paje_dump_buffer(1);
76 /* destroy all data structures of tracing (and free) */
77 destroyAllContainers();
79 /* close the trace file */
84 DEBUG0("Tracing system is shutdown");
88 void TRACE_activate (void)
90 xbt_assert0 (trace_active==0, "Tracing is already active.");
92 DEBUG0 ("Tracing is on");
95 void TRACE_desactivate (void)
98 DEBUG0 ("Tracing is off");
101 int TRACE_is_active (void)
106 int TRACE_is_enabled(void)
108 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
111 int TRACE_is_configured(void)
113 return trace_configured;
116 int TRACE_smpi_is_enabled(void)
118 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI) &&
122 int TRACE_smpi_is_grouped(void)
124 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
127 int TRACE_categorized (void)
129 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
132 int TRACE_uncategorized (void)
134 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
137 int TRACE_msg_task_is_enabled(void)
139 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK) &&
143 int TRACE_msg_process_is_enabled(void)
145 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS) &&
149 int TRACE_msg_volume_is_enabled(void)
151 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME) &&
155 char *TRACE_get_filename(void)
157 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
160 char *TRACE_get_platform_method(void)
162 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
165 char *TRACE_get_triva_uncat_conf (void)
167 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
170 char *TRACE_get_triva_cat_conf (void)
172 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
175 void TRACE_global_init(int *argc, char **argv)
177 /* name of the tracefile */
178 char *default_tracing_filename = xbt_strdup("simgrid.trace");
179 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
180 "Trace file created by the instrumented SimGrid.",
181 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
185 int default_tracing = 0;
186 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
188 xbt_cfgelm_int, &default_tracing, 0, 1,
192 int default_tracing_smpi = 0;
193 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
194 "Tracing of the SMPI interface.",
195 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
199 int default_tracing_smpi_grouped = 0;
200 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
201 "Group MPI processes by host.",
202 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
207 int default_tracing_platform = 0;
208 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
209 "Tracing of categorized platform (host and link) utilization.",
210 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
213 /* tracing uncategorized resource utilization */
214 int default_tracing_uncategorized = 0;
215 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
216 "Tracing of uncategorized resource (host and link) utilization.",
217 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
220 /* platform method */
221 char *default_tracing_platform_method = xbt_strdup("a");
222 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
223 "Tracing method used to register categorized resource behavior.",
224 xbt_cfgelm_string, &default_tracing_platform_method, 1,
228 int default_tracing_msg_task = 0;
229 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
230 "Tracing of MSG task behavior.",
231 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
235 int default_tracing_msg_process = 0;
236 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
237 "Tracing of MSG process behavior.",
238 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
241 /* msg volume (experimental) */
242 int default_tracing_msg_volume = 0;
243 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
244 "Tracing of MSG communication volume (experimental).",
245 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
248 /* Triva graph configuration for uncategorized tracing */
249 char *default_triva_uncat_conf_file = xbt_strdup ("");
250 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
251 "Triva Graph configuration file for uncategorized resource utilization traces.",
252 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
255 /* Triva graph configuration for uncategorized tracing */
256 char *default_triva_cat_conf_file = xbt_strdup ("");
257 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
258 "Triva Graph configuration file for categorized resource utilization traces.",
259 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
262 /* instrumentation can be considered configured now */
263 trace_configured = 1;
266 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
268 char str[INSTR_DEFAULT_STR_SIZE];
269 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
271 int len = strlen (str);
272 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
273 if (!!longdesc && detailed){
274 printf ("%s\n\n", longdesc);
278 void TRACE_help (int detailed)
281 "Description of the tracing options accepted by this simulator:\n\n");
282 print_line (OPT_TRACING, "Enable the tracing system",
283 " It activates the tracing system and register the simulation platform\n"
284 " in the trace file. You have to enable this option to others take effect.",
286 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
287 " It activates the categorized resource utilization tracing. It should\n"
288 " be enabled if tracing categories are used by this simulator.",
290 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
291 " It activates the uncategorized resource utilization tracing. Use it if\n"
292 " this simulator do not use tracing categories and resource use have to be\n"
295 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
296 " It changes the way resource utilization (categorized or not) is traced\n"
297 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
298 " by the CPU/network model of a given resource. Depending on the interface used\n"
299 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
300 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
301 " without losing details of resource utilization. Method 'c' generates even\n"
302 " smaller files by doing time integration during the simulation, but it loses\n"
303 " precision. If this last method is used, the smallest timeslice used in the\n"
304 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
305 " unsure, do not change this option.",
307 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
308 " A file with this name will be created to register the simulation. The file\n"
309 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
310 " tools. More information can be found in these webpages:\n"
311 " http://triva.gforge.inria.fr/\n"
312 " http://paje.sourceforge.net/",
314 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
315 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
316 " interface and generates a trace that can be analyzed using Gantt-like\n"
317 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
318 " state, and point-to-point communications can be analyzed with arrows.",
320 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
321 " This option only has effect if this simulator is SMPI-based. The processes\n"
322 " are grouped by the hosts where they were executed.",
324 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
325 " This option only has effect if this simulator is MSG-based. It traces the\n"
326 " behavior of all categorized MSG tasks, grouping them by hosts.",
328 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
329 " This option only has effect if this simulator is MSG-based. It traces the\n"
330 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
331 " can be used to track process location if this simulator has process migration.",
333 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
334 " This experimental option only has effect if this simulator is MSG-based.\n"
335 " It traces the communication volume of MSG send/receive.",
337 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
338 " This option can be used in all types of simulators build with SimGrid\n"
339 " to generate a uncategorized resource utilization graph to be used as\n"
340 " configuration for the Triva visualization analysis. This option\n"
341 " can be used with tracing/categorized:1 and tracing:1 options to\n"
342 " analyze an unmodified simulator before changing it to contain\n"
345 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
346 " This option can be used if this simulator uses tracing categories\n"
347 " in its code. The file specified by this option holds a graph configuration\n"
348 " file for the Triva visualization tool that can be used to analyze a categorized\n"
349 " resource utilization.",
353 void TRACE_generate_triva_uncat_conf (void)
355 char *output = TRACE_get_triva_uncat_conf ();
356 if (output && strlen(output) > 0){
357 xbt_dict_cursor_t cursor=NULL;
360 FILE *file = fopen (output, "w");
361 xbt_assert1 (file != NULL,
362 "Unable to open file (%s) for writing triva graph "
363 "configuration (uncategorized).", output);
366 fprintf (file, "{\n");
368 //register NODE types
369 fprintf (file, " node = (");
370 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
371 fprintf (file, "%s, ", name);
374 //register EDGE types
378 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
379 fprintf (file, "%s, ", name);
385 //register each NODE type layout
386 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
387 fprintf (file, " %s = {\n", name);
388 if (strcmp (name, "HOST") == 0){
393 " type = separation;\n"
395 " values = (power_used);\n"
397 }else if (strcmp (name, "ROUTER") == 0){
401 }else if (strcmp (name, "LINK") == 0){
404 " size = bandwidth;\n"
407 " type = separation;\n"
408 " size = bandwidth;\n"
409 " values = (bandwidth_used);\n"
412 fprintf (file, " };\n\n");
416 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
417 fprintf (file, " %s = { size = 1; };\n", name);
420 //graphviz configuration
421 fprintf (file, "\n");
422 fprintf (file, " graphviz-algorithm = neato;\n");
425 fprintf (file, "}\n");
430 void TRACE_generate_triva_cat_conf (void)
432 char *output = TRACE_get_triva_cat_conf();
433 if (output && strlen(output) > 0){
434 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
435 char *name, *name2, *value, *value2;
437 //check if we do have categories declared
438 if (xbt_dict_length(created_categories) == 0){
439 INFO0("No categories declared, ignoring generation of triva graph configuration");
443 FILE *file = fopen (output, "w");
444 xbt_assert1 (file != NULL,
445 "Unable to open file (%s) for writing triva graph "
446 "configuration (categorized).", output);
449 fprintf (file, "{\n");
451 //register NODE types
452 fprintf (file, " node = (");
453 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
454 fprintf (file, "%s, ", name);
457 //register EDGE types
461 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
462 fprintf (file, "%s, ", name);
468 //register each NODE type layout
469 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
470 fprintf (file, " %s = {\n", name);
471 if (strcmp (name, "HOST") == 0){
476 " type = separation;\n"
479 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
480 fprintf (file, "%s, ", name2);
485 }else if (strcmp (name, "ROUTER") == 0){
489 }else if (strcmp (name, "LINK") == 0){
492 " size = bandwidth;\n"
495 " type = separation;\n"
496 " size = bandwidth;\n"
498 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
499 fprintf (file, "%s, ", name2);
505 fprintf (file, " };\n\n");
509 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
510 fprintf (file, " %s = { size = 1; };\n", name);
513 //graphviz configuration
514 fprintf (file, "\n");
515 fprintf (file, " graphviz-algorithm = neato;\n");
518 fprintf (file, "}\n");
524 #undef OPT_TRACING_SMPI
525 #undef OPT_TRACING_SMPI_GROUP
526 #undef OPT_TRACING_CATEGORIZED
527 #undef OPT_TRACING_UNCATEGORIZED
528 #undef OPT_TRACING_MSG_TASK
529 #undef OPT_TRACING_MSG_PROCESS
530 #undef OPT_TRACING_MSG_VOLUME
531 #undef OPT_TRACING_FILENAME
532 #undef OPT_TRACING_PLATFORM_METHOD
533 #undef OPT_TRIVA_UNCAT_CONF
534 #undef OPT_TRIVA_CAT_CONF
536 #endif /* HAVE_TRACING */