Skip to content

Commit c208f47

Browse files
authored
Merge pull request #10469 from ColinNV/enhance_ucx_info
TOOLS/INFO: Optional name filter for config dump
2 parents 52026fd + ea1c395 commit c208f47

File tree

8 files changed

+122
-76
lines changed

8 files changed

+122
-76
lines changed

AUTHORS

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Bin Lei <[email protected]>
1818
Boris Karasev <[email protected]>
1919
Brad Benton <[email protected]>
2020
Changcheng Liu <[email protected]>
21+
Colin Hirsch <[email protected]>
2122
Corey J. Nolet <[email protected]>
2223
David Wootton <[email protected]>
2324
Devendar Bureddy <[email protected]>
@@ -121,9 +122,9 @@ Christophe Harle
121122
Christopher Lamb
122123
Craig Stunkel
123124
Cydney Ewald Stevens
124-
Davide Rossetti
125+
Davide Rossetti
125126
Donald Becker
126-
Duncan Poole
127+
Duncan Poole
127128
Edgar A. Leon
128129
Eric Van Hensbergen
129130
Geoffrey Blake
@@ -137,7 +138,7 @@ Liran Liss
137138
Nathaniel Graham
138139
Oscar Hernandez
139140
Pavan Balaji
140-
Richard Graham
141+
Richard Graham
141142
Ron Brightwell
142143
Sameer Kumar
143144
Sameh Sharkawi

src/tools/info/ucx_info.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static void usage()
5858
printf(" -s Show system information\n");
5959
printf(" -c Show UCX configuration\n");
6060
printf(" -C Comment-out default configuration values\n");
61+
printf(" -F <string> Only show configuration values whose name "
62+
"contains 'string'\n");
6163
printf(" -a Show also hidden configuration\n");
6264
printf(" -f Display fully decorated output\n");
6365
printf("\nUCP information (-u is required):\n");
@@ -122,6 +124,7 @@ int main(int argc, char **argv)
122124
size_t ucp_num_ppn;
123125
unsigned print_opts;
124126
char *tl_name, *mem_spec;
127+
const char *cfg_filter;
125128
const char *f;
126129
int c;
127130

@@ -132,12 +135,14 @@ int main(int argc, char **argv)
132135
ucp_num_eps = 1;
133136
ucp_num_ppn = 1;
134137
mem_spec = NULL;
138+
cfg_filter = NULL;
135139
dev_type_bitmap = UINT_MAX;
136140
proc_placement = PROCESS_PLACEMENT_SELF;
137141
ucp_ep_params.field_mask = 0;
138142
ip_addr_family = AF_INET;
139143

