Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit abedcad

Browse files
committed
mca/base: standize MCA verbosity levels
Up until this point we have had inconsistent usage for MCA verbosity levels. This commit attempts to correct this by recommending components use these standard levels: none (-1), error (0), component (10), warn (20), info (40), trace (60), debug (80), and max (100). master commit open-mpi/ompi@8cbf743 Signed-off-by: Nathan Hjelm <[email protected]>
1 parent b672e5c commit abedcad

File tree

5 files changed

+158
-9
lines changed

5 files changed

+158
-9
lines changed

opal/mca/base/base.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* $COPYRIGHT$
1717
*
@@ -69,6 +69,30 @@ OPAL_DECLSPEC extern bool mca_base_component_disable_dlopen;
6969
OPAL_DECLSPEC extern char *mca_base_system_default_path;
7070
OPAL_DECLSPEC extern char *mca_base_user_default_path;
7171

72+
/*
73+
* Standard verbosity levels
74+
*/
75+
enum {
76+
/** total silence */
77+
MCA_BASE_VERBOSE_NONE = -1,
78+
/** only errors are printed */
79+
MCA_BASE_VERBOSE_ERROR = 0,
80+
/** emit messages about component selection, open, and unloading */
81+
MCA_BASE_VERBOSE_COMPONENT = 10,
82+
/** also emit warnings */
83+
MCA_BASE_VERBOSE_WARN = 20,
84+
/** also emit general, user-relevant information, such as rationale as to why certain choices
85+
* or code paths were taken, information gleaned from probing the local system, etc. */
86+
MCA_BASE_VERBOSE_INFO = 40,
87+
/** also emit relevant tracing information (e.g., which functions were invoked /
88+
* call stack entry/exit info) */
89+
MCA_BASE_VERBOSE_TRACE = 60,
90+
/** also emit Open MPI-developer-level (i.e,. highly detailed) information */
91+
MCA_BASE_VERBOSE_DEBUG = 80,
92+
/** also output anything else that might be useful */
93+
MCA_BASE_VERBOSE_MAX = 100,
94+
};
95+
7296
/*
7397
* Public functions
7498
*/

opal/mca/base/mca_base_framework.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ int mca_base_framework_register (struct mca_base_framework_t *framework,
9292
}
9393

9494
/* register a verbosity variable for this framework */
95-
asprintf (&desc, "Verbosity level for the %s framework (0 = no verbosity)",
96-
framework->framework_name);
95+
ret = asprintf (&desc, "Verbosity level for the %s framework (default: 0)",
96+
framework->framework_name);
97+
if (0 > ret) {
98+
return OPAL_ERR_OUT_OF_RESOURCE;
99+
}
100+
101+
framework->framework_verbose = MCA_BASE_VERBOSE_ERROR;
97102
ret = mca_base_framework_var_register (framework, "verbose", desc,
98-
MCA_BASE_VAR_TYPE_INT, NULL, 0,
103+
MCA_BASE_VAR_TYPE_INT,
104+
&mca_base_var_enum_verbose, 0,
99105
MCA_BASE_VAR_FLAG_SETTABLE,
100106
OPAL_INFO_LVL_8,
101107
MCA_BASE_VAR_SCOPE_LOCAL,

opal/mca/base/mca_base_var.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ int mca_base_var_deregister(int vari)
852852
var->mbv_storage->stringval) {
853853
free (var->mbv_storage->stringval);
854854
var->mbv_storage->stringval = NULL;
855-
} else if (MCA_BASE_VAR_TYPE_BOOL != var->mbv_type && NULL != var->mbv_enumerator) {
855+
} else if (var->mbv_enumerator && !var->mbv_enumerator->enum_is_static) {
856856
OBJ_RELEASE(var->mbv_enumerator);
857857
}
858858

@@ -1486,7 +1486,9 @@ static int register_variable (const char *project_name, const char *framework_na
14861486
OBJ_RELEASE (var->mbv_enumerator);
14871487
}
14881488

1489-
OBJ_RETAIN(enumerator);
1489+
if (!enumerator->enum_is_static) {
1490+
OBJ_RETAIN(enumerator);
1491+
}
14901492
}
14911493

