Skip to content

Commit 7a5e9c5

Browse files
authored
Merge pull request #10820 from gkatev/main_ompi_info_color
ompi_info color coding
2 parents b17c722 + 40abfa3 commit 7a5e9c5

File tree

9 files changed

+431
-46
lines changed

9 files changed

+431
-46
lines changed

opal/mca/base/mca_base_pvar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,8 @@ int mca_base_pvar_dump(int index, char ***out, mca_base_var_dump_type_t output_t
908908
if (NULL != pvar->enumerator) {
909909
char *values;
910910

911-
ret = pvar->enumerator->dump(pvar->enumerator, &values);
911+
ret = pvar->enumerator->dump(pvar->enumerator, &values,
912+
MCA_BASE_VAR_DUMP_TYPE_TO_ENUM_DUMP_TYPE(output_type));
912913
if (OPAL_SUCCESS == ret) {
913914
(void) opal_asprintf(out[0] + line++, "Values: %s", values);
914915
free(values);

opal/mca/base/mca_base_var.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* reserved.
2323
* Copyright (c) 2020 Google, LLC. All rights reserved.
2424
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
25+
* Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
26+
* Laboratory, ICS Forth. All rights reserved.
2527
* $COPYRIGHT$
2628
*
2729
* Additional copyrights may follow
@@ -49,6 +51,7 @@
4951
#include "opal/mca/installdirs/installdirs.h"
5052
#include "opal/mca/mca.h"
5153
#include "opal/runtime/opal.h"
54+
#include "opal/runtime/opal_params_core.h"
5255
#include "opal/util/argv.h"
5356
#include "opal/util/opal_environ.h"
5457
#include "opal/util/os_path.h"
@@ -713,7 +716,8 @@ static int var_set_from_string(mca_base_var_t *var, char *src)
713716
&& ((unsigned int) int_value != int_value))) {
714717
if (var->mbv_enumerator) {
715718
char *valid_values;
716-
(void) var->mbv_enumerator->dump(var->mbv_enumerator, &valid_values);
719+
(void) var->mbv_enumerator->dump(var->mbv_enumerator, &valid_values,
720+
MCA_BASE_VAR_ENUM_DUMP_READABLE);
717721
opal_show_help("help-mca-var.txt", "invalid-value-enum", true, var->mbv_full_name,
718722
src, valid_values);
719723
free(valid_values);
@@ -2190,7 +2194,11 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ
21902194
}
21912195

21922196
free(tmp);
2193-
} else if (MCA_BASE_VAR_DUMP_READABLE == output_type) {
2197+
} else if (MCA_BASE_VAR_DUMP_READABLE == output_type
2198+
|| MCA_BASE_VAR_DUMP_READABLE_COLOR == output_type) {
2199+
2200+
char *color_name = "", *color_value = "", *color_reset = "";
2201+
21942202
/* There will be at most three lines in the pretty print case */
21952203
*out = (char **) calloc(4, sizeof(char *));
21962204
if (NULL == *out) {
@@ -2199,10 +2207,18 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ
21992207
return OPAL_ERR_OUT_OF_RESOURCE;
22002208
}
22012209

2210+
if (MCA_BASE_VAR_DUMP_READABLE_COLOR == output_type) {
2211+
color_name = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VAR_NAME];
2212+
color_value = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VAR_VALUE];
2213+
color_reset = "\033[0m";
2214+
}
2215+
22022216
opal_asprintf(out[0],
2203-
"%s \"%s\" (current value: \"%s\", data source: %s, level: %d %s, type: %s",
2204-
VAR_IS_DEFAULT_ONLY(var[0]) ? "informational" : "parameter", full_name,
2205-
value_string, source_string, var->mbv_info_lvl + 1,
2217+
"%s %s\"%s\"%s (current value: %s\"%s\"%s, data source: %s, level: %d %s, type: %s",
2218+
VAR_IS_DEFAULT_ONLY(var[0]) ? "informational" : "parameter",
2219+
color_name, full_name, color_reset,
2220+
color_value, value_string, color_reset,
2221+
source_string, var->mbv_info_lvl + 1,
22062222
info_lvl_strings[var->mbv_info_lvl], ompi_var_type_names[var->mbv_type]);
22072223