140-
while ((c = getopt(argc, argv, "fahvc6ydbswpeCt:n:u:D:P:m:N:A:TM")) != -1) {
144+
while ((c = getopt(argc, argv, "fahvc6ydbswpeCF:t:n:u:D:P:m:N:A:TM")) !=
145+
-1) {
141146
switch (c) {
142147
case 'f':
143148
print_flags |= UCS_CONFIG_PRINT_CONFIG | UCS_CONFIG_PRINT_HEADER | UCS_CONFIG_PRINT_DOC;
@@ -151,6 +156,9 @@ int main(int argc, char **argv)
151156
case 'C':
152157
print_flags |= UCS_CONFIG_PRINT_COMMENT_DEFAULT;
153158
break;
159+
case 'F':
160+
cfg_filter = optarg;
161+
break;
154162
case 'v':
155163
print_opts |= PRINT_VERSION;
156164
break;
@@ -304,7 +312,8 @@ int main(int argc, char **argv)
304312

305313
if (print_flags & UCS_CONFIG_PRINT_CONFIG) {
306314
ucs_config_parser_print_all_opts(stdout, UCS_DEFAULT_ENV_PREFIX,
307-
print_flags, &ucs_config_global_list);
315+
print_flags, &ucs_config_global_list,
316+
cfg_filter);
308317
}
309318

310319
if (print_opts & (PRINT_UCP_CONTEXT|PRINT_UCP_WORKER|PRINT_UCP_EP|PRINT_MEM_MAP)) {

src/ucp/core/ucp_context.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ void ucp_config_print_cached_uct(const ucp_config_t *config, FILE *stream,
869869
void ucp_config_print(const ucp_config_t *config, FILE *stream,
870870
const char *title, ucs_config_print_flags_t print_flags)
871871
{
872-
ucs_config_parser_print_opts(stream, title, config, ucp_config_table,
873-
NULL, UCS_DEFAULT_ENV_PREFIX, print_flags);
872+
ucs_config_parser_print_opts(stream, title, config, ucp_config_table, NULL,
873+
UCS_DEFAULT_ENV_PREFIX, print_flags, NULL);
874874
ucp_config_print_cached_uct(config, stream, title, print_flags);
875875
}
876876

src/ucs/config/global_opts.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,12 @@ void ucs_global_opts_print(FILE *stream, ucs_config_print_flags_t print_flags)
413413
{
414414
ucs_config_parser_print_opts(stream, "Global configuration",
415415
&ucs_global_opts, ucs_global_opts_table, NULL,
416-
UCS_DEFAULT_ENV_PREFIX, print_flags);
416+
UCS_DEFAULT_ENV_PREFIX, print_flags, NULL);
417417
ucs_config_parser_print_opts(stream,
418418
"Global configuration (runtime read-only)",
419419
&ucs_global_opts,
420420
ucs_global_opts_read_only_table, NULL,
421-
UCS_DEFAULT_ENV_PREFIX, print_flags);
421+
UCS_DEFAULT_ENV_PREFIX, print_flags, NULL);
422422
}
423423

424424
static void ucs_vfs_read_log_level(void *obj, ucs_string_buffer_t *strb,

src/ucs/config/parser.c

+69-55
Original file line numberDiff line numberDiff line change
@@ -2012,12 +2012,21 @@ static int ucs_config_parser_is_default(const char *env_prefix,
20122012
(getenv(var_name) == NULL);
20132013
}
20142014

2015-
static void
2016-
ucs_config_parser_print_field(FILE *stream, const void *opts, const char *env_prefix,
2017-
ucs_list_link_t *prefix_list, const char *name,
2018-
const ucs_config_field_t *field, unsigned long flags,
2019-
const char *docstr, ...)
2015+
static void ucs_config_parser_print_header(FILE *stream, const char *title)
20202016
{
2017+
fprintf(stream, "#\n");
2018+
fprintf(stream, "# %s\n", title);
2019+
fprintf(stream, "#\n");
2020+
fprintf(stream, "\n");
2021+
}
2022+
2023+
static void ucs_config_parser_print_field(
2024+
FILE *stream, const void *opts, const char *env_prefix,
2025+
ucs_list_link_t *prefix_list, const char *name,
2026+
const ucs_config_field_t *field, ucs_config_print_flags_t *flags_p,
2027+
const char *title, const char *filter, const char *docstr, ...)
2028+
{
2029+
char name_buf[128] = {0};
20212030
char value_buf[128] = {0};
20222031
char syntax_buf[256] = {0};
20232032
ucs_config_parser_prefix_t *prefix, *head;
@@ -2027,6 +2036,19 @@ ucs_config_parser_print_field(FILE *stream, const void *opts, const char *env_pr
20272036
ucs_assert(!ucs_list_is_empty(prefix_list));
20282037
head = ucs_list_head(prefix_list, ucs_config_parser_prefix_t, list);
20292038

2039+
snprintf(name_buf, sizeof(name_buf), "%s%s%s", env_prefix, head->prefix,
2040+
name);
2041+
2042+
/* Apply optional filter from -F command line argument. */
2043+
if ((filter != NULL) && (strstr(name_buf, filter) == NULL)) {
2044+
return;
2045+
}
2046+
2047+
if (*flags_p & UCS_CONFIG_PRINT_HEADER) {
2048+
*flags_p &= ~UCS_CONFIG_PRINT_HEADER;
2049+
ucs_config_parser_print_header(stream, title);
2050+
}
2051+
20302052
if (ucs_config_is_deprecated_field(field)) {
20312053
snprintf(value_buf, sizeof(value_buf), " (deprecated)");
20322054
snprintf(syntax_buf, sizeof(syntax_buf), "N/A");
@@ -2038,14 +2060,14 @@ ucs_config_parser_print_field(FILE *stream, const void *opts, const char *env_pr
20382060
field->parser.help(syntax_buf, sizeof(syntax_buf) - 1, field->parser.arg);
20392061
}
20402062

2041-
if ((flags & UCS_CONFIG_PRINT_COMMENT_DEFAULT) &&
2063+
if ((*flags_p & UCS_CONFIG_PRINT_COMMENT_DEFAULT) &&
20422064
ucs_config_parser_is_default(env_prefix, head->prefix, name)) {
20432065
default_config_prefix = "# ";
20442066
} else {
20452067
default_config_prefix = "";
20462068
}
20472069

2048-
if (flags & UCS_CONFIG_PRINT_DOC) {
2070+
if (*flags_p & UCS_CONFIG_PRINT_DOC) {
20492071
fprintf(stream, "#\n");
20502072
ucs_config_print_doc_line_by_line(field, __print_stream_cb, stream);
20512073
fprintf(stream, "#\n");
@@ -2080,19 +2102,17 @@ ucs_config_parser_print_field(FILE *stream, const void *opts, const char *env_pr
20802102
fprintf(stream, "#\n");
20812103
}
20822104

2083-
fprintf(stream, "%s%s%s%s%s\n", default_config_prefix, env_prefix,
2084-
head->prefix, name, value_buf);
2105+
fprintf(stream, "%s%s%s\n", default_config_prefix, name_buf, value_buf);
20852106

2086-
if (flags & UCS_CONFIG_PRINT_DOC) {
2107+
if (*flags_p & UCS_CONFIG_PRINT_DOC) {
20872108
fprintf(stream, "\n");
20882109
}
20892110
}
20902111

2091-
static void
2092-
ucs_config_parser_print_opts_recurs(FILE *stream, const void *opts,
2093-
const ucs_config_field_t *fields,
2094-
unsigned flags, const char *prefix,
2095-
ucs_list_link_t *prefix_list)
2112+
static void ucs_config_parser_print_opts_recurs(
2113+
FILE *stream, const void *opts, const ucs_config_field_t *fields,
2114+
ucs_config_print_flags_t *flags_p, const char *prefix,
2115+
ucs_list_link_t *prefix_list, const char *title, const char *filter)
20962116
{
20972117
const ucs_config_field_t *field, *aliased_field;
20982118
ucs_config_parser_prefix_t *head;
@@ -2119,16 +2139,16 @@ ucs_config_parser_print_opts_recurs(FILE *stream, const void *opts,
21192139
inner_prefix.prefix = NULL;
21202140
}
21212141

2122-
ucs_config_parser_print_opts_recurs(stream,
2123-
UCS_PTR_BYTE_OFFSET(opts, field->offset),
2124-
field->parser.arg, flags,
2125-
prefix, prefix_list);
2142+
ucs_config_parser_print_opts_recurs(
2143+
stream, UCS_PTR_BYTE_OFFSET(opts, field->offset),
2144+
field->parser.arg, flags_p, prefix, prefix_list, title,
2145+
filter);
21262146

21272147
if (inner_prefix.prefix != NULL) {
21282148
ucs_list_del(&inner_prefix.list);
21292149
}
21302150
} else if (ucs_config_is_alias_field(field)) {
2131-
if (flags & UCS_CONFIG_PRINT_HIDDEN) {
2151+
if (*flags_p & UCS_CONFIG_PRINT_HIDDEN) {
21322152
aliased_field =
21332153
ucs_config_find_aliased_field(fields, field,
21342154
&alias_table_offset);
@@ -2138,68 +2158,62 @@ ucs_config_parser_print_opts_recurs(FILE *stream, const void *opts,
21382158

21392159
head = ucs_list_head(prefix_list, ucs_config_parser_prefix_t, list);
21402160

2141-
ucs_config_parser_print_field(stream,
2142-
UCS_PTR_BYTE_OFFSET(opts, alias_table_offset),
2143-
prefix, prefix_list,
2144-
field->name, aliased_field,
2145-
flags, "%-*s %s%s%s",
2146-
UCS_CONFIG_PARSER_DOCSTR_WIDTH,
2147-
"alias of:", prefix,
2148-
head->prefix,
2149-
aliased_field->name);
2161+
ucs_config_parser_print_field(
2162+
stream, UCS_PTR_BYTE_OFFSET(opts, alias_table_offset),
2163+
prefix, prefix_list, field->name, aliased_field,
2164+
flags_p, title, filter, "%-*s %s%s%s",
2165+
UCS_CONFIG_PARSER_DOCSTR_WIDTH, "alias of:", prefix,
2166+
head->prefix, aliased_field->name);
21502167
}
21512168
} else {
21522169
if (ucs_config_is_deprecated_field(field) &&
2153-
!(flags & UCS_CONFIG_PRINT_HIDDEN)) {
2170+
!(*flags_p & UCS_CONFIG_PRINT_HIDDEN)) {
21542171
continue;
21552172
}
21562173
ucs_config_parser_print_field(stream, opts, prefix, prefix_list,
2157-
field->name, field, flags, NULL);
2174+
field->name, field, flags_p, title,
2175+
filter, NULL);
21582176
}
21592177
}
21602178
}
21612179

2162-
void ucs_config_parser_print_opts(FILE *stream, const char *title, const void *opts,
2163-
ucs_config_field_t *fields, const char *table_prefix,
2164-
const char *prefix, ucs_config_print_flags_t flags)
2180+
void ucs_config_parser_print_opts(FILE *stream, const char *title,
2181+
const void *opts, ucs_config_field_t *fields,
2182+
const char *table_prefix, const char *prefix,
2183+
const ucs_config_print_flags_t flags,
2184+
const char *filter)
21652185
{
2186+
ucs_config_print_flags_t flags_copy = flags;
21662187
ucs_config_parser_prefix_t table_prefix_elem;
21672188
UCS_LIST_HEAD(prefix_list);
21682189

2169-
if (flags & UCS_CONFIG_PRINT_DOC) {
2170-
fprintf(stream, "# UCX library configuration file\n");
2171-
fprintf(stream, "# Uncomment to modify values\n");
2172-
}
2173-
2174-
if (flags & UCS_CONFIG_PRINT_HEADER) {
2175-
fprintf(stream, "\n");
2176-
fprintf(stream, "#\n");
2177-
fprintf(stream, "# %s\n", title);
2178-
fprintf(stream, "#\n");
2179-
fprintf(stream, "\n");
2180-
}
2181-
21822190
if (flags & UCS_CONFIG_PRINT_CONFIG) {
21832191
table_prefix_elem.prefix = table_prefix ? table_prefix : "";
21842192
ucs_list_add_tail(&prefix_list, &table_prefix_elem.list);
2185-
ucs_config_parser_print_opts_recurs(stream, opts, fields, flags,
2186-
prefix, &prefix_list);
2187-
}
2188-
2189-
if (flags & UCS_CONFIG_PRINT_HEADER) {
2190-
fprintf(stream, "\n");
2193+
ucs_config_parser_print_opts_recurs(stream, opts, fields, &flags_copy,
2194+
prefix, &prefix_list, title,
2195+
filter);
2196+
} else if (flags & UCS_CONFIG_PRINT_HEADER) {
2197+
ucs_config_parser_print_header(stream, title);
21912198
}
21922199
}
21932200

21942201
void ucs_config_parser_print_all_opts(FILE *stream, const char *prefix,
21952202
ucs_config_print_flags_t flags,
2196-
ucs_list_link_t *config_list)
2203+
ucs_list_link_t *config_list,
2204+
const char *filter)
21972205
{
21982206
ucs_config_global_list_entry_t *entry;
21992207
ucs_status_t status;
22002208
char title[64];
22012209
void *opts;
22022210

2211+
if (flags & UCS_CONFIG_PRINT_DOC) {
2212+
fprintf(stream, "# UCX library configuration file\n");
2213+
fprintf(stream, "# Uncomment to modify values\n");
2214+
fprintf(stream, "\n");
2215+
}
2216+
22032217
ucs_list_for_each(entry, config_list, list) {
22042218
if ((entry->table == NULL) ||
22052219
(ucs_config_field_is_last(&entry->table[0]))) {
@@ -2221,7 +2235,7 @@ void ucs_config_parser_print_all_opts(FILE *stream, const char *prefix,
22212235

22222236
snprintf(title, sizeof(title), "%s configuration", entry->name);
22232237
ucs_config_parser_print_opts(stream, title, opts, entry->table,
2224-
entry->prefix, prefix, flags);
2238+
entry->prefix, prefix, flags, filter);
22252239

22262240
ucs_config_parser_release_opts(opts, entry->table);
22272241
ucs_free(opts);

src/ucs/config/parser.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -550,22 +550,27 @@ void ucs_config_parser_release_opts(void *opts, ucs_config_field_t *fields);
550550
* @param table_prefix Optional prefix to add to the variables of top-level table.
551551
* @param prefix Prefix to add to all environment variables.
552552
* @param flags Flags which control the output.
553+
* @param filter Filter output with substring match, if not NULL.
553554
*/
554-
void ucs_config_parser_print_opts(FILE *stream, const char *title, const void *opts,
555-
ucs_config_field_t *fields, const char *table_prefix,
556-
const char *prefix, ucs_config_print_flags_t flags);
555+
void ucs_config_parser_print_opts(FILE *stream, const char *title,
556+
const void *opts, ucs_config_field_t *fields,
557+
const char *table_prefix, const char *prefix,
558+
ucs_config_print_flags_t flags,
559+
const char *filter);
557560

558561
/**
559562
* Print all options defined in the library - names, values, documentation.
560563
*
561564
* @param stream Output stream to print to.
562565
* @param prefix Prefix to add to all environment variables.
563566
* @param flags Flags which control the output.
564-
* @param config_list List of config tables
567+
* @param config_list List of config tables.
568+
* @param filter Filter output with substring match, if not NULL.
565569
*/
566570
void ucs_config_parser_print_all_opts(FILE *stream, const char *prefix,
567571
ucs_config_print_flags_t flags,
568-
ucs_list_link_t *config_list);
572+
ucs_list_link_t *config_list,
573+
const char *filter);
569574

570575
/**
571576
* Read a value from options structure.

test/apps/test_ucp_config.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int main(int argc, char **argv)
8787
ucp_context_print_info(context, stdout);
8888
ucs_config_parser_print_all_opts(stdout, UCS_DEFAULT_ENV_PREFIX,
8989
UCS_CONFIG_PRINT_CONFIG,
90-
&ucs_config_global_list);
90+
&ucs_config_global_list, NULL);
9191
ucp_worker_destroy(worker);
9292
ret = 0;
9393

0 commit comments

Comments
 (0)