[igt-dev] [PATCH i-g-t 14/15] intel_gpu_top: Reduce one level of indent

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Wed May 10 08:43:39 UTC 2023


On 06/05/2023 01:55, Umesh Nerlige Ramappa wrote:
> Prepare to display gt specific items in INTERACTIVE mode with the -p
> option. An additional for loop will push code more towards right, so
> reduce one level of indent.
> 
> Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa at intel.com>
> ---
>   tools/intel_gpu_top.c | 74 ++++++++++++++++++++++---------------------
>   1 file changed, 38 insertions(+), 36 deletions(-)
> 
> diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
> index 8bcca67a6..0acc81e9e 100644
> --- a/tools/intel_gpu_top.c
> +++ b/tools/intel_gpu_top.c
> @@ -1944,7 +1944,7 @@ print_header(const struct igt_device_card *card,
>   		&power_group,
>   		NULL
>   	};
> -	int i;
> +	int rem, i;
>   
>   	/*
>   	 * If we have multi-gt and the user has specified -p options, show gt
> @@ -1971,51 +1971,53 @@ print_header(const struct igt_device_card *card,
>   
>   	*consumed = print_groups(groups);
>   
> -	if (output_mode == INTERACTIVE) {
> -		int rem = con_w;
> +	if (output_mode != INTERACTIVE)
> +		return lines;

Yeah this is better in any case since it correctly expresses the 
either-or flow.

Regards,

Tvrtko

>   
> -		printf("\033[H\033[J");
> +	/* INTERACTIVE MODE */
> +	rem = con_w;
>   
> -		lines = print_header_token(NULL, lines, con_w, con_h, &rem,
> -					   "intel-gpu-top:");
> +	printf("\033[H\033[J");
>   
> -		lines = print_header_token(" ", lines, con_w, con_h, &rem,
> -					   "%s", codename);
> +	lines = print_header_token(NULL, lines, con_w, con_h, &rem,
> +				   "intel-gpu-top:");
>   
> -		lines = print_header_token(" @ ", lines, con_w, con_h, &rem,
> -					   "%s", card->card);
> +	lines = print_header_token(" ", lines, con_w, con_h, &rem,
> +				   "%s", codename);
>   
> -		lines = print_header_token(" - ", lines, con_w, con_h, &rem,
> -					   "%s/%s MHz",
> -					   freq_items[1].buf,
> -					   freq_items[0].buf);
> +	lines = print_header_token(" @ ", lines, con_w, con_h, &rem,
> +				   "%s", card->card);
>   
> -		lines = print_header_token("; ", lines, con_w, con_h, &rem,
> -					   "%s%% RC6",
> -					   rc6_items[0].buf);
> +	lines = print_header_token(" - ", lines, con_w, con_h, &rem,
> +				   "%s/%s MHz",
> +				   freq_items[1].buf,
> +				   freq_items[0].buf);
>   
> -		if (engines->r_gpu.present) {
> -			lines = print_header_token("; ", lines, con_w, con_h,
> -						   &rem,
> -						   "%s/%s W",
> -						   power_items[0].buf,
> -						   power_items[1].buf);
> -		}
> +	lines = print_header_token("; ", lines, con_w, con_h, &rem,
> +				   "%s%% RC6",
> +				   rc6_items[0].buf);
>   
> -		lines = print_header_token("; ", lines, con_w, con_h, &rem,
> -					   "%s irqs/s",
> -					   irq_items[0].buf);
> +	if (engines->r_gpu.present) {
> +		lines = print_header_token("; ", lines, con_w, con_h,
> +					   &rem,
> +					   "%s/%s W",
> +					   power_items[0].buf,
> +					   power_items[1].buf);
> +	}
>   
> -		if (lines++ < con_h)
> -			printf("\n");
> +	lines = print_header_token("; ", lines, con_w, con_h, &rem,
> +				   "%s irqs/s",
> +				   irq_items[0].buf);
>   
> -		if (lines++ < con_h) {
> -			if (header_msg) {
> -				printf(" >>> %s\n", header_msg);
> -				header_msg = NULL;
> -			} else {
> -				printf("\n");
> -			}
> +	if (lines++ < con_h)
> +		printf("\n");
> +
> +	if (lines++ < con_h) {
> +		if (header_msg) {
> +			printf(" >>> %s\n", header_msg);
> +			header_msg = NULL;
> +		} else {
> +			printf("\n");
>   		}
>   	}
>   


More information about the igt-dev mailing list