diff mbox series

[i-g-t] intel_gpu_top: Wrap interactive header

Message ID 20210201115756.876351-1-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [i-g-t] intel_gpu_top: Wrap interactive header | expand

Commit Message

Tvrtko Ursulin Feb. 1, 2021, 11:57 a.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Slight improvement with regards to wrapping header components to fit
console width. If a single element is wider than max it can still
overflow but it should now work better for practical console widths.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tools/intel_gpu_top.c | 84 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 71 insertions(+), 13 deletions(-)

Comments

Chris Wilson Feb. 1, 2021, 12:07 p.m. UTC | #1
Quoting Tvrtko Ursulin (2021-02-01 11:57:56)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> Slight improvement with regards to wrapping header components to fit
> console width. If a single element is wider than max it can still
> overflow but it should now work better for practical console widths.

<----
intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0
 900/ 949 MHz;   0% RC6;  6.97/18.42 W;        2 irqs/s
      IMC reads:        6 MiB/s
     IMC writes:        0 MiB/s

---->
intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  903/ 954 MHz;   0% RC6
    7.16/18.40 W;       14 irqs/s

      IMC reads:       80 MiB/s
     IMC writes:        0 MiB/s

I thought it looked reasonably tidy, without adding any lines to the
header.
-Chris
Tvrtko Ursulin Feb. 3, 2021, 10:31 a.m. UTC | #2
On 01/02/2021 12:07, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2021-02-01 11:57:56)
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> Slight improvement with regards to wrapping header components to fit
>> console width. If a single element is wider than max it can still
>> overflow but it should now work better for practical console widths.
> 
> <----
> intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0
>   900/ 949 MHz;   0% RC6;  6.97/18.42 W;        2 irqs/s
>        IMC reads:        6 MiB/s
>       IMC writes:        0 MiB/s
> 
> ---->
> intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  903/ 954 MHz;   0% RC6
>      7.16/18.40 W;       14 irqs/s
> 
>        IMC reads:       80 MiB/s
>       IMC writes:        0 MiB/s
> 
> I thought it looked reasonably tidy, without adding any lines to the
> header.

Or on a wider terminal:
<----
intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0
    0/   0 MHz; 100% RC6;  0.00/ 1.29 W;        0 irqs/s
       IMC reads:      138 MiB/s
      IMC writes:        6 MiB/s
--->
intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0 -    0/   0 MHz; 100% RC6;  0.00/ 0.00 W;        0 irqs/s

       IMC reads:       77 MiB/s
      IMC writes:        4 MiB/s


So a "fight" between 80 chars vs 120 (or so). :) It may be a bit of an over-engineered solution but I don't like the wrap on a wide terminal, plus I like an extra blank line.

Regards,

Tvrtko
Chris Wilson Feb. 3, 2021, 11 a.m. UTC | #3
Quoting Tvrtko Ursulin (2021-02-03 10:31:04)
> 
> On 01/02/2021 12:07, Chris Wilson wrote:
> > Quoting Tvrtko Ursulin (2021-02-01 11:57:56)
> >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> >>
> >> Slight improvement with regards to wrapping header components to fit
> >> console width. If a single element is wider than max it can still
> >> overflow but it should now work better for practical console widths.
> > 
> > <----
> > intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0
> >   900/ 949 MHz;   0% RC6;  6.97/18.42 W;        2 irqs/s
> >        IMC reads:        6 MiB/s
> >       IMC writes:        0 MiB/s
> > 
> > ---->
> > intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  903/ 954 MHz;   0% RC6
> >      7.16/18.40 W;       14 irqs/s
> > 
> >        IMC reads:       80 MiB/s
> >       IMC writes:        0 MiB/s
> > 
> > I thought it looked reasonably tidy, without adding any lines to the
> > header.
> 
> Or on a wider terminal:
> <----
> intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0
>     0/   0 MHz; 100% RC6;  0.00/ 1.29 W;        0 irqs/s
>        IMC reads:      138 MiB/s
>       IMC writes:        6 MiB/s
> --->
> intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0 -    0/   0 MHz; 100% RC6;  0.00/ 0.00 W;        0 irqs/s
> 
>        IMC reads:       77 MiB/s
>       IMC writes:        4 MiB/s
> 
> 
> So a "fight" between 80 chars vs 120 (or so). :) It may be a bit of an over-engineered solution but I don't like the wrap on a wide terminal, plus I like an extra blank line.

But the memory counters are visually similar to the
frequency/rc6/power/interrupts...
-Chris
Tvrtko Ursulin Feb. 3, 2021, 1:12 p.m. UTC | #4
On 03/02/2021 11:00, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2021-02-03 10:31:04)
>>
>> On 01/02/2021 12:07, Chris Wilson wrote:
>>> Quoting Tvrtko Ursulin (2021-02-01 11:57:56)
>>>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>>>
>>>> Slight improvement with regards to wrapping header components to fit
>>>> console width. If a single element is wider than max it can still
>>>> overflow but it should now work better for practical console widths.
>>>
>>> <----
>>> intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0
>>>    900/ 949 MHz;   0% RC6;  6.97/18.42 W;        2 irqs/s
>>>         IMC reads:        6 MiB/s
>>>        IMC writes:        0 MiB/s
>>>
>>> ---->
>>> intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  903/ 954 MHz;   0% RC6
>>>       7.16/18.40 W;       14 irqs/s
>>>
>>>         IMC reads:       80 MiB/s
>>>        IMC writes:        0 MiB/s
>>>
>>> I thought it looked reasonably tidy, without adding any lines to the
>>> header.
>>
>> Or on a wider terminal:
>> <----
>> intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0
>>      0/   0 MHz; 100% RC6;  0.00/ 1.29 W;        0 irqs/s
>>         IMC reads:      138 MiB/s
>>        IMC writes:        6 MiB/s
>> --->
>> intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0 -    0/   0 MHz; 100% RC6;  0.00/ 0.00 W;        0 irqs/s
>>
>>         IMC reads:       77 MiB/s
>>        IMC writes:        4 MiB/s
>>
>>
>> So a "fight" between 80 chars vs 120 (or so). :) It may be a bit of an over-engineered solution but I don't like the wrap on a wide terminal, plus I like an extra blank line.
> 
> But the memory counters are visually similar to the
> frequency/rc6/power/interrupts...

