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 #define OPT_TRACING "tracing"
13 #define OPT_TRACING_SMPI "tracing/smpi"
14 #define OPT_TRACING_SMPI_GROUP "tracing/smpi/group"
15 #define OPT_TRACING_PLATFORM "tracing/platform"
16 #define OPT_TRACING_UNCATEGORIZED "tracing/uncategorized"
17 #define OPT_TRACING_MSG_TASK "tracing/msg/task"
18 #define OPT_TRACING_MSG_PROCESS "tracing/msg/process"
19 #define OPT_TRACING_MSG_VOLUME "tracing/msg/volume"
20 #define OPT_TRACING_FILENAME "tracing/filename"
21 #define OPT_TRACING_PLATFORM_METHOD "tracing/platform/method"
22 #define OPT_TRIVA_UNCAT_CONF "triva/uncategorized"
23 #define OPT_TRIVA_CAT_CONF "triva/categorized"
25 static int trace_configured = 0;
26 static int trace_active = 0;
28 extern xbt_dict_t created_categories; //declared in instr_interface.c
30 void TRACE_activate (void)
33 THROW0(tracing_error, TRACE_ERROR_ALREADY_ACTIVE,
34 "Tracing is already active.");
39 void TRACE_desactivate (void)
44 int TRACE_is_active (void)
49 int TRACE_is_enabled(void)
51 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
54 int TRACE_is_configured(void)
56 return trace_configured;
59 int TRACE_smpi_is_enabled(void)
61 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
64 int TRACE_smpi_is_grouped(void)
66 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
69 int TRACE_platform_is_enabled(void)
71 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
74 int TRACE_uncategorized (void)
76 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
79 int TRACE_msg_task_is_enabled(void)
81 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
84 int TRACE_msg_process_is_enabled(void)
86 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
89 int TRACE_msg_volume_is_enabled(void)
91 return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
94 char *TRACE_get_filename(void)
96 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
99 char *TRACE_get_platform_method(void)
101 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
104 char *TRACE_get_triva_uncat_conf (void)
106 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
109 char *TRACE_get_triva_cat_conf (void)
111 return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
114 void TRACE_global_init(int *argc, char **argv)
116 /* name of the tracefile */
117 char *default_tracing_filename = xbt_strdup("simgrid.trace");
118 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
119 "Trace file created by the instrumented SimGrid.",
120 xbt_cfgelm_string, &default_tracing_filename, 1, 1,
124 int default_tracing = 0;
125 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
127 xbt_cfgelm_int, &default_tracing, 0, 1,
131 int default_tracing_smpi = 0;
132 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
133 "Tracing of the SMPI interface.",
134 xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
138 int default_tracing_smpi_grouped = 0;
139 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
140 "Group MPI processes by host.",
141 xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
146 int default_tracing_platform = 0;
147 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
148 "Tracing of categorized platform (host and link) utilization.",
149 xbt_cfgelm_int, &default_tracing_platform, 0, 1,
152 /* tracing uncategorized resource utilization */
153 int default_tracing_uncategorized = 0;
154 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
155 "Tracing of uncategorized resource (host and link) utilization.",
156 xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
159 /* platform method */
160 char *default_tracing_platform_method = xbt_strdup("a");
161 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
162 "Tracing method used to register categorized resource behavior.",
163 xbt_cfgelm_string, &default_tracing_platform_method, 1,
167 int default_tracing_msg_task = 0;
168 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
169 "Tracing of MSG task behavior.",
170 xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
174 int default_tracing_msg_process = 0;
175 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
176 "Tracing of MSG process behavior.",
177 xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
180 /* msg volume (experimental) */
181 int default_tracing_msg_volume = 0;
182 xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
183 "Tracing of MSG communication volume (experimental).",
184 xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
187 /* Triva graph configuration for uncategorized tracing */
188 char *default_triva_uncat_conf_file = xbt_strdup ("");
189 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
190 "Triva Graph configuration file for uncategorized resource utilization traces.",
191 xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
194 /* Triva graph configuration for uncategorized tracing */
195 char *default_triva_cat_conf_file = xbt_strdup ("");
196 xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
197 "Triva Graph configuration file for categorized resource utilization traces.",
198 xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
201 /* instrumentation can be considered configured now */
202 trace_configured = 1;
205 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
207 char str[INSTR_DEFAULT_STR_SIZE];
208 snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
210 int len = strlen (str);
211 printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
212 if (!!longdesc && detailed){
213 printf ("%s\n\n", longdesc);
217 void TRACE_help (int detailed)
220 "Description of the tracing options accepted by this simulator:\n\n");
221 print_line (OPT_TRACING, "Enable the tracing system",
222 " It activates the tracing system and register the simulation platform\n"
223 " in the trace file. You have to enable this option to others take effect.",
225 print_line (OPT_TRACING_PLATFORM, "Trace categorized resource utilization",
226 " It activates the categorized resource utilization tracing. It should\n"
227 " be enabled if tracing categories are used by this simulator.",
229 print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
230 " It activates the uncategorized resource utilization tracing. Use it if\n"
231 " this simulator do not use tracing categories and resource use have to be\n"
234 print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
235 " It changes the way resource utilization (categorized or not) is traced\n"
236 " inside the simulation core. Method 'a' (default) traces all updates defined\n"
237 " by the CPU/network model of a given resource. Depending on the interface used\n"
238 " by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
239 " trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
240 " without losing details of resource utilization. Method 'c' generates even\n"
241 " smaller files by doing time integration during the simulation, but it loses\n"
242 " precision. If this last method is used, the smallest timeslice used in the\n"
243 " tracefile analysis must be bigger than the smaller resource utilization. If\n"
244 " unsure, do not change this option.",
246 print_line (OPT_TRACING_FILENAME, "Filename to register traces",
247 " A file with this name will be created to register the simulation. The file\n"
248 " is in the Paje format and can be analyzed using Triva or Paje visualization\n"
249 " tools. More information can be found in these webpages:\n"
250 " http://triva.gforge.inria.fr/\n"
251 " http://paje.sourceforge.net/",
253 print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
254 " This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
255 " interface and generates a trace that can be analyzed using Gantt-like\n"
256 " visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
257 " state, and point-to-point communications can be analyzed with arrows.",
259 print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
260 " This option only has effect if this simulator is SMPI-based. The processes\n"
261 " are grouped by the hosts where they were executed.",
263 print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
264 " This option only has effect if this simulator is MSG-based. It traces the\n"
265 " behavior of all categorized MSG tasks, grouping them by hosts.",
267 print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
268 " This option only has effect if this simulator is MSG-based. It traces the\n"
269 " behavior of all categorized MSG processes, grouping them by hosts. This option\n"
270 " can be used to track process location if this simulator has process migration.",
272 print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
273 " This experimental option only has effect if this simulator is MSG-based.\n"
274 " It traces the communication volume of MSG send/receive.",
278 void TRACE_generate_triva_uncat_conf (void)
280 char *output = TRACE_get_triva_uncat_conf ();
281 if (output && strlen(output) > 0){
282 FILE *file = fopen (output, "w");
284 THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
285 "Unable to open file (%s) for writing triva graph configuration (uncategorized).", output);
296 " type = separation;\n"
298 " values = (power_used);\n"
303 " dst = destination;\n"
304 " size = bandwidth;\n"
307 " type = separation;\n"
308 " size = bandwidth;\n"
309 " values = (bandwidth_used);\n"
312 " graphviz-algorithm = neato;\n"
319 void TRACE_generate_triva_cat_conf (void)
321 char *output = TRACE_get_triva_cat_conf();
322 if (output && strlen(output) > 0){
323 //check if we do have categories declared
324 if (xbt_dict_length(created_categories) == 0){
325 // INFO0("No categories declared, ignoring generation of triva graph configuration");
328 xbt_dict_cursor_t cursor=NULL;
330 FILE *file = fopen (output, "w");
332 THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
333 "Unable to open file (%s) for writing triva graph configuration (categorized).", output);
344 " type = separation;\n"
347 xbt_dict_foreach(created_categories,cursor,key,data) {
348 fprintf(file, "p%s, ",key);
356 " dst = destination;\n"
357 " size = bandwidth;\n"
360 " type = separation;\n"
361 " size = bandwidth;\n"
363 xbt_dict_foreach(created_categories,cursor,key,data) {
364 fprintf(file, "b%s, ",key);
370 " graphviz-algorithm = neato;\n"
378 #undef OPT_TRACING_SMPI
379 #undef OPT_TRACING_SMPI_GROUP
380 #undef OPT_TRACING_PLATFORM
381 #undef OPT_TRACING_UNCATEGORIZED
382 #undef OPT_TRACING_MSG_TASK
383 #undef OPT_TRACING_MSG_PROCESS
384 #undef OPT_TRACING_MSG_VOLUME
385 #undef OPT_TRACING_FILENAME
386 #undef OPT_TRACING_PLATFORM_METHOD
387 #undef OPT_TRIVA_UNCAT_CONF
388 #undef OPT_TRIVA_CAT_CONF
390 #endif /* HAVE_TRACING */