diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2024-04-30 12:01:49 -0700 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2024-05-01 01:48:55 -0500 |
commit | d407d11c9659fb30d46206606e157b4bfa03b971 (patch) | |
tree | d8cf98ea836079a5e960a73145a0948febded42c /tools | |
parent | b33f92c3dc307f59c59ea3c5af35e9d4954cecc0 (diff) |
tools/gputop: Extract method to update console size
Cleanup the mainloop moving the console size handling to a helper
functions.
Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Link: https://lore.kernel.org/r/20240430190150.3654507-5-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gputop.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/tools/gputop.c b/tools/gputop.c index 8f81e6fca..455f77d0c 100644 --- a/tools/gputop.c +++ b/tools/gputop.c @@ -268,6 +268,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; @@ -283,17 +300,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); |