Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bad7e613de505a7d0f06bb20b1f1e50900f5abe0
[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/platform"
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   if (trace_active){
36     THROW0(tracing_error, TRACE_ERROR_ALREADY_ACTIVE,
37            "Tracing is already active.");
38   }
39   trace_active = 1;
40 }
41
42 void TRACE_desactivate (void)
43 {
44   trace_active = 0;
45 }
46
47 int TRACE_is_active (void)
48 {
49   return trace_active;
50 }
51
52 int TRACE_is_enabled(void)
53 {
54   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
55 }
56
57 int TRACE_is_configured(void)
58 {
59   return trace_configured;
60 }
61
62 int TRACE_smpi_is_enabled(void)
63 {
64   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
65 }
66
67 int TRACE_smpi_is_grouped(void)
68 {
69   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
70 }
71
72 int TRACE_platform_is_enabled(void)
73 {
74   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
75 }
76
77 int TRACE_uncategorized (void)
78 {
79   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
80 }
81
82 int TRACE_msg_task_is_enabled(void)
83 {
84   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
85 }
86
87 int TRACE_msg_process_is_enabled(void)
88 {
89   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
90 }
91
92 int TRACE_msg_volume_is_enabled(void)
93 {
94   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
95 }
96
97 char *TRACE_get_filename(void)
98 {
99   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
100 }
101
102 char *TRACE_get_platform_method(void)
103 {
104   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
105 }
106
107 char *TRACE_get_triva_uncat_conf (void)
108 {
109   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
110 }
111
112 char *TRACE_get_triva_cat_conf (void)
113 {
114   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
115 }
116
117 void TRACE_global_init(int *argc, char **argv)
118 {
119   /* name of the tracefile */
120   char *default_tracing_filename = xbt_strdup("simgrid.trace");
121   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_FILENAME,
122                    "Trace file created by the instrumented SimGrid.",
123                    xbt_cfgelm_string, &default_tracing_filename, 1, 1,
124                    NULL, NULL);
125
126   /* tracing */
127   int default_tracing = 0;
128   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
129                    "Enable Tracing.",
130                    xbt_cfgelm_int, &default_tracing, 0, 1,
131                    NULL, NULL);
132
133   /* smpi */
134   int default_tracing_smpi = 0;
135   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI,
136                    "Tracing of the SMPI interface.",
137                    xbt_cfgelm_int, &default_tracing_smpi, 0, 1,
138                    NULL, NULL);
139
140   /* smpi grouped */
141   int default_tracing_smpi_grouped = 0;
142   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_SMPI_GROUP,
143                    "Group MPI processes by host.",
144                    xbt_cfgelm_int, &default_tracing_smpi_grouped, 0, 1,
145                    NULL, NULL);
146
147
148   /* platform */
149   int default_tracing_platform = 0;
150   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM,
151                    "Tracing of categorized platform (host and link) utilization.",
152                    xbt_cfgelm_int, &default_tracing_platform, 0, 1,
153                    NULL, NULL);
154
155   /* tracing uncategorized resource utilization */
156   int default_tracing_uncategorized = 0;
157   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_UNCATEGORIZED,
158                    "Tracing of uncategorized resource (host and link) utilization.",
159                    xbt_cfgelm_int, &default_tracing_uncategorized, 0, 1,
160                    NULL, NULL);
161
162   /* platform method */
163   char *default_tracing_platform_method = xbt_strdup("a");
164   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD,
165                    "Tracing method used to register categorized resource behavior.",
166                    xbt_cfgelm_string, &default_tracing_platform_method, 1,
167                    1, NULL, NULL);
168
169   /* msg task */
170   int default_tracing_msg_task = 0;
171   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_TASK,
172                    "Tracing of MSG task behavior.",
173                    xbt_cfgelm_int, &default_tracing_msg_task, 0, 1,
174                    NULL, NULL);
175
176   /* msg process */
177   int default_tracing_msg_process = 0;
178   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_PROCESS,
179                    "Tracing of MSG process behavior.",
180                    xbt_cfgelm_int, &default_tracing_msg_process, 0, 1,
181                    NULL, NULL);
182
183   /* msg volume (experimental) */
184   int default_tracing_msg_volume = 0;
185   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING_MSG_VOLUME,
186                    "Tracing of MSG communication volume (experimental).",
187                    xbt_cfgelm_int, &default_tracing_msg_volume, 0, 1,
188                    NULL, NULL);
189
190   /* Triva graph configuration for uncategorized tracing */
191   char *default_triva_uncat_conf_file = xbt_strdup ("");
192   xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_UNCAT_CONF,
193                    "Triva Graph configuration file for uncategorized resource utilization traces.",
194                    xbt_cfgelm_string, &default_triva_uncat_conf_file, 1, 1,
195                    NULL, NULL);
196
197   /* Triva graph configuration for uncategorized tracing */
198   char *default_triva_cat_conf_file = xbt_strdup ("");
199   xbt_cfg_register(&_surf_cfg_set, OPT_TRIVA_CAT_CONF,
200                    "Triva Graph configuration file for categorized resource utilization traces.",
201                    xbt_cfgelm_string, &default_triva_cat_conf_file, 1, 1,
202                    NULL, NULL);
203
204   /* instrumentation can be considered configured now */
205   trace_configured = 1;
206 }
207
208 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
209 {
210   char str[INSTR_DEFAULT_STR_SIZE];
211   snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
212
213   int len = strlen (str);
214   printf ("%s%*.*s %s\n", str, 30-len, 30-len, "", desc);
215   if (!!longdesc && detailed){
216     printf ("%s\n\n", longdesc);
217   }
218 }
219
220 void TRACE_help (int detailed)
221 {
222   printf(
223       "Description of the tracing options accepted by this simulator:\n\n");
224   print_line (OPT_TRACING, "Enable the tracing system",
225       "  It activates the tracing system and register the simulation platform\n"
226       "  in the trace file. You have to enable this option to others take effect.",
227       detailed);
228   print_line (OPT_TRACING_PLATFORM, "Trace categorized resource utilization",
229       "  It activates the categorized resource utilization tracing. It should\n"
230       "  be enabled if tracing categories are used by this simulator.",
231       detailed);
232   print_line (OPT_TRACING_UNCATEGORIZED, "Trace uncategorized resource utilization",
233       "  It activates the uncategorized resource utilization tracing. Use it if\n"
234       "  this simulator do not use tracing categories and resource use have to be\n"
235       "  traced.",
236       detailed);
237   print_line (OPT_TRACING_PLATFORM_METHOD, "Change the resource utilization tracing method",
238       "  It changes the way resource utilization (categorized or not) is traced\n"
239       "  inside the simulation core. Method 'a' (default) traces all updates defined\n"
240       "  by the CPU/network model of a given resource. Depending on the interface used\n"
241       "  by this simulator (MSG, SMPI, SimDAG), the default method can generate large\n"
242       "  trace files. Method 'b' tries to make smaller tracefiles using clever updates,\n"
243       "  without losing details of resource utilization. Method 'c' generates even\n"
244       "  smaller files by doing time integration during the simulation, but it loses\n"
245       "  precision. If this last method is used, the smallest timeslice used in the\n"
246       "  tracefile analysis must be bigger than the smaller resource utilization. If\n"
247       "  unsure, do not change this option.",
248       detailed);
249   print_line (OPT_TRACING_FILENAME, "Filename to register traces",
250       "  A file with this name will be created to register the simulation. The file\n"
251       "  is in the Paje format and can be analyzed using Triva or Paje visualization\n"
252       "  tools. More information can be found in these webpages:\n"
253       "     http://triva.gforge.inria.fr/\n"
254       "     http://paje.sourceforge.net/",
255       detailed);
256   print_line (OPT_TRACING_SMPI, "Trace the MPI Interface (SMPI)",
257       "  This option only has effect if this simulator is SMPI-based. Traces the MPI\n"
258       "  interface and generates a trace that can be analyzed using Gantt-like\n"
259       "  visualizations. Every MPI function (implemented by SMPI) is transformed in a\n"
260       "  state, and point-to-point communications can be analyzed with arrows.",
261       detailed);
262   print_line (OPT_TRACING_SMPI_GROUP, "Group MPI processes by host (SMPI)",
263       "  This option only has effect if this simulator is SMPI-based. The processes\n"
264       "  are grouped by the hosts where they were executed.",
265       detailed);
266   print_line (OPT_TRACING_MSG_TASK, "Trace task behavior (MSG)",
267       "  This option only has effect if this simulator is MSG-based. It traces the\n"
268       "  behavior of all categorized MSG tasks, grouping them by hosts.",
269       detailed);
270   print_line (OPT_TRACING_MSG_PROCESS, "Trace processes behavior (MSG)",
271       "  This option only has effect if this simulator is MSG-based. It traces the\n"
272       "  behavior of all categorized MSG processes, grouping them by hosts. This option\n"
273       "  can be used to track process location if this simulator has process migration.",
274       detailed);
275   print_line (OPT_TRACING_MSG_VOLUME, "Tracing of communication volume (MSG)",
276       "  This experimental option only has effect if this simulator is MSG-based.\n"
277       "  It traces the communication volume of MSG send/receive.",
278       detailed);
279   print_line (OPT_TRIVA_UNCAT_CONF, "Generate graph configuration for Triva",
280       "  This option can be used in all types of simulators build with SimGrid\n"
281       "  to generate a uncategorized resource utilization graph to be used as\n"
282       "  configuration for the Triva visualization analysis. This option\n"
283       "  can be used with tracing/categorized:1 and tracing:1 options to\n"
284       "  analyze an unmodified simulator before changing it to contain\n"
285       "  categories.",
286       detailed);
287   print_line (OPT_TRIVA_CAT_CONF, "generate uncategorized graph configuration for Triva",
288       "  This option can be used if this simulator uses tracing categories\n"
289       "  in its code. The file specified by this option holds a graph configuration\n"
290       "  file for the Triva visualization tool that can be used to analyze a categorized\n"
291       "  resource utilization.",
292       detailed);
293 }
294
295 void TRACE_generate_triva_uncat_conf (void)
296 {
297   char *output = TRACE_get_triva_uncat_conf ();
298   if (output && strlen(output) > 0){
299     FILE *file = fopen (output, "w");
300     if (!file){
301       THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
302              "Unable to open file (%s) for writing triva graph configuration (uncategorized).", output);
303     }
304     fprintf (file,
305         "{\n"
306         "  node = (HOST);\n"
307         "  edge = (LINK);\n"
308         "\n"
309         "  HOST = {\n"
310         "    size = power;\n"
311         "    scale = global;\n"
312         "    host_sep = {\n"
313         "      type = separation;\n"
314         "      size = power;\n"
315         "      values = (power_used);\n"
316         "    };\n"
317         "  };\n"
318         "  LINK = {\n"
319         "    src = source;\n"
320         "    dst = destination;\n"
321         "    size = bandwidth;\n"
322         "    scale = global;\n"
323         "    link_sep = {\n"
324         "      type = separation;\n"
325         "      size = bandwidth;\n"
326         "      values = (bandwidth_used);\n"
327         "    };\n"
328         "  };\n"
329         "  graphviz-algorithm = neato;\n"
330         "}\n"
331         );
332     fclose (file);
333   }
334 }
335
336 void TRACE_generate_triva_cat_conf (void)
337 {
338   char *output = TRACE_get_triva_cat_conf();
339   if (output && strlen(output) > 0){
340     //check if we do have categories declared
341     if (xbt_dict_length(created_categories) == 0){
342 //      INFO0("No categories declared, ignoring generation of triva graph configuration");
343       return;
344     }
345     xbt_dict_cursor_t cursor=NULL;
346     char *key, *data;
347     FILE *file = fopen (output, "w");
348     if (!file){
349       THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
350              "Unable to open file (%s) for writing triva graph configuration (categorized).", output);
351     }
352     fprintf (file,
353         "{\n"
354         "  node = (HOST);\n"
355         "  edge = (LINK);\n"
356         "\n"
357         "  HOST = {\n"
358         "    size = power;\n"
359         "    scale = global;\n"
360         "    host_sep = {\n"
361         "      type = separation;\n"
362         "      size = power;\n"
363         "      values = (");
364     xbt_dict_foreach(created_categories,cursor,key,data) {
365       fprintf(file, "p%s, ",key);
366     }
367     fprintf (file,
368         ");\n"
369         "    };\n"
370         "  };\n"
371         "  LINK = {\n"
372         "    src = source;\n"
373         "    dst = destination;\n"
374         "    size = bandwidth;\n"
375         "    scale = global;\n"
376         "    link_sep = {\n"
377         "      type = separation;\n"
378         "      size = bandwidth;\n"
379         "      values = (");
380     xbt_dict_foreach(created_categories,cursor,key,data) {
381       fprintf(file, "b%s, ",key);
382     }
383     fprintf (file,
384         ");\n"
385         "    };\n"
386         "  };\n"
387         "  graphviz-algorithm = neato;\n"
388         "}\n"
389         );
390     fclose(file);
391   }
392 }
393
394 #undef OPT_TRACING
395 #undef OPT_TRACING_SMPI
396 #undef OPT_TRACING_SMPI_GROUP
397 #undef OPT_TRACING_PLATFORM
398 #undef OPT_TRACING_UNCATEGORIZED
399 #undef OPT_TRACING_MSG_TASK
400 #undef OPT_TRACING_MSG_PROCESS
401 #undef OPT_TRACING_MSG_VOLUME
402 #undef OPT_TRACING_FILENAME
403 #undef OPT_TRACING_PLATFORM_METHOD
404 #undef OPT_TRIVA_UNCAT_CONF
405 #undef OPT_TRIVA_CAT_CONF
406
407 #endif /* HAVE_TRACING */