Skip to content

Commit

Permalink
lstopo: add --thickness
Browse files Browse the repository at this point in the history
Closes #414

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Sep 19, 2020
1 parent a0ab822 commit ecacdc8
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -52,6 +52,8 @@ Version 2.3.0
among the memory binding set.
+ Tools that have a --restrict option may now receive a nodeset or
some custom flags for restricting the topology.
+ lstopo now has a --thickness option for changing line thickness in the
graphical output.
+ Fix lstopo drawing when autoresizing on Windows 10.
+ Pressing the F5 key in lstopo X11 and Windows graphical/interactive outputs
now refreshes the display according to the current topology and binding.
Expand Down
3 changes: 3 additions & 0 deletions tests/hwloc/ports/include/windows/windows.h
Expand Up @@ -49,6 +49,7 @@ typedef void *HBRUSH;
typedef void *HICON;
typedef void *HMENU;
typedef void *HFONT;
typedef void *HPEN;
typedef HICON HCURSOR;
typedef DWORD COLORREF;
typedef LRESULT CALLBACK (*WNDPROC)(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
Expand Down Expand Up @@ -160,6 +161,8 @@ BOOL Rectangle(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottom
BOOL MoveToEx(HDC hdc, int X, int Y, LPPOINT lpPoint);
BOOL LineTo(HDC hdc, int nXEnd, int nYEnd);
HFONT CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet, DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality, DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
#define PS_SOLID 0
HPEN CreatePen(int iStyle, int cWidth, COLORREF color);
BOOL TextOut(HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cchString);
BOOL GetTextExtentPoint32(HDC hdc, LPCTSTR lpString, int c, LPSIZE lpSize);
#define TRANSPARENT 0
Expand Down
4 changes: 2 additions & 2 deletions utils/lstopo/lstopo-cairo.c
Expand Up @@ -73,7 +73,7 @@ topo_cairo_box(struct lstopo_output *loutput, const struct lstopo_color *lcolor,

cairo_rectangle(c, x, y, width, height);
cairo_set_source_rgb(c, 0, 0, 0);
cairo_set_line_width(c, 1);
cairo_set_line_width(c, loutput->thickness);
cairo_stroke(c);
}

Expand All @@ -86,7 +86,7 @@ topo_cairo_line(struct lstopo_output *loutput, const struct lstopo_color *lcolor

cairo_move_to(c, x1, y1);
cairo_set_source_rgb(c, (float) r / 255, (float) g / 255, (float) b / 255);
cairo_set_line_width(c, 1);
cairo_set_line_width(c, loutput->thickness);
cairo_line_to(c, x2, y2);
cairo_stroke(c);
}
Expand Down
6 changes: 3 additions & 3 deletions utils/lstopo/lstopo-fig.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2019 Inria. All rights reserved.
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2010 Université Bordeaux
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -54,7 +54,7 @@ fig_box(struct lstopo_output *loutput, const struct lstopo_color *lcolor, unsign
y *= FIG_FACTOR;
width *= FIG_FACTOR;
height *= FIG_FACTOR;
fprintf(file, "2 2 0 1 0 %d %u -1 20 0.0 0 0 -1 0 0 5\n\t", lcolor->private.fig.color, depth);
fprintf(file, "2 2 0 %u 0 %d %u -1 20 0.0 0 0 -1 0 0 5\n\t", loutput->thickness, lcolor->private.fig.color, depth);
fprintf(file, " %u %u", x, y);
fprintf(file, " %u %u", x + width, y);
fprintf(file, " %u %u", x + width, y + height);
Expand All @@ -72,7 +72,7 @@ fig_line(struct lstopo_output *loutput, const struct lstopo_color *lcolor, unsig
y1 *= FIG_FACTOR;
x2 *= FIG_FACTOR;
y2 *= FIG_FACTOR;
fprintf(file, "2 1 0 1 0 %d %u -1 -1 0.0 0 0 -1 0 0 2\n\t", lcolor->private.fig.color, depth);
fprintf(file, "2 1 0 %u 0 %d %u -1 -1 0.0 0 0 -1 0 0 2\n\t", loutput->thickness, lcolor->private.fig.color, depth);
fprintf(file, " %u %u", x1, y1);
fprintf(file, " %u %u", x2, y2);
fprintf(file, "\n");
Expand Down
7 changes: 7 additions & 0 deletions utils/lstopo/lstopo-no-graphics.1in
Expand Up @@ -317,6 +317,13 @@ The default is 4.

The option was included in \fB\-\-gridsize\fR prior to hwloc 2.1 (and its default was 10).

This option is ignored in the ASCII backend.
.TP
\fB\-\-thickness\fR <size>
Set the thickness of lines and boxes in the graphical output.

The default is 1.

This option is ignored in the ASCII backend.
.TP
\fB\-\-horiz\fR, \fB\-\-horiz\fR=<type1,...>
Expand Down
10 changes: 5 additions & 5 deletions utils/lstopo/lstopo-svg.c
@@ -1,5 +1,5 @@
/*
* Copyright © 2019 Inria. All rights reserved.
* Copyright © 2019-2020 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

Expand Down Expand Up @@ -36,8 +36,8 @@ native_svg_box(struct lstopo_output *loutput, const struct lstopo_color *lcolor,
snprintf(id, sizeof id, " id='anon_rect%s'", complement);
}

fprintf(file,"\t<rect%s%s x='%u' y='%u' width='%u' height='%u' fill='rgb(%d,%d,%d)' stroke='rgb(0,0,0)' stroke-width='1'/>\n",
id, class, x, y, width, height, r, g, b);
fprintf(file,"\t<rect%s%s x='%u' y='%u' width='%u' height='%u' fill='rgb(%d,%d,%d)' stroke='rgb(0,0,0)' stroke-width='%u'/>\n",
id, class, x, y, width, height, r, g, b, loutput->thickness);
}


Expand All @@ -61,8 +61,8 @@ native_svg_line(struct lstopo_output *loutput, const struct lstopo_color *lcolor
snprintf(id, sizeof id, " id='anon_line%s'", complement);
}

fprintf(file,"\t<line%s%s x1='%u' y1='%u' x2='%u' y2='%u' stroke='rgb(%d,%d,%d)' stroke-width='1'/>\n",
id, class, x1, y1, x2, y2, r, g, b);
fprintf(file,"\t<line%s%s x1='%u' y1='%u' x2='%u' y2='%u' stroke='rgb(%d,%d,%d)' stroke-width='%u'/>\n",
id, class, x1, y1, x2, y2, r, g, b, loutput->thickness);
}

static void
Expand Down
9 changes: 5 additions & 4 deletions utils/lstopo/lstopo-tikz.c
@@ -1,5 +1,6 @@
/*
* Copyright © 2020 Hewlett Packard Enterprise. All rights reserved.
* Copyright © 2020 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

Expand Down Expand Up @@ -55,8 +56,8 @@ tikz_box(struct lstopo_output *loutput, const struct lstopo_color *lcolor, unsig
FILE *file = loutput->file;
int r = lcolor->r, g = lcolor->g, b = lcolor->b;

fprintf(file, "\t\\filldraw [fill=hwloc-color-%d-%d-%d,draw=black,line width=1pt] (%u,%u) rectangle ++(%u,%u);\n",
r, g, b, x, y, width, height);
fprintf(file, "\t\\filldraw [fill=hwloc-color-%d-%d-%d,draw=black,line width=%upt] (%u,%u) rectangle ++(%u,%u);\n",
r, g, b, loutput->thickness, x, y, width, height);
}


Expand All @@ -66,8 +67,8 @@ tikz_line(struct lstopo_output *loutput, const struct lstopo_color *lcolor, unsi
FILE *file = loutput->file;
int r = lcolor->r, g = lcolor->g, b = lcolor->b;

fprintf(file, "\t\\draw [draw=hwloc-color-%d-%d-%d,line width=1pt] (%u,%u) -- (%u,%u);\n",
r, g, b, x1, y1, x2, y2);
fprintf(file, "\t\\draw [draw=hwloc-color-%d-%d-%d,line width=%upt] (%u,%u) -- (%u,%u);\n",
r, g, b, loutput->thickness, x1, y1, x2, y2);
}

static void
Expand Down
4 changes: 4 additions & 0 deletions utils/lstopo/lstopo-windows.c
Expand Up @@ -185,6 +185,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)

case WM_PAINT: {
HFONT font;
HPEN pen;
#ifdef HWLOC_HAVE_GCC_W_MISSING_FIELD_INITIALIZERS
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
Expand All @@ -195,6 +196,8 @@ WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
BeginPaint(hwnd, &the_output.ps);
font = CreateFont(loutput->fontsize, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL);
SelectObject(the_output.ps.hdc, (HGDIOBJ) font);
pen = CreatePen(PS_SOLID, loutput->thickness, RGB(0,0,0));
SelectObject(the_output.ps.hdc, pen);
SetBkMode(the_output.ps.hdc, TRANSPARENT);
loutput->drawing = LSTOPO_DRAWING_PREPARE;
output_draw(loutput);
Expand Down Expand Up @@ -223,6 +226,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
loutput->drawing = LSTOPO_DRAWING_DRAW;
windows_box(loutput, &white, 0, 0, win_width, 0, win_height, NULL, 0);
output_draw(loutput);
DeleteObject(pen);
DeleteObject(font);
EndPaint(hwnd, &the_output.ps);
break;
Expand Down
8 changes: 8 additions & 0 deletions utils/lstopo/lstopo.c
Expand Up @@ -416,6 +416,7 @@ void usage(const char *name, FILE *where)
fprintf (where, " --fontsize 10 Set size of text font\n");
fprintf (where, " --gridsize 7 Set size of margin between elements\n");
fprintf (where, " --linespacing 4 Set spacing between lines of text\n");
fprintf (where, " --thickness 1 Set thickness of lines and boxes\n");
fprintf (where, " --horiz[=<type,...>] Horizontal graphical layout instead of nearly 4/3 ratio\n");
fprintf (where, " --vert[=<type,...>] Vertical graphical layout instead of nearly 4/3 ratio\n");
fprintf (where, " --rect[=<type,...>] Rectangular graphical layout with nearly 4/3 ratio\n");
Expand Down Expand Up @@ -712,6 +713,7 @@ main (int argc, char *argv[])
loutput.fontsize = 10;
loutput.gridsize = 7;
loutput.linespacing = 4;
loutput.thickness = 1;

loutput.text_xscale = 1.0f;
env = getenv("LSTOPO_TEXT_XSCALE");
Expand Down Expand Up @@ -1156,6 +1158,12 @@ main (int argc, char *argv[])
loutput.linespacing = atoi(argv[1]);
opt = 1;
}
else if (!strcmp (argv[0], "--thickness")) {
if (argc < 2)
goto out_usagefailure;
loutput.thickness = atoi(argv[1]);
opt = 1;
}
else if (!strcmp (argv[0], "--no-legend")) {
loutput.show_legend = LSTOPO_SHOW_LEGEND_NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/lstopo/lstopo.h
Expand Up @@ -88,7 +88,7 @@ struct lstopo_output {
/* draw config */
char title[256];
unsigned plain_children_order;
unsigned int gridsize, fontsize, linespacing;
unsigned int gridsize, fontsize, linespacing, thickness;
float text_xscale;
enum lstopo_orient_e force_orient[HWLOC_OBJ_TYPE_MAX]; /* orientation of children within an object of the given type */
unsigned no_half_lines; /* set by ASCII backend because it cannot write between lines of the terminal */
Expand Down

0 comments on commit ecacdc8

Please sign in to comment.