Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MALP_Config.c
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #include "MALP_Config.h"
20 #include "Utils.h"
21 
22 #include <stdlib.h>
23 
24 
26 
27 
28 //TA_Conf_entry
29 
30 void TA_Conf_entry_init( TA_Conf_key_t key, char *desc, TA_Conf_type type, char *value )
31 {
32 
33  if ( (TA_CONF_KEY_COUNT <= key ) ) {
34  printf("Bad entry key \n");
35  abort();
36  }
37 
38  struct TA_Conf_entry *entry = &TA_Conf_entries[key];
39 
40  strncpy( entry->desc, desc, 499);
41  entry->type = type;
42 
43  char empty[] = "";
44  if( !value )
45  value = empty;
46 
47 
48  if ( !TA_Conf_entry_update( entry, value ) ) {
49  printf("Wrong default config given \n");
50  abort();
51  }
52 
53 
54 }
55 
56 int TA_Conf_entry_update( struct TA_Conf_entry *entry, char *value )
57 {
58  if( (strlen(value) == 0) && entry->type != TA_CONF_STRING && entry->type != TA_CONF_NONE ) {
59  printf("this options awaits a value\n");
60  return 0;
61  }
62 
63  snprintf(entry->c_value, 200, "%s", value);
64 
65  if ( entry->type != TA_CONF_STRING && entry->type != TA_CONF_NONE ) {
66  if ( !MALP_Trace_is_numeric( value ) ) {
67  printf("Given entry ( %s ) is not numeric\n", value );
68  return 0;
69  }
70 
71  switch ( entry->type ) {
72  case TA_CONF_INT :
73  entry->i_value = atoi(value);
74  break;
75  case TA_CONF_DOUBLE :
76  entry->d_value = atof(value);
77  break;
78  case TA_CONF_BOOL :
79  entry->i_value = atoi(value);
80  break;
81  default :
82  printf("Unknown type \n");
83  abort();
84  }
85  } else {
86  entry->d_value = 0.0;
87  entry->i_value = 0;
88  }
89 
90  return 1;
91 }
92 
93 
94 //TA_Conf
102 static inline int TA_Conf_get_key_index( char *key_name )
103 {
104  int i = 0;
105 
106  for ( i = 0 ; i < TA_CONF_KEY_COUNT ; i++ ) {
107  if ( MALP_Trace_fast_strcmp( (char *)TA_Conf_key_lablel[i], key_name ) )
108  return i;
109 
110  }
111 
112  return -1;
113 }
114 
115 
116 int TA_Conf_update( char *key_name, char *val )
117 {
118 
119  int index = TA_Conf_get_key_index( key_name );
120 
121  if ( index < 0 )
122  return 0;
123 
124  struct TA_Conf_entry *entry = &TA_Conf_entries[index];
125 
126  return TA_Conf_entry_update( entry, val );
127 
128 }
129 
130 
132 {
133  int i;
134  for( i = 0 ; i < TA_CONF_KEY_COUNT ; i++ )
135  {
136  char * key = getenv( TA_Conf_key_lablel[i] );
137 
138  if( key )
139  {
140  printf("Overriding %s to %s from env \n", TA_Conf_key_lablel[i], key);
141  if ( !TA_Conf_update( TA_Conf_key_lablel[i], key ) )
142  {
143  printf("Warning env option for %s (%s) misformated \n", (char *)TA_Conf_key_lablel[i], key);
144  }
145  }
146 
147  }
148 }
149 
150 
151 
153 {
154  //GLOBAL CONFIG
156  "#############################################\n"
157  "# #\n"
158  "# GLOBAL CONFIGURATION #\n"
159  "# #\n"
160  "##############################################\n",
161  TA_CONF_NONE,
162  "" );
164  "Number of concurent worker threads per task (0 for core count)",
165  TA_CONF_INT,
166  "1" );
167  //VERBOSITY
169  "##############################################\n"
170  "# #\n"
171  "# ANALYZER VERBOSITY #\n"
172  "# #\n"
173  "##############################################\n",
174  TA_CONF_NONE,
175  "");
177  "Display MALP banner at program startup",
178  TA_CONF_BOOL,
179  "1" );
181  "Display blackboard's load to diagnose heavy load (useful for C++)",
182  TA_CONF_BOOL,
183  "0" );
185  "Activates debug messages during report generation",
186  TA_CONF_BOOL,
187  "0" );
188  //INSTRUMENTATION
189 
191  "##############################################\n"
192  "# #\n"
193  "# INSTRUMENTATION #\n"
194  "# #\n"
195  "##############################################\n",
196  TA_CONF_NONE,
197  "");
199  "Enable MPI calls instrumentation",
200  TA_CONF_BOOL,
201  "1" );
203  "Enable POSIX calls instrumentation",
204  TA_CONF_BOOL,
205  "0" );
207  "Activate to send MPI calls to the OTF trace",
208  TA_CONF_BOOL,
209  "1" );
211  "Activate to send POSIX calls to the OTF trace",
212  TA_CONF_BOOL,
213  "0" );
215  "Generate a complete posix profile (including untracked streams)",
216  TA_CONF_BOOL,
217  "1" );
219  "Dump a posix profile at program termination (Works for non MPI programs)",
220  TA_CONF_BOOL,
221  "0" );
222  //SAMPLE ANALYSIS
224  "#############################################\n"
225  "# #\n"
226  "# SAMPLE ANALYSIS #\n"
227  "# #\n"
228  "##############################################\n",
229  TA_CONF_NONE,
230  "" );
232  "Enable Sample Analysis (TEST MODULE ONLY)",
233  TA_CONF_BOOL,
234  "0" );
235  //OTF2 ANALYSIS
237  "#############################################\n"
238  "# #\n"
239  "# OTF2 ANALYSIS #\n"
240  "# #\n"
241  "##############################################\n",
242  TA_CONF_NONE,
243  "" );
245  "Enable OTF2 Analysis",
246  TA_CONF_BOOL,
247  "0" );
249  "Path to otf2 trace",
251  "./otf2/" );
253  "Name of otf2 trace file",
255  "malp_output" );
256 
257 }
258 
259 
260 
261 
262 void TA_Conf_dump( char *dest )
263 {
264  FILE *conf = fopen( dest, "w" );
265 
266  if ( !conf ) {
267  printf("Failed to open config file for write (%s)\n", dest);
268  return;
269  }
270 
271  int i = 0;
272 
273  for (i = 0; i < TA_CONF_KEY_COUNT; i++) {
274  fprintf(conf, "\n#%s\n", TA_Conf_entries[i].desc );
275  if ( TA_Conf_entries[i].type != TA_CONF_NONE ) {
276  fprintf(conf, "%s %s\n", TA_Conf_key_lablel[i], TA_Conf_entries[i].c_value );
277  }
278 
279  }
280 
281  fclose(conf);
282 }
283 
284 
285 void TA_Conf_load( char *source )
286 {
287  FILE *file = fopen( source , "r" );
288 
289  if (!file) {
290  //printf("INFO : Could NOT open config file, ignoring\n");
291  return;
292  }
293 
294 
295  char linebuff[1500];
296  char name_buff[500];
297  char val_buff[1000];
298 
299  int line_count = 1;
300 
301 
302  while ( fgets( linebuff, 500, file) ) {
303  int ret = 0;
304  linebuff[strlen(linebuff) - 1] = '\0'; //strip the \n
305 
306  if ( !MALP_Trace_line_begins_with_sharp(linebuff) ) {
307  if ( (ret =sscanf( linebuff, "%s %1000[^\n]s", name_buff, val_buff)) == 2 ) {
308  if ( !TA_Conf_update( name_buff, val_buff ) ) {
309  printf("Warning @ line %d : %s \n", line_count, linebuff);
310  }
311  }
312 
313  if( ret == 1 ) {
314  //Allows empty update ( for strings )
315  if ( (sscanf( linebuff, "%s", name_buff) == 1 ) ) {
316  if ( !TA_Conf_update( name_buff, "" ) ) {
317  printf("Warning @ line %d : %s \n", line_count, linebuff);
318  }
319  }
320 
321  }
322 
323 
324  if ( ret == 0 )
325  perror("Error parsing line");
326 
327 
328  }
329  line_count++;
330  }
331 
332  fclose( file );
333 }
static const char *const TA_Conf_key_lablel[TA_CONF_KEY_COUNT]
Definition: MALP_Config.h:71
TA_Conf_type
Possible types for the Analyzer configuration parameter values.
Definition: MALP_Config.h:110
void TA_Conf_load(char *source)
Load and use a file to set the Analyzer configuration.
Definition: MALP_Config.c:285
void TA_Conf_dump(char *dest)
Save the Analyzer_ configuration in the destination file in argument.
Definition: MALP_Config.c:262
TA_Conf_type type
Type of a configuration parameter value.
Definition: MALP_Config.h:125
int TA_Conf_entry_update(struct TA_Conf_entry *entry, char *value)
Update the value for a configuration parameter after control of the value's content and type...
Definition: MALP_Config.c:56
No defined type.
Definition: MALP_Config.h:111
void TA_Conf_init_default()
Initialisation of the Trace_Collector with default options.
Definition: MALP_Config.c:152
Boolean.
Definition: MALP_Config.h:113
void TA_Conf_entry_init(TA_Conf_key_t key, char *desc, TA_Conf_type type, char *value)
Initialisation of the Analyzer configuration parameter's type, description and value.
Definition: MALP_Config.c:30
struct TA_Conf_entry TA_Conf_entries[TA_CONF_KEY_COUNT]
Definition: MALP_Config.c:25
char desc[500]
Descriptor of a configuration parameter.
Definition: MALP_Config.h:124
void TA_Conf_init_from_env()
Initialisation of config from environment.
Definition: MALP_Config.c:131
static int MALP_Trace_line_begins_with_sharp(char *line)
Checks if the first not space char of a string is a #.
Definition: Utils.h:129
Define a configuration entry structure, which contain a descritpion buffer, the entry type and variab...
Definition: MALP_Config.h:123
static int TA_Conf_get_key_index(char *key_name)
Return the index of a key name in list of Analyser configuration keys ( TA_Conf_key_t ) ...
Definition: MALP_Config.c:102
static int MALP_Trace_is_numeric(char *number)
Checks if a string contains a numerical element.
Definition: Utils.h:113
int i_value
integer variable for the configuration parameter value
Definition: MALP_Config.h:130
char c_value[1000]
char* buffer for the configuration parameter value
Definition: MALP_Config.h:128
static int MALP_Trace_fast_strcmp(char *haystack, char *needle)
Fast string comparison.
Definition: Utils.h:89
TA_Conf_key_t
Enumeration of the configuration parameter keys for MALP.
Definition: MALP_Config.h:32
Integer.
Definition: MALP_Config.h:112
int TA_Conf_update(char *key_name, char *val)
Update the value for a configuration option with control of the value name.
Definition: MALP_Config.c:116
float d_value
float variable for the configuration parameter value
Definition: MALP_Config.h:129