[PATCH i-g-t v2 17/21] gputop: print percentage number
Tvrtko Ursulin
tursulin at ursulin.net
Fri Apr 26 11:16:45 UTC 2024
On 24/04/2024 00:44, Lucas De Marchi wrote:
> Besides printing the bar, also print the raw number for easy
> visualization of small quantities. While at it, make sure gputop still
> works with small console widths.
>
> Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
> ---
> tools/gputop.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/tools/gputop.c b/tools/gputop.c
> index 9edb76acc..820a1b553 100644
> --- a/tools/gputop.c
> +++ b/tools/gputop.c
> @@ -42,17 +42,19 @@ static void n_spaces(const unsigned int n)
>
> static void print_percentage_bar(double percent, int max_len)
> {
> - int bar_len, i, len = max_len - 2;
> + int bar_len, i, len = max_len - 1;
> const int w = 8;
>
> - assert(max_len > 0);
> + len -= printf("|%.1f%% ", percent);
> +
> + /* no space left for bars, do what we can */
> + if (len < 0)
> + len = 0;
>
> bar_len = ceil(w * percent * len / 100.0);
> if (bar_len > w * len)
> bar_len = w * len;
>
> - putchar('|');
> -
> for (i = bar_len; i >= w; i -= w)
> printf("%s", bars[w]);
> if (i)
Works for me I think. Maybe specify the width of the non-decimal part so
it is nicely aligned for all rows (%3.1f).
Btw there's also the alternative way how intel_gpu_top does it, where it
kind of overlays the percentage over the bar. "Kind of" because if
splats a bit over short percentage bars so I was never fully happy with it.
Regards,
Tvrtko
More information about the igt-dev
mailing list