14921494
var->mbv_enumerator = enumerator;
@@ -1847,7 +1849,7 @@ static void var_destructor(mca_base_var_t *var)
18471849
}
18481850

18491851
/* don't release the boolean enumerator */
1850-
if (MCA_BASE_VAR_TYPE_BOOL != var->mbv_type && NULL != var->mbv_enumerator) {
1852+
if (var->mbv_enumerator && !var->mbv_enumerator->enum_is_static) {
18511853
OBJ_RELEASE(var->mbv_enumerator);
18521854
}
18531855

@@ -1860,6 +1862,7 @@ static void var_destructor(mca_base_var_t *var)
18601862
if (NULL != var->mbv_long_name) {
18611863
free(var->mbv_long_name);
18621864
}
1865+
18631866
if (NULL != var->mbv_description) {
18641867
free(var->mbv_description);
18651868
}

opal/mca/base/mca_base_var_enum.c

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2008-2013 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2012-2014 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* $COPYRIGHT$
1717
*
@@ -23,6 +23,7 @@
2323
#include "opal_config.h"
2424

2525
#include "opal/mca/base/mca_base_var_enum.h"
26+
#include "opal/mca/base/base.h"
2627

2728
#include <stdio.h>
2829
#include <string.h>
@@ -33,6 +34,10 @@ static void mca_base_var_enum_destructor (mca_base_var_enum_t *enumerator);
3334
OBJ_CLASS_INSTANCE(mca_base_var_enum_t, opal_object_t, mca_base_var_enum_constructor,
3435
mca_base_var_enum_destructor);
3536

37+
static int enum_dump (mca_base_var_enum_t *self, char **out);
38+
static int enum_get_count (mca_base_var_enum_t *self, int *count);
39+
static int enum_get_value (mca_base_var_enum_t *self, int index, int *value, const char **string_value);
40+
3641
static int mca_base_var_enum_bool_get_count (mca_base_var_enum_t *enumerator, int *count)
3742
{
3843
*count = 2;
@@ -97,6 +102,7 @@ static int mca_base_var_enum_bool_dump (mca_base_var_enum_t *self, char **out)
97102

98103
mca_base_var_enum_t mca_base_var_enum_bool = {
99104
.super = OPAL_OBJ_STATIC_INIT(opal_object_t),
105+
.enum_is_static = true,
100106
.enum_name = "boolean",
101107
.get_count = mca_base_var_enum_bool_get_count,
102108
.get_value = mca_base_var_enum_bool_get_value,
@@ -105,6 +111,108 @@ mca_base_var_enum_t mca_base_var_enum_bool = {
105111
.dump = mca_base_var_enum_bool_dump
106112
};
107113

114+
/* verbosity enumerator */
115+
static mca_base_var_enum_value_t verbose_values[] = {
116+
{MCA_BASE_VERBOSE_NONE, "none"},
117+
{MCA_BASE_VERBOSE_ERROR, "error"},
118+
{MCA_BASE_VERBOSE_COMPONENT, "component"},
119+
{MCA_BASE_VERBOSE_WARN, "warn"},
120+
{MCA_BASE_VERBOSE_INFO, "info"},
121+
{MCA_BASE_VERBOSE_TRACE, "trace"},
122+
{MCA_BASE_VERBOSE_DEBUG, "debug"},
123+
{MCA_BASE_VERBOSE_MAX, "max"},
124+
{-1, NULL}
125+
};
126+
127+
static int mca_base_var_enum_verbose_vfs (mca_base_var_enum_t *self, const char *string_value,
128+
int *value)
129+
{
130+
char *tmp;
131+
int v;
132+
133+
/* skip whitespace */
134+
string_value += strspn (string_value, " \t\n\v\f\r");
135+
136+
v = strtol (string_value, &tmp, 10);
137+
if (*tmp != '\0') {
138+
for (int i = 0 ; verbose_values[i].string ; ++i) {
139+
if (0 == strcmp (verbose_values[i].string, string_value)) {
140+
*value = verbose_values[i].value;
141+
return OPAL_SUCCESS;
142+
}
143+
}
144+
145+
return OPAL_ERR_NOT_FOUND;
146+
} else if (v < MCA_BASE_VERBOSE_NONE) {
147+
v = MCA_BASE_VERBOSE_NONE;
148+
} else if (v > MCA_BASE_VERBOSE_MAX) {
149+
v = MCA_BASE_VERBOSE_MAX;
150+
}
151+
152+
*value = v;
153+
154+
return OPAL_SUCCESS;
155+
}
156+
157+
static int mca_base_var_enum_verbose_sfv (mca_base_var_enum_t *self, const int value,
158+
const char **string_value)
159+
{
160+
static char buffer[4];
161+
162+
if (value < 0 || value > 100) {
163+
return OPAL_ERR_VALUE_OUT_OF_BOUNDS;
164+
}
165+
166+
for (int i = 0 ; verbose_values[i].string ; ++i) {
167+
if (verbose_values[i].value == value) {
168+
*string_value = verbose_values[i].string;
169+
return OPAL_SUCCESS;
170+
}
171+
}
172+
173+
snprintf (buffer, 4, "%d", value);
174+
if (string_value) {
175+
*string_value = buffer;
176+
}
177+
178+
return OPAL_SUCCESS;
179+
}
180+
181+
static int mca_base_var_enum_verbose_dump (mca_base_var_enum_t *self, char **out)
182+
{
183+
char *tmp;
184+
int ret;
185+
186+
ret = enum_dump (self, out);
187+
if (OPAL_SUCCESS != ret) {
188+
return ret;
189+
}
190+
191+
ret = asprintf (&tmp, "%s, 0 - 100", *out);
192+
free (*out);
193+
if (0 > ret) {
194+
*out = NULL;
195+
return OPAL_ERR_OUT_OF_RESOURCE;
196+
}
197+
198+
*out = tmp;
199+
200+
return OPAL_SUCCESS;
201+
}
202+
203+
mca_base_var_enum_t mca_base_var_enum_verbose = {
204+
.super = OPAL_OBJ_STATIC_INIT(opal_object_t),
205+
.enum_is_static = true,
206+
.enum_name = "verbosity",
207+
.get_count = enum_get_count,
208+
.get_value = enum_get_value,
209+
.value_from_string = mca_base_var_enum_verbose_vfs,
210+
.string_from_value = mca_base_var_enum_verbose_sfv,
211+
.dump = mca_base_var_enum_verbose_dump,
212+
.enum_value_count = 8,
213+
.enum_values = verbose_values,
214+
};
215+
108216

109217
int mca_base_var_enum_create (const char *name, const mca_base_var_enum_value_t *values, mca_base_var_enum_t **enumerator)
110218
{
@@ -264,6 +372,7 @@ static void mca_base_var_enum_constructor (mca_base_var_enum_t *enumerator)
264372
enumerator->value_from_string = enum_value_from_string;
265373
enumerator->string_from_value = enum_string_from_value;
266374
enumerator->dump = enum_dump;
375+
enumerator->enum_is_static = false;
267376
}
268377

269378
static void mca_base_var_enum_destructor (mca_base_var_enum_t *enumerator)

opal/mca/base/mca_base_var_enum.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2008-2011 Cisco Systems, Inc. All rights reserved.
14-
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* $COPYRIGHT$
1717
*
@@ -106,6 +106,9 @@ typedef struct mca_base_var_enum_value_t mca_base_var_enum_value_t;
106106
struct mca_base_var_enum_t {
107107
opal_object_t super;
108108

109+
/** Is the enumerator statically allocated */
110+
bool enum_is_static;
111+
109112
/** Name of this enumerator. This value is duplicated from the argument provided to
110113
mca_base_var_enum_create() */
111114
char *enum_name;
@@ -176,5 +179,9 @@ OPAL_DECLSPEC int mca_base_var_enum_create (const char *name, const mca_base_var
176179
*/
177180
extern mca_base_var_enum_t mca_base_var_enum_bool;
178181

182+
/**
183+
* Verbosity level enumerator
184+
*/
185+
extern mca_base_var_enum_t mca_base_var_enum_verbose;
179186

180187
#endif /* !defined(MCA_BASE_VAR_ENUM_H) */

0 commit comments

Comments
 (0)