[PATCH 1/4] gputop: print percentage number

Kamil Konieczny kamil.konieczny at linux.intel.com
Tue May 7 18:22:06 UTC 2024


Hi Lucas,
On 2024-05-01 at 12:33:00 -0500, 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.
> 
> v2: Use %5.1f instead of %.1f so it also aligns the non-decimal part
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>

> ---
>  tools/gputop.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/gputop.c b/tools/gputop.c
> index 8cec951b4..7fd9e9790 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("|%5.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)
> -- 
> 2.45.0
> 


More information about the igt-dev mailing list