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_paje_dump_buffer();
75 /* destroy all data structures of tracing (and free) */
76 destroyAllContainers();
78 /* close the trace file */
83 DEBUG0("Tracing system is shutdown");
87 void TRACE_activate (void)
89 xbt_assert0 (trace_active==0, "Tracing is already active.");
91 DEBUG0 ("Tracing is on");
94 void TRACE_desactivate (void)
97 DEBUG0 ("Tracing is off");
100 int TRACE_is_active (void)
105 int TRACE_is_enabled(void)
107 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
110 int TRACE_is_configured(void)
112 return trace_configured;
115 int TRACE_smpi_is_enabled(void)
117 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
120 int TRACE_smpi_is_grouped(void)
122 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
125 int TRACE_categorized (void)
127 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
130 int TRACE_uncategorized (void)
132 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
135 int TRACE_msg_task_is_enabled(void)
137 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
140 int TRACE_msg_process_is_enabled(void)
142 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
145 int TRACE_msg_volume_is_enabled(void)
147 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
150 char *TRACE_get_filename(void)
152 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
155 char *TRACE_get_platform_method(void)
157 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
160 char *TRACE_get_triva_uncat_conf (void)
162 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
165 char *TRACE_get_triva_cat_conf (void)
167 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
170 void TRACE_global_init(int *argc, char **argv)
172 /* name of the tracefile */
173 char *default_tracing_filename = xbt_strdup("simgrid.trace");
174 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
175 "Trace file created by the instrumented SimGrid.",
176 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
180 int default_tracing = 0;
181 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
183 xbt_cfgelm_int, &default_tracing, 0, 1,
187 int default_tracing_smpi = 0;
188 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
189 "Tracing of the SMPI interface.",
190 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
194 int default_tracing_smpi_grouped = 0;
195 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
196 "Group MPI processes by host.",
197 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
202 int default_tracing_platform = 0;
203 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
204 "Tracing of categorized platform (host and link) utilization.",
205 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
208 /* tracing uncategorized resource utilization */
209 int default_tracing_uncategorized = 0;
210 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
211 "Tracing of uncategorized resource (host and link) utilization.",
212 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
215 /* platform method */
216 char *default_tracing_platform_method = xbt_strdup("a");
217 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
218 "Tracing method used to register categorized resource behavior.",
219 xbt_cfgelm_string, &default_tracing_platform_method, 1,
223 int default_tracing_msg_task = 0;
224 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
225 "Tracing of MSG task behavior.",
226 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
230 int default_tracing_msg_process = 0;
231 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
232 "Tracing of MSG process behavior.",
233 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
236 /* msg volume (experimental) */
237 int default_tracing_msg_volume = 0;
238 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
239 "Tracing of MSG communication volume (experimental).",
240 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
243 /* Triva graph configuration for uncategorized tracing */
244 char *default_triva_uncat_conf_file = xbt_strdup ("");
245 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
246 "Triva Graph configuration file for uncategorized resource utilization traces.",
247 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
250 /* Triva graph configuration for uncategorized tracing */
251 char *default_triva_cat_conf_file = xbt_strdup ("");
252 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
253 "Triva Graph configuration file for categorized resource utilization traces.",
254 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
257 /* instrumentation can be considered configured now */
258 trace_configured = 1;
261 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
263 char str[INSTR_DEFAULT_STR_SIZE];
264 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
266 int len = strlen (str);
267 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
268 if (!!longdesc && detailed){
269 printf ("%s\n\n", longdesc);
273 void TRACE_help (int detailed)
276 "Description of the tracing options accepted by this simulator:\n\n");
277 print_line (OPT_TRACING, "Enable the tracing system",
278 " It activates the tracing system and register the simulation platform\n"
279 " in the trace file. You have to enable this option to others take effect.",
281 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
282 " It activates the categorized resource utilization tracing. It should\n"
283 " be enabled if tracing categories are used by this simulator.",
285 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
286 " It activates the uncategorized resource utilization tracing. Use it if\n"
287 " this simulator do not use tracing categories and resource use have to be\n"
290 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
291 " It changes the way resource utilization (categorized or not) is traced\n"
292 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
293 " by the CPU/network model of a given resource. Depending on the interface used\n"
294 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
295 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
296 " without losing details of resource utilization. Method 'c' generates even\n"
297 " smaller files by doing time integration during the simulation, but it loses\n"
298 " precision. If this last method is used, the smallest timeslice used in the\n"
299 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
300 " unsure, do not change this option.",
302 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
303 " A file with this name will be created to register the simulation. The file\n"
304 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
305 " tools. More information can be found in these webpages:\n"
306 " http://triva.gforge.inria.fr/\n"
307 " http://paje.sourceforge.net/",
309 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
310 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
311 " interface and generates a trace that can be analyzed using Gantt-like\n"
312 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
313 " state, and point-to-point communications can be analyzed with arrows.",
315 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
316 " This option only has effect if this simulator is SMPI-based. The processes\n"
317 " are grouped by the hosts where they were executed.",
319 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
320 " This option only has effect if this simulator is MSG-based. It traces the\n"
321 " behavior of all categorized MSG tasks, grouping them by hosts.",
323 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
324 " This option only has effect if this simulator is MSG-based. It traces the\n"
325 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
326 " can be used to track process location if this simulator has process migration.",
328 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
329 " This experimental option only has effect if this simulator is MSG-based.\n"
330 " It traces the communication volume of MSG send/receive.",
332 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
333 " This option can be used in all types of simulators build with SimGrid\n"
334 " to generate a uncategorized resource utilization graph to be used as\n"
335 " configuration for the Triva visualization analysis. This option\n"
336 " can be used with tracing/categorized:1 and tracing:1 options to\n"
337 " analyze an unmodified simulator before changing it to contain\n"
340 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
341 " This option can be used if this simulator uses tracing categories\n"
342 " in its code. The file specified by this option holds a graph configuration\n"
343 " file for the Triva visualization tool that can be used to analyze a categorized\n"
344 " resource utilization.",
348 void TRACE_generate_triva_uncat_conf (void)
350 char *output = TRACE_get_triva_uncat_conf ();
351 if (output && strlen(output) > 0){
352 xbt_dict_cursor_t cursor=NULL;
355 FILE *file = fopen (output, "w");
356 xbt_assert1 (file != NULL,
357 "Unable to open file (%s) for writing triva graph "
358 "configuration (uncategorized).", output);
361 fprintf (file, "{\n");
363 //register NODE types
364 fprintf (file, " node = (");
365 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
366 fprintf (file, "%s, ", name);
369 //register EDGE types
373 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
374 fprintf (file, "%s, ", name);
380 //register each NODE type layout
381 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
382 fprintf (file, " %s = {\n", name);
383 if (strcmp (name, "HOST") == 0){
388 " type = separation;\n"
390 " values = (power_used);\n"
392 }else if (strcmp (name, "ROUTER") == 0){
396 }else if (strcmp (name, "LINK") == 0){
399 " size = bandwidth;\n"
402 " type = separation;\n"
403 " size = bandwidth;\n"
404 " values = (bandwidth_used);\n"
407 fprintf (file, " };\n\n");
411 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
412 fprintf (file, " %s = { size = 1; };\n", name);
415 //graphviz configuration
416 fprintf (file, "\n");
417 fprintf (file, " graphviz-algorithm = neato;\n");
420 fprintf (file, "}\n");
425 void TRACE_generate_triva_cat_conf (void)
427 char *output = TRACE_get_triva_cat_conf();
428 if (output && strlen(output) > 0){
429 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
430 char *name, *name2, *value, *value2;
432 //check if we do have categories declared
433 if (xbt_dict_length(created_categories) == 0){
434 INFO0("No categories declared, ignoring generation of triva graph configuration");
438 FILE *file = fopen (output, "w");
439 xbt_assert1 (file != NULL,
440 "Unable to open file (%s) for writing triva graph "
441 "configuration (categorized).", output);
444 fprintf (file, "{\n");
446 //register NODE types
447 fprintf (file, " node = (");
448 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
449 fprintf (file, "%s, ", name);
452 //register EDGE types
456 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
457 fprintf (file, "%s, ", name);
463 //register each NODE type layout
464 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
465 fprintf (file, " %s = {\n", name);
466 if (strcmp (name, "HOST") == 0){
471 " type = separation;\n"
474 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
475 fprintf (file, "%s, ", name2);
480 }else if (strcmp (name, "ROUTER") == 0){
484 }else if (strcmp (name, "LINK") == 0){
487 " size = bandwidth;\n"
490 " type = separation;\n"
491 " size = bandwidth;\n"
493 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
494 fprintf (file, "%s, ", name2);
500 fprintf (file, " };\n\n");
504 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
505 fprintf (file, " %s = { size = 1; };\n", name);
508 //graphviz configuration
509 fprintf (file, "\n");
510 fprintf (file, " graphviz-algorithm = neato;\n");
513 fprintf (file, "}\n");
519 #undef OPT_TRACING_SMPI
520 #undef OPT_TRACING_SMPI_GROUP
521 #undef OPT_TRACING_CATEGORIZED
522 #undef OPT_TRACING_UNCATEGORIZED
523 #undef OPT_TRACING_MSG_TASK
524 #undef OPT_TRACING_MSG_PROCESS
525 #undef OPT_TRACING_MSG_VOLUME
526 #undef OPT_TRACING_FILENAME
527 #undef OPT_TRACING_PLATFORM_METHOD
528 #undef OPT_TRIVA_UNCAT_CONF
529 #undef OPT_TRIVA_CAT_CONF
531 #endif /* HAVE_TRACING */