22082224
tmp = out[0][0];
@@ -2250,7 +2266,8 @@ int mca_base_var_dump(int vari, char ***out, mca_base_var_dump_type_t output_typ
22502266
if (NULL != var->mbv_enumerator) {
22512267
char *values;
22522268

2253-
ret = var->mbv_enumerator->dump(var->mbv_enumerator, &values);
2269+
ret = var->mbv_enumerator->dump(var->mbv_enumerator, &values,
2270+
MCA_BASE_VAR_DUMP_TYPE_TO_ENUM_DUMP_TYPE(output_type));
22542271
if (OPAL_SUCCESS == ret) {
22552272
opal_asprintf(out[0] + line++, "Valid values: %s", values);
22562273
free(values);

opal/mca/base/mca_base_var.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1818
* Copyright (c) 2018 Triad National Security, LLC. All rights
1919
* reserved.
20+
* Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
21+
* Laboratory, ICS Forth. All rights reserved.
2022
* $COPYRIGHT$
2123
*
2224
* Additional copyrights may follow
@@ -699,7 +701,9 @@ typedef enum {
699701
/* Dump easily parsable strings */
700702
MCA_BASE_VAR_DUMP_PARSABLE = 1,
701703
/* Dump simple name=value string */
702-
MCA_BASE_VAR_DUMP_SIMPLE = 2
704+
MCA_BASE_VAR_DUMP_SIMPLE = 2,
705+
/* Dump human-readable strings, with color where supported */
706+
MCA_BASE_VAR_DUMP_READABLE_COLOR = 3
703707
} mca_base_var_dump_type_t;
704708

705709
/**

opal/mca/base/mca_base_var_enum.c

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2017-2022 IBM Corporation. All rights reserved.
1919
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
20+
* Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
21+
* Laboratory, ICS Forth. All rights reserved.
2022
* $COPYRIGHT$
2123
*
2224
* Additional copyrights may follow
@@ -46,7 +48,8 @@ static void mca_base_var_enum_flag_destructor(mca_base_var_enum_flag_t *enumerat
4648
static OBJ_CLASS_INSTANCE(mca_base_var_enum_flag_t, opal_object_t,
4749
mca_base_var_enum_flag_constructor, mca_base_var_enum_flag_destructor);
4850

49-
static int enum_dump(mca_base_var_enum_t *self, char **out);
51+
static int enum_dump(mca_base_var_enum_t *self, char **out,
52+
mca_base_var_enum_dump_type_t output_type);
5053
static int enum_get_count(mca_base_var_enum_t *self, int *count);
5154
static int enum_get_value(mca_base_var_enum_t *self, int index, int *value,
5255
const char **string_value);
@@ -109,10 +112,37 @@ static int mca_base_var_enum_bool_sfv(mca_base_var_enum_t *self, const int value
109112
return OPAL_SUCCESS;
110113
}
111114

112-
static int mca_base_var_enum_bool_dump(mca_base_var_enum_t *self, char **out)
115+
static int mca_base_var_enum_bool_dump(mca_base_var_enum_t *self, char **out,
116+
mca_base_var_enum_dump_type_t output_type)
113117
{
114-
*out = strdup("0: f|false|disabled|no|n, 1: t|true|enabled|yes|y");
115-
return *out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE;
118+
int ret;
119+
char *color_vv = "", *color_reset = "";
120+
121+
if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type) {
122+
color_vv = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VALID_VALUES];
123+
color_reset = "\033[0m";
124+
}
125+
126+
ret = opal_asprintf(out, "%s0%s|%sf%s|%sfalse%s|%sdisabled%s|%sno%s|%sn%s, "
127+
"%s1%s|%st%s|%strue%s|%senabled%s|%syes%s|%sy%s",
128+
color_vv, color_reset,
129+
color_vv, color_reset,
130+
color_vv, color_reset,
131+
color_vv, color_reset,
132+
color_vv, color_reset,
133+
color_vv, color_reset,
134+
color_vv, color_reset,
135+
color_vv, color_reset,
136+
color_vv, color_reset,
137+
color_vv, color_reset,
138+
color_vv, color_reset,
139+
color_vv, color_reset);
140+
if (ret < 0) {
141+
*out = NULL;
142+
return OPAL_ERR_OUT_OF_RESOURCE;
143+
}
144+
145+
return OPAL_SUCCESS;
116146
}
117147

118148
mca_base_var_enum_t mca_base_var_enum_bool = {.super = OPAL_OBJ_STATIC_INIT(opal_object_t),
@@ -199,10 +229,40 @@ static int mca_base_var_enum_auto_bool_sfv(mca_base_var_enum_t *self, const int
199229
return OPAL_SUCCESS;
200230
}
201231

202-
static int mca_base_var_enum_auto_bool_dump(mca_base_var_enum_t *self, char **out)
232+
static int mca_base_var_enum_auto_bool_dump(mca_base_var_enum_t *self, char **out,
233+
mca_base_var_enum_dump_type_t output_type)
203234
{
204-
*out = strdup("-1: auto, 0: f|false|disabled|no|n, 1: t|true|enabled|yes|y");
205-
return *out ? OPAL_SUCCESS : OPAL_ERR_OUT_OF_RESOURCE;
235+
int ret;
236+
char *color_vv = "", *color_reset = "";
237+
238+
if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type) {
239+
color_vv = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VALID_VALUES];
240+
color_reset = "\033[0m";
241+
}
242+
243+
ret = opal_asprintf(out, "%s-1%s|%sauto%s, "
244+
"%s0%s|%sf%s|%sfalse%s|%sdisabled%s|%sno%s|%sn%s, "
245+
"%s1%s|%st%s|%strue%s|%senabled%s|%syes%s|%sy%s",
246+
color_vv, color_reset,
247+
color_vv, color_reset,
248+
color_vv, color_reset,
249+
color_vv, color_reset,
250+
color_vv, color_reset,
251+
color_vv, color_reset,
252+
color_vv, color_reset,
253+
color_vv, color_reset,
254+
color_vv, color_reset,
255+
color_vv, color_reset,
256+
color_vv, color_reset,
257+
color_vv, color_reset,
258+
color_vv, color_reset,
259+
color_vv, color_reset);
260+
if (ret < 0) {
261+
*out = NULL;
262+
return OPAL_ERR_OUT_OF_RESOURCE;
263+
}
264+
265+
return OPAL_SUCCESS;
206266
}
207267

208268
mca_base_var_enum_t mca_base_var_enum_auto_bool
@@ -284,17 +344,27 @@ static int mca_base_var_enum_verbose_sfv(mca_base_var_enum_t *self, const int va
284344
return OPAL_SUCCESS;
285345
}
286346

287-
static int mca_base_var_enum_verbose_dump(mca_base_var_enum_t *self, char **out)
347+
static int mca_base_var_enum_verbose_dump(mca_base_var_enum_t *self, char **out,
348+
mca_base_var_enum_dump_type_t output_type)
288349
{
289350
char *tmp;
290351
int ret;
291352

292-
ret = enum_dump(self, out);
353+
char *color_vv = "", *color_reset = "";
354+
355+
ret = enum_dump(self, out, output_type);
293356
if (OPAL_SUCCESS != ret) {
294357
return ret;
295358
}
296359

297-
ret = opal_asprintf(&tmp, "%s, 0 - 100", *out);
360+
if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type) {
361+
color_vv = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VALID_VALUES];
362+
color_reset = "\033[0m";
363+
}
364+
365+
ret = opal_asprintf(&tmp, "%s, %s0%s-%s100%s", *out,
366+
color_vv, color_reset,
367+
color_vv, color_reset);
298368
free(*out);
299369
if (0 > ret) {
300370
*out = NULL;
@@ -408,22 +478,32 @@ int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_valu
408478
return OPAL_SUCCESS;
409479
}
410480

411-
static int enum_dump(mca_base_var_enum_t *self, char **out)
481+
static int enum_dump(mca_base_var_enum_t *self, char **out,
482+
mca_base_var_enum_dump_type_t output_type)
412483
{
413484
int i;
414485
char *tmp;
415486
int ret;
416487

488+
char *color_vv = "", *color_reset = "";
489+
417490
*out = NULL;
418491

419492
if (NULL == self) {
420493
return OPAL_ERROR;
421494
}
422495

496+
if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type) {
497+
color_vv = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VALID_VALUES];
498+
color_reset = "\033[0m";
499+
}
500+
423501
tmp = NULL;
424502
for (i = 0; i < self->enum_value_count && self->enum_values[i].string; ++i) {
425-
ret = opal_asprintf(out, "%s%s%d:\"%s\"", tmp ? tmp : "", tmp ? ", " : "",
426-
self->enum_values[i].value, self->enum_values[i].string);
503+
ret = opal_asprintf(out, "%s%s%s%d%s|%s%s%s",
504+
tmp ? tmp : "", tmp ? ", " : "",
505+
color_vv, self->enum_values[i].value, color_reset,
506+
color_vv, self->enum_values[i].string, color_reset);
427507
if (tmp) {
428508
free(tmp);
429509
}
@@ -691,18 +771,26 @@ static int enum_string_from_value_flag(mca_base_var_enum_t *self, const int valu
691771
return OPAL_SUCCESS;
692772
}
693773

694-
static int enum_dump_flag(mca_base_var_enum_t *self, char **out)
774+
static int enum_dump_flag(mca_base_var_enum_t *self, char **out,
775+
mca_base_var_enum_dump_type_t output_type)
695776
{
696777
mca_base_var_enum_flag_t *flag_enum = (mca_base_var_enum_flag_t *) self;
697778
char *tmp;
698779
int ret;
699780

781+
char *color_vv = "", *color_reset = "";
782+
700783
*out = NULL;
701784

702785
if (NULL == self) {
703786
return OPAL_ERROR;
704787
}
705788

789+
if (MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR == output_type) {
790+
color_vv = opal_var_dump_color[OPAL_VAR_DUMP_COLOR_VALID_VALUES];
791+
color_reset = "\033[0m";
792+
}
793+
706794
*out = strdup("Comma-delimited list of: ");
707795
if (NULL == *out) {
708796
return OPAL_ERR_OUT_OF_RESOURCE;
@@ -711,8 +799,10 @@ static int enum_dump_flag(mca_base_var_enum_t *self, char **out)
711799
for (int i = 0; i < self->enum_value_count; ++i) {
712800
tmp = *out;
713801

714-
ret = opal_asprintf(out, "%s%s0x%x:\"%s\"", tmp, i ? ", " : " ",
715-
flag_enum->enum_flags[i].flag, flag_enum->enum_flags[i].string);
802+
ret = opal_asprintf(out, "%s%s%s0x%x%s|%s%s%s",
803+
tmp, i ? ", " : " ",
804+
color_vv, flag_enum->enum_flags[i].flag, color_reset,
805+
color_vv, flag_enum->enum_flags[i].string, color_reset);
716806
free(tmp);
717807
if (0 > ret) {
718808
return OPAL_ERR_OUT_OF_RESOURCE;

opal/mca/base/mca_base_var_enum.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* reserved.
1616
* Copyright (c) 2017 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
18+
* Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
19+
* Laboratory, ICS Forth. All rights reserved.
1820
* $COPYRIGHT$
1921
*
2022
* Additional copyrights may follow
@@ -29,6 +31,21 @@
2931

3032
# include "opal/class/opal_object.h"
3133
# include "opal/constants.h"
34+
# include "opal/runtime/opal_params_core.h"
35+
36+
/* Output mode for dumping var enumerators.
37+
* Caution: Not 1:1 with mca_base_var_dump_type_t, appropriate
38+
* conversion is required, see MCA_BASE_VAR_DUMP_TYPE_TO_ENUM_DUMP_TYPE() */
39+
typedef enum {
40+
/* Dump human-readable strings */
41+
MCA_BASE_VAR_ENUM_DUMP_READABLE = 0,
42+
/* Dump human-readable strings, with color where supported */
43+
MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR = 1
44+
} mca_base_var_enum_dump_type_t;
45+
46+
#define MCA_BASE_VAR_DUMP_TYPE_TO_ENUM_DUMP_TYPE(var_dump_type) \
47+
(MCA_BASE_VAR_DUMP_READABLE_COLOR == (var_dump_type) ? \
48+
MCA_BASE_VAR_ENUM_DUMP_READABLE_COLOR : MCA_BASE_VAR_ENUM_DUMP_READABLE)
3249

3350
typedef struct mca_base_var_enum_t mca_base_var_enum_t;
3451

@@ -69,11 +86,13 @@ typedef int (*mca_base_var_enum_vfs_fn_t)(mca_base_var_enum_t *self, const char
6986
*
7087
* @param[in] self the enumerator
7188
* @param[out] out the string representation
89+
* @param[in] output_type the type of output desired
7290
*
7391
* @retval OPAL_SUCCESS on success
7492
* @retval opal error on error
7593
*/
76-
typedef int (*mca_base_var_enum_dump_fn_t)(mca_base_var_enum_t *self, char **out);
94+
typedef int (*mca_base_var_enum_dump_fn_t)(mca_base_var_enum_t *self, char **out,
95+
mca_base_var_enum_dump_type_t output_type);
7796

7897
/**
7998
* Get the string representation for an enumerator value

opal/runtime/help-opal-runtime.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# All rights reserved.
1313
# Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
1414
# Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
15+
# Copyright (c) 2022 Computer Architecture and VLSI Systems (CARV)
16+
# Laboratory, ICS Forth. All rights reserved.
1517
# $COPYRIGHT$
1618
#
1719
# Additional copyrights may follow
@@ -57,3 +59,13 @@ WARNING: Cannot set both the MCA parameters opal_leave_pinned (a.k.a.,
5759
mpi_leave_pinned) and opal_leave_pinned_pipeline (a.k.a.,
5860
mpi_leave_pinned_pipeline) to "true". Defaulting to mpi_leave_pinned
5961
ONLY.
62+
#
63+
[mpi-params:var_dump_color:format-error]
64+
WARNING: Token "%s" in opal_var_dump_color MCA parameter
65+
is not in the expected "key=value" format, ignoring.
66+
#
67+
[mpi-params:var_dump_color:unknown-key]
68+
WARNING: Key "%s" in opal_var_dump_color MCA parameter
69+
token "%s" is unknown, ignoring.
70+
71+
Valid keys are: %s

0 commit comments

Comments
 (0)