[PATCH i-g-t 10/12] gputop: Extract method to update console size

Umesh Nerlige Ramappa umesh.nerlige.ramappa at intel.com
Thu Apr 18 22:51:51 UTC 2024


On Fri, Apr 05, 2024 at 01:00:54AM -0500, Lucas De Marchi wrote:
>Cleanup the mainloop moving the console size handling to a helper
>functions.
>
>Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>

Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa at intel.com>

>---
> tools/gputop.c | 30 +++++++++++++++++++-----------
> 1 file changed, 19 insertions(+), 11 deletions(-)
>
>diff --git a/tools/gputop.c b/tools/gputop.c
>index b13044b50..1f349b3ed 100644
>--- a/tools/gputop.c
>+++ b/tools/gputop.c
>@@ -243,6 +243,23 @@ static int client_cmp(const void *_a, const void *_b, void *unused)
>
> }
>
>+static void update_console_size(int *w, int *h)
>+{
>+	struct winsize ws = {};
>+
>+	if (ioctl(0, TIOCGWINSZ, &ws) == -1)
>+		return;
>+
>+	*w = ws.ws_col;
>+	*h = ws.ws_row;
>+
>+	if (*w == 0 && *h == 0) {
>+		/* Serial console. */
>+		*w = 80;
>+		*h = 24;
>+	}
>+}
>+
> int main(int argc, char **argv)
> {
> 	unsigned int period_us = 2e6;
>@@ -258,17 +275,8 @@ int main(int argc, char **argv)
> 	for (;;) {
> 		struct igt_drm_client *c, *prevc = NULL;
> 		int i, engine_w = 0, lines = 0;
>-		struct winsize ws;
>-
>-		if (ioctl(0, TIOCGWINSZ, &ws) != -1) {
>-			con_w = ws.ws_col;
>-			con_h = ws.ws_row;
>-			if (con_w == 0 && con_h == 0) {
>-				/* Serial console. */
>-				con_w = 80;
>-				con_h = 24;
>-			}
>-		}
>+
>+		update_console_size(&con_w, &con_h);
>
> 		igt_drm_clients_scan(clients, NULL, NULL, 0, NULL, 0);
> 		igt_drm_clients_sort(clients, client_cmp);
>-- 
>2.44.0
>


More information about the igt-dev mailing list