From: "Purkait, Soham" <soham.purkait@intel.com>
To: "Srinivas, Vidya" <vidya.srinivas@intel.com>,
"igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>,
"Konieczny, Kamil" <kamil.konieczny@intel.com>
Subject: Re: tools/gputop: Fix zero output when stdout is not a terminal
Date: Mon, 6 Apr 2026 22:04:35 +0530 [thread overview]
Message-ID: <13484d88-3cd6-429d-a083-b7af1fd93aac@intel.com> (raw)
In-Reply-To: <PH7PR11MB82525EF1740193ACABD30E52895DA@PH7PR11MB8252.namprd11.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 3388 bytes --]
Hi Vidya,
On 06-04-2026 11:11, Srinivas, Vidya wrote:
>
>> -----Original Message-----
>> From: Purkait, Soham<soham.purkait@intel.com>
>> Sent: 06 April 2026 10:27
>> To: Srinivas, Vidya<vidya.srinivas@intel.com>;igt-dev@lists.freedesktop.org;
>> Konieczny, Kamil<kamil.konieczny@intel.com>
>> Subject: Re: tools/gputop: Fix zero output when stdout is not a terminal
>>
>> Hi Vidya,
>>
>> On 02-04-2026 19:15, Vidya Srinivas wrote:
>>> When gputop output is redirected to a file or pipe, such as:
>>>
>>> gputop -n 5 -d 1 > results.txt
>> Isn’t only stdout (fd 1) redirected to the file here?
>>
>> I guess some thing like "echo test | ./gputop" would be returning the default
>> value (-1 in this case) for con_h.
> Hello,
>
> Many thanks for the review.
> I will update the patch like this. Should be okay?
>
> if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
> ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1 &&
> ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1) {
I assume it's better to keep this : "if (ioctl(0, TIOCGWINSZ, &ws) ==
-1)" as is. As it won't make any issue if the gputop output is
redirected to any file or so (which only involve stdout). The
expression will only be true when stdin is not a terminal, may be
during running gputop in a ci.
And Its better to assign the default values to con_w and con_h in main.
(please see below)
> ws.ws_col = 80;
> ws.ws_row = 50;
> }
>
> Regards
> Vidya
>
>>> 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>
>>> Reviewed-by: Kamil Konieczny<kamil.konieczny@linux.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;
Imho instead of setting the values (*w = 80;*h = 50) here , it's better
to initialize these as default values in main as "int con_w = 80, con_h
= 50;"
Thanks, Soham
>> How about assigning the values during initialization in the main function ?
>>
>> eg : int con_w = 80, con_h = 50;
>>
>> Thanks,
>> Soham
>>
>>> return;
>>> + }
>>>
>>> *w = ws.ws_col;
>>> *h = ws.ws_row;
[-- Attachment #2: Type: text/html, Size: 5456 bytes --]
next prev parent reply other threads:[~2026-04-06 16:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13484d88-3cd6-429d-a083-b7af1fd93aac@intel.com \
--to=soham.purkait@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@intel.com \
--cc=vidya.srinivas@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox