Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
eebe5bca6511953a5538415669450834b6cbb997
[simgrid.git] / src / instr / instr_config.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7
8 #include "instr/instr_private.h"
9
10 #ifdef HAVE_TRACING
11
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");
14
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"
27
28 static int trace_configured = 0;
29 static int trace_active = 0;
30
31 extern xbt_dict_t created_categories; //declared in instr_interface.c
32
33 void TRACE_activate (void)
34 {
35   xbt_assert0 (trace_active==0, "Tracing is already active.");
36   trace_active = 1;
37   DEBUG0 ("Tracing is on");
38 }
39
40 void TRACE_desactivate (void)
41 {
42   trace_active = 0;
43   DEBUG0 ("Tracing is off");
44 }
45
46 int TRACE_is_active (void)
47 {
48   return trace_active;
49 }
50
51 int TRACE_is_enabled(void)
52 {
53   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
54 }
55
56 int TRACE_is_configured(void)
57 {
58   return trace_configured;
59 }
60
61 int TRACE_smpi_is_enabled(void)
62 {
63   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
64 }
65
66 int TRACE_smpi_is_grouped(void)
67 {
68   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
69 }
70
71 int TRACE_platform_is_enabled(void)
72 {
73   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
74 }
75
76 int TRACE_uncategorized (void)
77 {
78   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
79 }
80
81 int TRACE_msg_task_is_enabled(void)
82 {
83   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
84 }
85
86 int TRACE_msg_process_is_enabled(void)
87 {
88   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
89 }
90
91 int TRACE_msg_volume_is_enabled(void)
92 {
93   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
94 }
95
96 char *TRACE_get_filename(void)
97 {
98   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
99 }
100
101 char *TRACE_get_platform_method(void)
102 {
103   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
104 }
105
106 char *TRACE_get_triva_uncat_conf (void)
107 {
108   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
109 }
110
111 char *TRACE_get_triva_cat_conf (void)
112 {
113   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
114 }
115
116 void TRACE_global_init(int *argc, char **argv)
117 {
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,
123                    NULL, NULL);
124
125   /* tracing */
126   int default_tracing = 0;
127   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
128                    "Enable Tracing.",
129                    xbt_cfgelm_int, &default_tracing, 0, 1,
130                    NULL, NULL);
131
132   /* smpi */
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,
137                    NULL, NULL);
138
139   /* smpi grouped */
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,
144                    NULL, NULL);
145
146
147   /* platform */
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,
152                    NULL, NULL);
153
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,
159                    NULL, NULL);
160
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,
166                    1, NULL, NULL);
167
168   /* msg task */
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,
173                    NULL, NULL);
174
175   /* msg process */
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,
180                    NULL, NULL);
181
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,
187                    NULL, NULL);
188
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,
194                    NULL, NULL);
195
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,
201                    NULL, NULL);
202
203   /* instrumentation can be considered configured now */
204   trace_configured = 1;
205 }
206
207 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
208 {
209   char str[INSTR_DEFAULT_STR_SIZE];
210   snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
211
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);
216   }
217 }
218
219 void TRACE_help (int detailed)
220 {
221   printf(
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.",
226       detailed);
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.",
230       detailed);
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"
234       "  traced.",
235       detailed);
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.",
247       detailed);
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/",
254       detailed);
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.",
260       detailed);
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.",
264       detailed);
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.",
268       detailed);
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.",
273       detailed);
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.",
277       detailed);
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"
284       "  categories.",
285       detailed);
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.",
291       detailed);
292 }
293
294 void TRACE_generate_triva_uncat_conf (void)
295 {
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);
302     fprintf (file,
303         "{\n"
304         "  node = (HOST);\n"
305         "  edge = (LINK);\n"
306         "\n"
307         "  HOST = {\n"
308         "    size = power;\n"
309         "    scale = global;\n"
310         "    host_sep = {\n"
311         "      type = separation;\n"
312         "      size = power;\n"
313         "      values = (power_used);\n"
314         "    };\n"
315         "  };\n"
316         "  LINK = {\n"
317         "    src = source;\n"
318         "    dst = destination;\n"
319         "    size = bandwidth;\n"
320         "    scale = global;\n"
321         "    link_sep = {\n"
322         "      type = separation;\n"
323         "      size = bandwidth;\n"
324         "      values = (bandwidth_used);\n"
325         "    };\n"
326         "  };\n"
327         "  graphviz-algorithm = neato;\n"
328         "}\n"
329         );
330     fclose (file);
331   }
332 }
333
334 void TRACE_generate_triva_cat_conf (void)
335 {
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");
341       return;
342     }
343     xbt_dict_cursor_t cursor=NULL;
344     char *key, *data;
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);
349     fprintf (file,
350         "{\n"
351         "  node = (HOST);\n"
352         "  edge = (LINK);\n"
353         "\n"
354         "  HOST = {\n"
355         "    size = power;\n"
356         "    scale = global;\n"
357         "    host_sep = {\n"
358         "      type = separation;\n"
359         "      size = power;\n"
360         "      values = (");
361     xbt_dict_foreach(created_categories,cursor,key,data) {
362       fprintf(file, "p%s, ",key);
363     }
364     fprintf (file,
365         ");\n"
366         "    };\n"
367         "  };\n"
368         "  LINK = {\n"
369         "    src = source;\n"
370         "    dst = destination;\n"
371         "    size = bandwidth;\n"
372         "    scale = global;\n"
373         "    link_sep = {\n"
374         "      type = separation;\n"
375         "      size = bandwidth;\n"
376         "      values = (");
377     xbt_dict_foreach(created_categories,cursor,key,data) {
378       fprintf(file, "b%s, ",key);
379     }
380     fprintf (file,
381         ");\n"
382         "    };\n"
383         "  };\n"
384         "  graphviz-algorithm = neato;\n"
385         "}\n"
386         );
387     fclose(file);
388   }
389 }
390
391 #undef OPT_TRACING
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
403
404 #endif /* HAVE_TRACING */