Skip to content

Commit a3d34d8

Browse files
committed
lstopo/draw: add --no-default-legend
To remove the default lines (hostname, date, ...) without ignoring user-given lines with --append-legend or lstopoLegend. And hitting 'l' key toggles between none, no default or all default lines. Signed-off-by: Brice Goglin <[email protected]>
1 parent cd4678c commit a3d34d8

File tree

7 files changed

+59
-17
lines changed

7 files changed

+59
-17
lines changed

contrib/completion/hwloc-completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ _lstopo() {
6060
--attrs --attrs=
6161
--no-attrs --no-attrs=
6262
--no-legend
63+
--no-default-legend
6364
--append-legend
6465
--binding-color
6566
--disallowed-color

utils/lstopo/lstopo-cairo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,18 @@ output_x11(struct lstopo_output *loutput, const char *dummy __hwloc_attribute_un
594594
move_x11(disp);
595595
break;
596596
case XK_l:
597-
loutput->legend ^= 1;
598-
printf("%s legend\n", loutput->legend ? "enabled" : "disabled");
597+
if (loutput->show_legend == LSTOPO_SHOW_LEGEND_ALL) {
598+
loutput->show_legend = LSTOPO_SHOW_LEGEND_NONE;
599+
printf("switched to no legend lines\n");
600+
} else if (loutput->show_legend == LSTOPO_SHOW_LEGEND_NONE) {
601+
loutput->show_legend = LSTOPO_SHOW_LEGEND_NO_DEFAULT;
602+
printf("switched to no default legend lines\n");
603+
} else if (loutput->show_legend == LSTOPO_SHOW_LEGEND_NO_DEFAULT) {
604+
loutput->show_legend = LSTOPO_SHOW_LEGEND_ALL;
605+
printf("switched to all legend lines\n");
606+
} else {
607+
abort();
608+
}
599609
disp->needs_redraw = 1;
600610
disp->needs_resize = 1;
601611
move_x11(disp);

utils/lstopo/lstopo-draw.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,6 @@ output_draw(struct lstopo_output *loutput)
13991399
{
14001400
hwloc_topology_t topology = loutput->topology;
14011401
struct draw_methods *methods = loutput->methods;
1402-
int legend = loutput->legend;
14031402
unsigned gridsize = loutput->gridsize;
14041403
unsigned fontsize = loutput->fontsize;
14051404
unsigned linespacing = loutput->linespacing;
@@ -1416,7 +1415,8 @@ output_draw(struct lstopo_output *loutput)
14161415
unsigned maxtextwidth = 0, textwidth;
14171416
unsigned infocount = 0;
14181417

1419-
if (legend) {
1418+
if (loutput->show_legend == LSTOPO_SHOW_LEGEND_ALL) {
1419+
/* build the default legend lines */
14201420
forcedhostname = hwloc_obj_get_info_by_name(hwloc_get_root_obj(topology), "HostName");
14211421
if (!forcedhostname && hwloc_topology_is_thissystem(topology)) {
14221422
#if defined(HWLOC_WIN_SYS) && !defined(__CYGWIN__)
@@ -1469,7 +1469,10 @@ output_draw(struct lstopo_output *loutput)
14691469
if (textwidth > maxtextwidth)
14701470
maxtextwidth = textwidth;
14711471
ntext++;
1472+
}
14721473

1474+
if (loutput->show_legend != LSTOPO_SHOW_LEGEND_NONE) {
1475+
/* look at custom legend lines in root info attr and --append-legend */
14731476
for(i=0; i<root->infos_count; i++) {
14741477
if (!strcmp(root->infos[i].name, "lstopoLegend")) {
14751478
infocount++;
@@ -1478,7 +1481,6 @@ output_draw(struct lstopo_output *loutput)
14781481
maxtextwidth = textwidth;
14791482
}
14801483
}
1481-
14821484
for(i=0; i<loutput->legend_append_nr; i++) {
14831485
textwidth = get_textwidth(loutput, loutput->legend_append[i], (unsigned) strlen(loutput->legend_append[i]), fontsize);
14841486
if (textwidth > maxtextwidth)
@@ -1501,7 +1503,8 @@ output_draw(struct lstopo_output *loutput)
15011503

15021504
/* loutput height is sum(root, legend) */
15031505
totheight = rlud->height;
1504-
if (legend)
1506+
if (loutput->show_legend != LSTOPO_SHOW_LEGEND_NONE
1507+
&& (ntext + infocount + loutput->legend_append_nr))
15051508
totheight += gridsize + (ntext + infocount + loutput->legend_append_nr - 1) * (linespacing+fontsize) + fontsize + gridsize;
15061509
loutput->height = totheight;
15071510

@@ -1514,7 +1517,8 @@ output_draw(struct lstopo_output *loutput)
15141517
get_type_fun(root->type)(loutput, root, depth, 0, 0);
15151518

15161519
/* Draw legend */
1517-
if (legend) {
1520+
if (loutput->show_legend != LSTOPO_SHOW_LEGEND_NONE
1521+
&& (ntext + infocount + loutput->legend_append_nr)) {
15181522
offset = rlud->height + gridsize;
15191523
methods->box(loutput, &WHITE_COLOR, depth, 0, loutput->width, totheight, gridsize + (ntext + infocount + loutput->legend_append_nr - 1) * (linespacing + fontsize) + fontsize + gridsize, NULL, 0);
15201524
for(i=0; i<ntext; i++, offset += linespacing + fontsize)

utils/lstopo/lstopo-no-graphics.1in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,12 @@ If a comma-separated list of object types is given, attributes are reenabled for
362362
(if they were previously disabled with \fB\-\-no\-attrs\fR).
363363
.TP
364364
\fB\-\-no\-legend\fR
365-
Remove the text legend at the bottom of the graphical output.
365+
Remove all text legend lines at the bottom of the graphical output.
366+
.TP
367+
\fB\-\-no\-default\-legend\fR
368+
Remove default text legend lines at the bottom of the graphical output.
369+
User-added legend lines with \fB\-\-append\-legend\fB or the "lstopoLegend" info
370+
are still displayed if any.
366371
.TP
367372
\fB\-\-append\-legend\fB <line>
368373
Append the line of text to the bottom of the legend in the graphical output.

utils/lstopo/lstopo-windows.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,18 @@ WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
133133
redraw = 1;
134134
break;
135135
case 'l':
136-
loutput->legend ^= 1;
137-
printf("%s legend\n", loutput->legend ? "enabled" : "disabled");
136+
if (loutput->show_legend == LSTOPO_SHOW_LEGEND_ALL) {
137+
loutput->show_legend = LSTOPO_SHOW_LEGEND_NONE;
138+
printf("switched to no legend lines\n");
139+
} else if (loutput->show_legend == LSTOPO_SHOW_LEGEND_NONE) {
140+
loutput->show_legend = LSTOPO_SHOW_LEGEND_NO_DEFAULT;
141+
printf("switched to no default legend lines\n");
142+
} else if (loutput->show_legend == LSTOPO_SHOW_LEGEND_NO_DEFAULT) {
143+
loutput->show_legend = LSTOPO_SHOW_LEGEND_ALL;
144+
printf("switched to all legend lines\n");
145+
} else {
146+
abort();
147+
}
138148
redraw = 1;
139149
if (auto_resize)
140150
needs_resize = 1;

utils/lstopo/lstopo.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ void usage(const char *name, FILE *where)
423423
fprintf (where, " --no-index=[<type,.>] Do not display indexes for the given object types\n");
424424
fprintf (where, " --attrs=[<type,...>] Display attributes for the given object types\n");
425425
fprintf (where, " --no-attrs=[<type,.>] Do not display attributes for the given object types\n");
426-
fprintf (where, " --no-legend Remove the text legend at the bottom\n");
426+
fprintf (where, " --no-legend Remove all text legend lines at the bottom\n");
427+
fprintf (where, " --no-default-legend Remove default text legend lines at the bottom\n");
427428
fprintf (where, " --append-legend <s> Append a new line of text at the bottom of the legend\n");
428429
fprintf (where, " --binding-color none Do not colorize PU and NUMA nodes according to the binding\n");
429430
fprintf (where, " --disallowed-color none Do not colorize disallowed PU and NUMA nodes\n");
@@ -462,7 +463,7 @@ void lstopo_show_interactive_help(void)
462463
printf(" Toggle displaying of obj attributes . a\n");
463464
printf(" Toggle color for disallowed objects . d\n");
464465
printf(" Toggle color for binding objects .... b\n");
465-
printf(" Toggle displaying of the legend ..... l\n");
466+
printf(" Toggle displaying of legend lines ... l\n");
466467
printf(" Export to file with current config .. E\n");
467468
printf("\n\n");
468469
fflush(stdout);
@@ -490,8 +491,10 @@ static void lstopo__show_interactive_cli_options(const struct lstopo_output *lou
490491
printf(" --binding-color none");
491492
if (!loutput->show_disallowed)
492493
printf(" --disallowed-color none");
493-
if (!loutput->legend)
494+
if (loutput->show_legend == LSTOPO_SHOW_LEGEND_NONE)
494495
printf(" --no-legend");
496+
else if (loutput->show_legend == LSTOPO_SHOW_LEGEND_NO_DEFAULT)
497+
printf(" --no-default-legend");
495498
}
496499

497500
void lstopo_show_interactive_cli_options(const struct lstopo_output *loutput)
@@ -688,7 +691,7 @@ main (int argc, char *argv[])
688691
loutput.export_xml_flags = 0;
689692
loutput.shmem_output_addr = 0;
690693

691-
loutput.legend = 1;
694+
loutput.show_legend = LSTOPO_SHOW_LEGEND_ALL;
692695
loutput.legend_append = NULL;
693696
loutput.legend_append_nr = 0;
694697
snprintf(loutput.title, sizeof(loutput.title), "lstopo");
@@ -1149,7 +1152,10 @@ main (int argc, char *argv[])
11491152
opt = 1;
11501153
}
11511154
else if (!strcmp (argv[0], "--no-legend")) {
1152-
loutput.legend = 0;
1155+
loutput.show_legend = LSTOPO_SHOW_LEGEND_NONE;
1156+
}
1157+
else if (!strcmp (argv[0], "--no-default-legend")) {
1158+
loutput.show_legend = LSTOPO_SHOW_LEGEND_NO_DEFAULT;
11531159
}
11541160
else if (!strcmp (argv[0], "--append-legend")) {
11551161
char **tmp;
@@ -1206,7 +1212,7 @@ main (int argc, char *argv[])
12061212
if (!loutput.fontsize) {
12071213
for(i=HWLOC_OBJ_TYPE_MIN; i<HWLOC_OBJ_TYPE_MAX; i++)
12081214
loutput.show_text[i] = 0;
1209-
loutput.legend = 0;
1215+
loutput.show_legend = LSTOPO_SHOW_LEGEND_NONE;
12101216
}
12111217

12121218
/***********************

utils/lstopo/lstopo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ enum lstopo_index_type_e {
3333
LSTOPO_INDEX_TYPE_NONE /* only used during the interactive display */
3434
};
3535

36+
enum lstopo_show_legend_e {
37+
LSTOPO_SHOW_LEGEND_ALL,
38+
LSTOPO_SHOW_LEGEND_NONE,
39+
LSTOPO_SHOW_LEGEND_NO_DEFAULT
40+
};
41+
3642
FILE *open_output(const char *filename, int overwrite) __hwloc_attribute_malloc;
3743

3844
struct draw_methods;
@@ -68,7 +74,7 @@ struct lstopo_output {
6874
uint64_t shmem_output_addr;
6975

7076
/* legend */
71-
int legend;
77+
enum lstopo_show_legend_e show_legend;
7278
char ** legend_append;
7379
unsigned legend_append_nr;
7480

0 commit comments

Comments
 (0)