But I broke my layout by accident when rebasing client stats... ;D

Regards,

Tvrtko
Chris Wilson Feb. 3, 2021, 5:02 p.m. UTC | #5
Quoting Tvrtko Ursulin (2021-02-03 13:12:05)
> 
> On 03/02/2021 11:00, Chris Wilson wrote:
> > Quoting Tvrtko Ursulin (2021-02-03 10:31:04)
> >>
> >> On 01/02/2021 12:07, Chris Wilson wrote:
> >>> Quoting Tvrtko Ursulin (2021-02-01 11:57:56)
> >>>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> >>>>
> >>>> Slight improvement with regards to wrapping header components to fit
> >>>> console width. If a single element is wider than max it can still
> >>>> overflow but it should now work better for practical console widths.
> >>>
> >>> <----
> >>> intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0
> >>>    900/ 949 MHz;   0% RC6;  6.97/18.42 W;        2 irqs/s
> >>>         IMC reads:        6 MiB/s
> >>>        IMC writes:        0 MiB/s
> >>>
> >>> ---->
> >>> intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  903/ 954 MHz;   0% RC6
> >>>       7.16/18.40 W;       14 irqs/s
> >>>
> >>>         IMC reads:       80 MiB/s
> >>>        IMC writes:        0 MiB/s
> >>>
> >>> I thought it looked reasonably tidy, without adding any lines to the
> >>> header.
> >>
> >> Or on a wider terminal:
> >> <----
> >> intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0
> >>      0/   0 MHz; 100% RC6;  0.00/ 1.29 W;        0 irqs/s
> >>         IMC reads:      138 MiB/s
> >>        IMC writes:        6 MiB/s
> >> --->
> >> intel-gpu-top: Intel Skylake (Gen9) @ /dev/dri/card0 -    0/   0 MHz; 100% RC6;  0.00/ 0.00 W;        0 irqs/s
> >>
> >>         IMC reads:       77 MiB/s
> >>        IMC writes:        4 MiB/s
> >>
> >>
> >> So a "fight" between 80 chars vs 120 (or so). :) It may be a bit of an over-engineered solution but I don't like the wrap on a wide terminal, plus I like an extra blank line.
> > 
> > But the memory counters are visually similar to the
> > frequency/rc6/power/interrupts...
> 
> But I broke my layout by accident when rebasing client stats... ;D

Strange. Did you take a vacation or something ;)
-Chris
diff mbox series

Patch

diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index dffc6ebecc57..c43054c3fee8 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -1443,6 +1443,41 @@  static bool print_groups(struct cnt_group **groups)
 	return print_data;
 }
 
+static int __attribute__ ((format(__printf__, 6, 7)))
+print_header_token(const char *cont, int lines, int con_w, int con_h, int *rem,
+		   const char *fmt, ...)
+{
+	const char *indent = "\n   ";
+	char buf[256];
+	va_list args;
+	int ret;
+
+	if (lines >= con_h)
+		return lines;
+
+	va_start(args, fmt);
+	ret = vsnprintf(buf, sizeof(buf), fmt, args);
+	assert(ret < sizeof(buf));
+	va_end(args);
+
+	ret = (cont ? strlen(cont) : 0) + strlen(buf);
+	*rem -= ret;
+	if (*rem < 0) {
+		if (++lines >= con_h)
+			return lines;
+
+		*rem = con_w - ret - strlen(indent);
+		cont = indent;
+	}
+
+	if (cont)
+		ret = printf("%s%s", cont, buf);
+	else
+		ret = printf("%s", buf);
+
+	return lines;
+}
+
 static int
 print_header(const struct igt_device_card *card,
 	     const char *codename,
@@ -1520,22 +1555,45 @@  print_header(const struct igt_device_card *card,
 	*consumed = print_groups(groups);
 
 	if (output_mode == INTERACTIVE) {
+		int rem = con_w;
+
 		printf("\033[H\033[J");
 
-		if (lines++ < con_h)
-			printf("intel-gpu-top: %s @ %s\n",
-			       codename, card->card);
-		if (lines++ < con_h) {
-			printf("%s/%s MHz; %s%% RC6; ",
-			       freq_items[1].buf, freq_items[0].buf,
-			       rc6_items[0].buf);
-			if (engines->r_gpu.present) {
-				printf("%s/%s W; ",
-				       power_items[0].buf,
-				       power_items[1].buf);
-			}
-			printf("%s irqs/s\n", irq_items[0].buf);
+		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", codename);
+
+		lines = print_header_token(" @ ", lines, con_w, con_h, &rem,
+					   "%s", card->card);
+
+		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%% RC6",
+					   rc6_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 irqs/s",
+					   irq_items[0].buf);
+
+		if (lines++ < con_h)
+			printf("\n");
+
+		if (lines++ < con_h)
+			printf("\n");
 	}
 
 	return lines;