public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH] tools/gputop: Fix zero output when stdout is not a terminal
@ 2026-04-02 13:45 Vidya Srinivas
  2026-04-02 14:56 ` Kamil Konieczny
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Vidya Srinivas @ 2026-04-02 13:45 UTC (permalink / raw)
  To: igt-dev; +Cc: Vidya Srinivas

When gputop output is redirected to a file or pipe, such as:

  gputop -n 5 -d 1 > results.txt
  gputop -n 3 -d 2 | grep rcs

ioctl(0, TIOCGWINSZ) fails with -1 since stdin is not a terminal.
update_console_size() then returns without setting *w and *h, leaving
con_w and con_h at their initial value of -1.

The main display loop uses 'if (lines >= con_h) break' to limit output
to the terminal height. With con_h = -1, the condition (0 >= -1) is
immediately true on the very first line, causing all client output to be
silently suppressed. The result is that gputop produces only ANSI clear-
screen escape sequences and zero actual data.

This affects anyone using gputop in automation, CI pipelines, or any
non-interactive context on Linux or Android where output is redirected
or piped.

Fix this by falling back to a default console size of 80x50 when the
ioctl fails, consistent with the existing fallback for serial consoles
(where ws_col and ws_row are both 0).

Signed-off-by: Vidya Srinivas <vidya.srinivas@intel.com>
---
 tools/gputop.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/gputop.c b/tools/gputop.c
index 9b2e8cb6f..112ec5ddb 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -505,8 +505,11 @@ static void update_console_size(int *w, int *h)
 {
 	struct winsize ws = {};
 
-	if (ioctl(0, TIOCGWINSZ, &ws) == -1)
+	if (ioctl(0, TIOCGWINSZ, &ws) == -1) {
+		*w = 80;
+		*h = 50;
 		return;
+	}
 
 	*w = ws.ws_col;
 	*h = ws.ws_row;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-04-09 16:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 13:45 [PATCH] tools/gputop: Fix zero output when stdout is not a terminal Vidya Srinivas
2026-04-02 14:56 ` Kamil Konieczny
2026-04-06  3:27   ` Srinivas, Vidya
2026-04-06  4:56 ` Purkait, Soham
2026-04-06  5:41   ` Srinivas, Vidya
2026-04-06 16:34     ` Purkait, Soham
2026-04-07 13:47       ` Srinivas, Vidya
2026-04-06  6:02 ` [PATCH] " Vidya Srinivas
2026-04-06  7:54 ` ✓ Xe.CI.BAT: success for tools/gputop: Fix zero output when stdout is not a terminal (rev2) Patchwork
2026-04-06  8:11 ` ✓ i915.CI.BAT: " Patchwork
2026-04-06 10:26 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-04-06 11:20 ` ✗ i915.CI.Full: " Patchwork
2026-04-07 13:39 ` [PATCH] tools/gputop: Fix zero output when stdout is not a terminal Vidya Srinivas
2026-04-09  9:21   ` Purkait, Soham
2026-04-09 13:23   ` [PATCH] " Kamil Konieczny
2026-04-09 16:58     ` Srinivas, Vidya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox