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_TRIVA_UNCAT_CONF "triva/uncategorized"
25 #define OPT_TRIVA_CAT_CONF "triva/categorized"
27 static int trace_configured = 0;
28 static int trace_active = 0;
30 xbt_dict_t created_categories; //declared in instr_interface.c
34 // tracing system must be:
35 // - enabled (with --cfg=tracing:1)
36 // - already configured (TRACE_global_init already called)
37 if (!(TRACE_is_enabled() && TRACE_is_configured())){
41 XBT_DEBUG("Tracing starts");
43 /* open the trace file */
49 /* other trace initialization */
50 created_categories = xbt_dict_new();
58 if (!TRACE_is_active())
61 /* generate uncategorized graph configuration for triva */
62 if (TRACE_get_triva_uncat_conf()){
63 TRACE_generate_triva_uncat_conf();
66 /* generate categorized graph configuration for triva */
67 if (TRACE_get_triva_cat_conf()){
68 TRACE_generate_triva_cat_conf();
71 /* dump trace buffer */
72 TRACE_last_timestamp_to_dump = surf_get_clock();
73 TRACE_paje_dump_buffer(1);
75 /* destroy all data structures of tracing (and free) */
76 destroyAllContainers();
78 /* close the trace file */
83 XBT_DEBUG("Tracing system is shutdown");
87 void TRACE_activate (void)
89 xbt_assert (trace_active==0, "Tracing is already active.");
91 XBT_DEBUG ("Tracing is on");
94 void TRACE_desactivate (void)
97 XBT_DEBUG ("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) &&
121 int TRACE_smpi_is_grouped(void)
123 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
126 int TRACE_categorized (void)
128 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_CATEGORIZED);
131 int TRACE_uncategorized (void)
133 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
136 int TRACE_msg_task_is_enabled(void)
138 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK) &&
142 int TRACE_msg_process_is_enabled(void)
144 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS) &&
148 int TRACE_msg_volume_is_enabled(void)
150 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME) &&
154 char *TRACE_get_filename(void)
156 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
159 char *TRACE_get_triva_uncat_conf (void)
161 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
164 char *TRACE_get_triva_cat_conf (void)
166 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
169 void TRACE_global_init(int *argc, char **argv)
171 /* name of the tracefile */
172 char *default_tracing_filename = xbt_strdup("simgrid.trace");
173 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
174 "Trace file created by the instrumented SimGrid.",
175 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
179 int default_tracing = 0;
180 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
182 xbt_cfgelm_int, &default_tracing, 0, 1,
186 int default_tracing_smpi = 0;
187 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
188 "Tracing of the SMPI interface.",
189 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
193 int default_tracing_smpi_grouped = 0;
194 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
195 "Group MPI processes by host.",
196 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
201 int default_tracing_platform = 0;
202 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_CATEGORIZED,
203 "Tracing of categorized platform (host and link) utilization.",
204 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
207 /* tracing uncategorized resource utilization */
208 int default_tracing_uncategorized = 0;
209 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
210 "Tracing of uncategorized resource (host and link) utilization.",
211 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
215 int default_tracing_msg_task = 0;
216 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
217 "Tracing of MSG task behavior.",
218 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
222 int default_tracing_msg_process = 0;
223 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
224 "Tracing of MSG process behavior.",
225 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
228 /* msg volume (experimental) */
229 int default_tracing_msg_volume = 0;
230 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
231 "Tracing of MSG communication volume (experimental).",
232 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
235 /* Triva graph configuration for uncategorized tracing */
236 char *default_triva_uncat_conf_file = xbt_strdup ("");
237 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
238 "Triva Graph configuration file for uncategorized resource utilization traces.",
239 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
242 /* Triva graph configuration for uncategorized tracing */
243 char *default_triva_cat_conf_file = xbt_strdup ("");
244 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
245 "Triva Graph configuration file for categorized resource utilization traces.",
246 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
249 /* instrumentation can be considered configured now */
250 trace_configured = 1;
253 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
255 char str[INSTR_DEFAULT_STR_SIZE];
256 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
258 int len = strlen (str);
259 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
260 if (!!longdesc && detailed){
261 printf ("%s\n\n", longdesc);
265 void TRACE_help (int detailed)
268 "Description of the tracing options accepted by this simulator:\n\n");
269 print_line (OPT_TRACING, "Enable the tracing system",
270 " It activates the tracing system and register the simulation platform\n"
271 " in the trace file. You have to enable this option to others take effect.",
273 print_line (OPT_TRACING_CATEGORIZED, "Trace categorized resource utilization",
274 " It activates the categorized resource utilization tracing. It should\n"
275 " be enabled if tracing categories are used by this simulator.",
277 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
278 " It activates the uncategorized resource utilization tracing. Use it if\n"
279 " this simulator do not use tracing categories and resource use have to be\n"
282 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
283 " A file with this name will be created to register the simulation. The file\n"
284 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
285 " tools. More information can be found in these webpages:\n"
286 " http://triva.gforge.inria.fr/\n"
287 " http://paje.sourceforge.net/",
289 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
290 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
291 " interface and generates a trace that can be analyzed using Gantt-like\n"
292 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
293 " state, and point-to-point communications can be analyzed with arrows.",
295 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
296 " This option only has effect if this simulator is SMPI-based. The processes\n"
297 " are grouped by the hosts where they were executed.",
299 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
300 " This option only has effect if this simulator is MSG-based. It traces the\n"
301 " behavior of all categorized MSG tasks, grouping them by hosts.",
303 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
304 " This option only has effect if this simulator is MSG-based. It traces the\n"
305 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
306 " can be used to track process location if this simulator has process migration.",
308 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
309 " This experimental option only has effect if this simulator is MSG-based.\n"
310 " It traces the communication volume of MSG send/receive.",
312 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
313 " This option can be used in all types of simulators build with SimGrid\n"
314 " to generate a uncategorized resource utilization graph to be used as\n"
315 " configuration for the Triva visualization analysis. This option\n"
316 " can be used with tracing/categorized:1 and tracing:1 options to\n"
317 " analyze an unmodified simulator before changing it to contain\n"
320 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
321 " This option can be used if this simulator uses tracing categories\n"
322 " in its code. The file specified by this option holds a graph configuration\n"
323 " file for the Triva visualization tool that can be used to analyze a categorized\n"
324 " resource utilization.",
328 void TRACE_generate_triva_uncat_conf (void)
330 char *output = TRACE_get_triva_uncat_conf ();
331 if (output && strlen(output) > 0){
332 xbt_dict_cursor_t cursor=NULL;
335 FILE *file = fopen (output, "w");
336 xbt_assert (file != NULL,
337 "Unable to open file (%s) for writing triva graph "
338 "configuration (uncategorized).", output);
341 fprintf (file, "{\n");
343 //register NODE types
344 fprintf (file, " node = (");
345 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
346 fprintf (file, "%s, ", name);
349 //register EDGE types
353 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
354 fprintf (file, "%s, ", name);
360 //configuration for all nodes
365 " values = (power_used);\n"
369 " size = bandwidth;\n"
370 " values = (bandwidth_used);\n"
373 fprintf (file, "}\n");
378 void TRACE_generate_triva_cat_conf (void)
380 char *output = TRACE_get_triva_cat_conf();
381 if (output && strlen(output) > 0){
382 xbt_dict_cursor_t cursor=NULL, cursor2=NULL;
383 char *name, *name2, *value, *value2;
385 //check if we do have categories declared
386 if (xbt_dict_length(created_categories) == 0){
387 XBT_INFO("No categories declared, ignoring generation of triva graph configuration");
391 FILE *file = fopen (output, "w");
392 xbt_assert (file != NULL,
393 "Unable to open file (%s) for writing triva graph "
394 "configuration (categorized).", output);
397 fprintf (file, "{\n");
399 //register NODE types
400 fprintf (file, " node = (");
401 xbt_dict_foreach(trivaNodeTypes, cursor, name, value) {
402 fprintf (file, "%s, ", name);
405 //register EDGE types
409 xbt_dict_foreach(trivaEdgeTypes, cursor, name, value) {
410 fprintf (file, "%s, ", name);
416 //configuration for all nodes
422 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
423 fprintf (file, "p%s, ", name2);
430 " size = bandwidth;\n"
432 xbt_dict_foreach(created_categories,cursor2,name2,value2) {
433 fprintf (file, "b%s, ", name2);
439 fprintf (file, "}\n");
445 #undef OPT_TRACING_SMPI
446 #undef OPT_TRACING_SMPI_GROUP
447 #undef OPT_TRACING_CATEGORIZED
448 #undef OPT_TRACING_UNCATEGORIZED
449 #undef OPT_TRACING_MSG_TASK
450 #undef OPT_TRACING_MSG_PROCESS
451 #undef OPT_TRACING_MSG_VOLUME
452 #undef OPT_TRACING_FILENAME
453 #undef OPT_TRACING_PLATFORM_METHOD
454 #undef OPT_TRIVA_UNCAT_CONF
455 #undef OPT_TRIVA_CAT_CONF
457 #endif /* HAVE_TRACING */