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_PLATFORM "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 extern xbt_dict_t created_categories; //declared in instr_interface.c
33 void TRACE_activate (void)
35 xbt_assert0 (trace_active==0, "Tracing is already active.");
37 DEBUG0 ("Tracing is on");
40 void TRACE_desactivate (void)
43 DEBUG0 ("Tracing is off");
46 int TRACE_is_active (void)
51 int TRACE_is_enabled(void)
53 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
56 int TRACE_is_configured(void)
58 return trace_configured;
61 int TRACE_smpi_is_enabled(void)
63 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
66 int TRACE_smpi_is_grouped(void)
68 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
71 int TRACE_platform_is_enabled(void)
73 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
76 int TRACE_uncategorized (void)
78 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
81 int TRACE_msg_task_is_enabled(void)
83 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
86 int TRACE_msg_process_is_enabled(void)
88 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
91 int TRACE_msg_volume_is_enabled(void)
93 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
96 char *TRACE_get_filename(void)
98 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
101 char *TRACE_get_platform_method(void)
103 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
106 char *TRACE_get_triva_uncat_conf (void)
108 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
111 char *TRACE_get_triva_cat_conf (void)
113 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
116 void TRACE_global_init(int *argc, char **argv)
118 /* name of the tracefile */
119 char *default_tracing_filename = xbt_strdup("simgrid.trace");
120 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
121 "Trace file created by the instrumented SimGrid.",
122 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
126 int default_tracing = 0;
127 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
129 xbt_cfgelm_int, &default_tracing, 0, 1,
133 int default_tracing_smpi = 0;
134 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
135 "Tracing of the SMPI interface.",
136 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
140 int default_tracing_smpi_grouped = 0;
141 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
142 "Group MPI processes by host.",
143 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
148 int default_tracing_platform = 0;
149 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
150 "Tracing of categorized platform (host and link) utilization.",
151 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
154 /* tracing uncategorized resource utilization */
155 int default_tracing_uncategorized = 0;
156 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
157 "Tracing of uncategorized resource (host and link) utilization.",
158 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
161 /* platform method */
162 char *default_tracing_platform_method = xbt_strdup("a");
163 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
164 "Tracing method used to register categorized resource behavior.",
165 xbt_cfgelm_string, &default_tracing_platform_method, 1,
169 int default_tracing_msg_task = 0;
170 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
171 "Tracing of MSG task behavior.",
172 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
176 int default_tracing_msg_process = 0;
177 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
178 "Tracing of MSG process behavior.",
179 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
182 /* msg volume (experimental) */
183 int default_tracing_msg_volume = 0;
184 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
185 "Tracing of MSG communication volume (experimental).",
186 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
189 /* Triva graph configuration for uncategorized tracing */
190 char *default_triva_uncat_conf_file = xbt_strdup ("");
191 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
192 "Triva Graph configuration file for uncategorized resource utilization traces.",
193 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
196 /* Triva graph configuration for uncategorized tracing */
197 char *default_triva_cat_conf_file = xbt_strdup ("");
198 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
199 "Triva Graph configuration file for categorized resource utilization traces.",
200 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
203 /* instrumentation can be considered configured now */
204 trace_configured = 1;
207 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
209 char str[INSTR_DEFAULT_STR_SIZE];
210 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
212 int len = strlen (str);
213 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
214 if (!!longdesc && detailed){
215 printf ("%s\n\n", longdesc);
219 void TRACE_help (int detailed)
222 "Description of the tracing options accepted by this simulator:\n\n");
223 print_line (OPT_TRACING, "Enable the tracing system",
224 " It activates the tracing system and register the simulation platform\n"
225 " in the trace file. You have to enable this option to others take effect.",
227 print_line (OPT_TRACING_PLATFORM, "Trace categorized resource utilization",
228 " It activates the categorized resource utilization tracing. It should\n"
229 " be enabled if tracing categories are used by this simulator.",
231 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
232 " It activates the uncategorized resource utilization tracing. Use it if\n"
233 " this simulator do not use tracing categories and resource use have to be\n"
236 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
237 " It changes the way resource utilization (categorized or not) is traced\n"
238 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
239 " by the CPU/network model of a given resource. Depending on the interface used\n"
240 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
241 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
242 " without losing details of resource utilization. Method 'c' generates even\n"
243 " smaller files by doing time integration during the simulation, but it loses\n"
244 " precision. If this last method is used, the smallest timeslice used in the\n"
245 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
246 " unsure, do not change this option.",
248 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
249 " A file with this name will be created to register the simulation. The file\n"
250 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
251 " tools. More information can be found in these webpages:\n"
252 " http://triva.gforge.inria.fr/\n"
253 " http://paje.sourceforge.net/",
255 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
256 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
257 " interface and generates a trace that can be analyzed using Gantt-like\n"
258 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
259 " state, and point-to-point communications can be analyzed with arrows.",
261 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
262 " This option only has effect if this simulator is SMPI-based. The processes\n"
263 " are grouped by the hosts where they were executed.",
265 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
266 " This option only has effect if this simulator is MSG-based. It traces the\n"
267 " behavior of all categorized MSG tasks, grouping them by hosts.",
269 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
270 " This option only has effect if this simulator is MSG-based. It traces the\n"
271 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
272 " can be used to track process location if this simulator has process migration.",
274 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
275 " This experimental option only has effect if this simulator is MSG-based.\n"
276 " It traces the communication volume of MSG send/receive.",
278 print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
279 " This option can be used in all types of simulators build with SimGrid\n"
280 " to generate a uncategorized resource utilization graph to be used as\n"
281 " configuration for the Triva visualization analysis. This option\n"
282 " can be used with tracing/categorized:1 and tracing:1 options to\n"
283 " analyze an unmodified simulator before changing it to contain\n"
286 print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
287 " This option can be used if this simulator uses tracing categories\n"
288 " in its code. The file specified by this option holds a graph configuration\n"
289 " file for the Triva visualization tool that can be used to analyze a categorized\n"
290 " resource utilization.",
294 void TRACE_generate_triva_uncat_conf (void)
296 char *output = TRACE_get_triva_uncat_conf ();
297 if (output && strlen(output) > 0){
298 FILE *file = fopen (output, "w");
299 xbt_assert1 (file != NULL,
300 "Unable to open file (%s) for writing triva graph "
301 "configuration (uncategorized).", output);
311 " type = separation;\n"
313 " values = (power_used);\n"
318 " dst = destination;\n"
319 " size = bandwidth;\n"
322 " type = separation;\n"
323 " size = bandwidth;\n"
324 " values = (bandwidth_used);\n"
327 " graphviz-algorithm = neato;\n"
334 void TRACE_generate_triva_cat_conf (void)
336 char *output = TRACE_get_triva_cat_conf();
337 if (output && strlen(output) > 0){
338 //check if we do have categories declared
339 if (xbt_dict_length(created_categories) == 0){
340 INFO0("No categories declared, ignoring generation of triva graph configuration");
343 xbt_dict_cursor_t cursor=NULL;
345 FILE *file = fopen (output, "w");
346 xbt_assert1 (file != NULL,
347 "Unable to open file (%s) for writing triva graph "
348 "configuration (categorized).", output);
358 " type = separation;\n"
361 xbt_dict_foreach(created_categories,cursor,key,data) {
362 fprintf(file, "p%s, ",key);
370 " dst = destination;\n"
371 " size = bandwidth;\n"
374 " type = separation;\n"
375 " size = bandwidth;\n"
377 xbt_dict_foreach(created_categories,cursor,key,data) {
378 fprintf(file, "b%s, ",key);
384 " graphviz-algorithm = neato;\n"
392 #undef OPT_TRACING_SMPI
393 #undef OPT_TRACING_SMPI_GROUP
394 #undef OPT_TRACING_PLATFORM
395 #undef OPT_TRACING_UNCATEGORIZED
396 #undef OPT_TRACING_MSG_TASK
397 #undef OPT_TRACING_MSG_PROCESS
398 #undef OPT_TRACING_MSG_VOLUME
399 #undef OPT_TRACING_FILENAME
400 #undef OPT_TRACING_PLATFORM_METHOD
401 #undef OPT_TRIVA_UNCAT_CONF
402 #undef OPT_TRIVA_CAT_CONF
404 #endif /* HAVE_TRACING */