Skip to content

Commit cd4678c

Browse files
committed
lstopo/draw: allow to save custom legend lines in the topology
Put lstopoLegend="This machine has a broken BIOS reporting each core as a package." in the root object infos, instead of using --append-legend everytime you re-export the picture. Signed-off-by: Brice Goglin <[email protected]>
1 parent 0a6a4f3 commit cd4678c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

utils/lstopo/lstopo-draw.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,14 +1406,15 @@ output_draw(struct lstopo_output *loutput)
14061406
hwloc_obj_t root = hwloc_get_root_obj(topology);
14071407
struct lstopo_obj_userdata *rlud = root->userdata;
14081408
unsigned depth = 100;
1409-
unsigned totwidth, totheight, offset, i;
1409+
unsigned totwidth, totheight, offset, i, j;
14101410
time_t t;
14111411
char text[3][128];
14121412
unsigned ntext = 0;
14131413
char hostname[122] = "";
14141414
const char *forcedhostname = NULL;
14151415
unsigned long hostname_size = sizeof(hostname);
14161416
unsigned maxtextwidth = 0, textwidth;
1417+
unsigned infocount = 0;
14171418

14181419
if (legend) {
14191420
forcedhostname = hwloc_obj_get_info_by_name(hwloc_get_root_obj(topology), "HostName");
@@ -1469,6 +1470,15 @@ output_draw(struct lstopo_output *loutput)
14691470
maxtextwidth = textwidth;
14701471
ntext++;
14711472

1473+
for(i=0; i<root->infos_count; i++) {
1474+
if (!strcmp(root->infos[i].name, "lstopoLegend")) {
1475+
infocount++;
1476+
textwidth = get_textwidth(loutput, root->infos[i].value, (unsigned) strlen(root->infos[i].value), fontsize);
1477+
if (textwidth > maxtextwidth)
1478+
maxtextwidth = textwidth;
1479+
}
1480+
}
1481+
14721482
for(i=0; i<loutput->legend_append_nr; i++) {
14731483
textwidth = get_textwidth(loutput, loutput->legend_append[i], (unsigned) strlen(loutput->legend_append[i]), fontsize);
14741484
if (textwidth > maxtextwidth)
@@ -1492,7 +1502,7 @@ output_draw(struct lstopo_output *loutput)
14921502
/* loutput height is sum(root, legend) */
14931503
totheight = rlud->height;
14941504
if (legend)
1495-
totheight += gridsize + (ntext+loutput->legend_append_nr - 1) * (linespacing+fontsize) + fontsize + gridsize;
1505+
totheight += gridsize + (ntext + infocount + loutput->legend_append_nr - 1) * (linespacing+fontsize) + fontsize + gridsize;
14961506
loutput->height = totheight;
14971507

14981508
} else { /* LSTOPO_DRAWING_DRAW */
@@ -1506,11 +1516,18 @@ output_draw(struct lstopo_output *loutput)
15061516
/* Draw legend */
15071517
if (legend) {
15081518
offset = rlud->height + gridsize;
1509-
methods->box(loutput, &WHITE_COLOR, depth, 0, loutput->width, totheight, gridsize + (ntext+loutput->legend_append_nr-1) * (linespacing + fontsize) + fontsize + gridsize, NULL, 0);
1519+
methods->box(loutput, &WHITE_COLOR, depth, 0, loutput->width, totheight, gridsize + (ntext + infocount + loutput->legend_append_nr - 1) * (linespacing + fontsize) + fontsize + gridsize, NULL, 0);
15101520
for(i=0; i<ntext; i++, offset += linespacing + fontsize)
15111521
methods->text(loutput, &BLACK_COLOR, fontsize, depth, gridsize, offset, text[i], NULL, i);
1522+
for(i=0, j=0; i<root->infos_count; i++) {
1523+
if (!strcmp(root->infos[i].name, "lstopoLegend")) {
1524+
methods->text(loutput, &BLACK_COLOR, fontsize, depth, gridsize, offset, root->infos[i].value, NULL, j+ntext);
1525+
j++;
1526+
offset += linespacing + fontsize;
1527+
}
1528+
}
15121529
for(i=0; i<loutput->legend_append_nr; i++, offset += linespacing + fontsize)
1513-
methods->text(loutput, &BLACK_COLOR, fontsize, depth, gridsize, offset, loutput->legend_append[i], NULL, i+ntext);
1530+
methods->text(loutput, &BLACK_COLOR, fontsize, depth, gridsize, offset, loutput->legend_append[i], NULL, i+ntext+infocount);
15141531
}
15151532
}
15161533
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ Remove the text legend at the bottom of the graphical output.
368368
Append the line of text to the bottom of the legend in the graphical output.
369369
If adding multiple lines, each line should be given separately by
370370
passing this option multiple times.
371+
Additional legend lines may also be specified inside the topology using the
372+
"lstopoLegend" info attributes on the topology root object.
371373
.TP
372374
\fB\-\-binding\-color none
373375
Do not colorize PUs and NUMA nodes according to the binding in the graphical output.

0 commit comments

Comments
 (0)