Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
49ff108b2da70c03251a1cd5048565727933dffc
[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 #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"
24
25 static int trace_configured = 0;
26 static int trace_active = 0;
27
28 extern xbt_dict_t created_categories; //declared in instr_interface.c
29
30 void TRACE_activate (void)
31 {
32   if (trace_active){
33     THROW0(tracing_error, TRACE_ERROR_ALREADY_ACTIVE,
34            "Tracing is already active.");
35   }
36   trace_active = 1;
37 }
38
39 void TRACE_desactivate (void)
40 {
41   trace_active = 0;
42 }
43
44 int TRACE_is_active (void)
45 {
46   return trace_active;
47 }
48
49 int TRACE_is_enabled(void)
50 {
51   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING);
52 }
53
54 int TRACE_is_configured(void)
55 {
56   return trace_configured;
57 }
58
59 int TRACE_smpi_is_enabled(void)
60 {
61   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI);
62 }
63
64 int TRACE_smpi_is_grouped(void)
65 {
66   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_SMPI_GROUP);
67 }
68
69 int TRACE_platform_is_enabled(void)
70 {
71   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_PLATFORM);
72 }
73
74 int TRACE_uncategorized (void)
75 {
76   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_UNCATEGORIZED);
77 }
78
79 int TRACE_msg_task_is_enabled(void)
80 {
81   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_TASK);
82 }
83
84 int TRACE_msg_process_is_enabled(void)
85 {
86   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_PROCESS);
87 }
88
89 int TRACE_msg_volume_is_enabled(void)
90 {
91   return xbt_cfg_get_int(_surf_cfg_set, OPT_TRACING_MSG_VOLUME);
92 }
93
94 char *TRACE_get_filename(void)
95 {
96   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_FILENAME);
97 }
98
99 char *TRACE_get_platform_method(void)
100 {
101   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRACING_PLATFORM_METHOD);
102 }
103
104 char *TRACE_get_triva_uncat_conf (void)
105 {
106   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_UNCAT_CONF);
107 }
108
109 char *TRACE_get_triva_cat_conf (void)
110 {
111   return xbt_cfg_get_string(_surf_cfg_set, OPT_TRIVA_CAT_CONF);
112 }
113
114 void TRACE_global_init(int *argc, char **argv)
115 {
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,
121                    NULL, NULL);
122
123   /* tracing */
124   int default_tracing = 0;
125   xbt_cfg_register(&_surf_cfg_set, OPT_TRACING,
126                    "Enable Tracing.",
127                    xbt_cfgelm_int, &default_tracing, 0, 1,
128                    NULL, NULL);
129
130   /* smpi */
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,
135                    NULL, NULL);
136
137   /* smpi grouped */
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,
142                    NULL, NULL);
143
144
145   /* platform */
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,
150                    NULL, NULL);
151
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,
157                    NULL, NULL);
158
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,
164                    1, NULL, NULL);
165
166   /* msg task */
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,
171                    NULL, NULL);
172
173   /* msg process */
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,
178                    NULL, NULL);
179
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,
185                    NULL, NULL);
186
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,
192                    NULL, NULL);
193
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,
199                    NULL, NULL);
200
201   /* instrumentation can be considered configured now */
202   trace_configured = 1;
203 }
204
205 static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)
206 {
207   char str[INSTR_DEFAULT_STR_SIZE];
208   snprintf (str, INSTR_DEFAULT_STR_SIZE, "--cfg=%s ", option);
209
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);
214   }
215 }
216
217 void TRACE_help (int detailed)
218 {
219   printf(
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.",
224       detailed);
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.",
228       detailed);
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"
232       "  traced.",
233       detailed);
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.",
245       detailed);
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/",
252       detailed);
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.",
258       detailed);
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.",
262       detailed);
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.",
266       detailed);
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.",
271       detailed);
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.",
275       detailed);
276 }
277
278 void TRACE_generate_triva_uncat_conf (void)
279 {
280   char *output = TRACE_get_triva_uncat_conf ();
281   if (output && strlen(output) > 0){
282     FILE *file = fopen (output, "w");
283     if (!file){
284       THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
285              "Unable to open file (%s) for writing triva graph configuration (uncategorized).", output);
286     }
287     fprintf (file,
288         "{\n"
289         "  node = (HOST);\n"
290         "  edge = (LINK);\n"
291         "\n"
292         "  HOST = {\n"
293         "    size = power;\n"
294         "    scale = global;\n"
295         "    host_sep = {\n"
296         "      type = separation;\n"
297         "      size = power;\n"
298         "      values = (power_used);\n"
299         "    };\n"
300         "  };\n"
301         "  LINK = {\n"
302         "    src = source;\n"
303         "    dst = destination;\n"
304         "    size = bandwidth;\n"
305         "    scale = global;\n"
306         "    link_sep = {\n"
307         "      type = separation;\n"
308         "      size = bandwidth;\n"
309         "      values = (bandwidth_used);\n"
310         "    };\n"
311         "  };\n"
312         "  graphviz-algorithm = neato;\n"
313         "}\n"
314         );
315     fclose (file);
316   }
317 }
318
319 void TRACE_generate_triva_cat_conf (void)
320 {
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");
326       return;
327     }
328     xbt_dict_cursor_t cursor=NULL;
329     char *key, *data;
330     FILE *file = fopen (output, "w");
331     if (!file){
332       THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
333              "Unable to open file (%s) for writing triva graph configuration (categorized).", output);
334     }
335     fprintf (file,
336         "{\n"
337         "  node = (HOST);\n"
338         "  edge = (LINK);\n"
339         "\n"
340         "  HOST = {\n"
341         "    size = power;\n"
342         "    scale = global;\n"
343         "    host_sep = {\n"
344         "      type = separation;\n"
345         "      size = power;\n"
346         "      values = (");
347     xbt_dict_foreach(created_categories,cursor,key,data) {
348       fprintf(file, "p%s, ",key);
349     }
350     fprintf (file,
351         ");\n"
352         "    };\n"
353         "  };\n"
354         "  LINK = {\n"
355         "    src = source;\n"
356         "    dst = destination;\n"
357         "    size = bandwidth;\n"
358         "    scale = global;\n"
359         "    link_sep = {\n"
360         "      type = separation;\n"
361         "      size = bandwidth;\n"
362         "      values = (");
363     xbt_dict_foreach(created_categories,cursor,key,data) {
364       fprintf(file, "b%s, ",key);
365     }
366     fprintf (file,
367         ");\n"
368         "    };\n"
369         "  };\n"
370         "  graphviz-algorithm = neato;\n"
371         "}\n"
372         );
373     fclose(file);
374   }
375 }
376
377 #undef OPT_TRACING
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
389
390 #endif /* HAVE_TRACING */