[Intel-gfx] [PATCH] Limit printing to terminal height in intel_gpu_top.

Kenneth Graunke kenneth at whitecape.org
Wed Dec 9 07:38:18 CET 2009


When using intel_gpu_top in a small terminal, the most important
information (ring idle/busy units) scrolls off the top of the screen.
This patch limits the number of lines printed to the terminal height
so that the most idle units (at the bottom) are truncated instead.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---

Currently it gets the terminal height each time it redraws the screen,
allowing it to update when you resize the terminal.  It might be
better to do that via a SIGWINCH handler, though - this was just simple.

 tools/intel_gpu_top.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index d314eda..9ef3ae4 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <err.h>
+#include <sys/ioctl.h>
 #include "intel_gpu_tools.h"
 #include "instdone.h"
 
@@ -257,6 +258,13 @@ int main(int argc, char **argv)
 		qsort(top_bits_sorted, num_instdone_bits,
 		      sizeof(struct top_bit *), top_bits_sort);
 
+		/* Limit the number of lines printed to the terminal height so the
+		 * most important info (at the top) will stay on screen. */
+		unsigned short int max_lines = -1;
+		struct winsize ws;
+		if (ioctl(0, TIOCGWINSZ, &ws) != -1)
+			max_lines = ws.ws_row - 6; /* exclude header lines */
+
 		printf("%s", clear_screen);
 
 		print_clock_info();
@@ -275,11 +283,13 @@ int main(int argc, char **argv)
 			if (top_bits_sorted[i]->count < 1)
 				break;
 
-			percent = top_bits_sorted[i]->count / SAMPLES_TO_PERCENT_RATIO;
-			len = printf("%30s: %3d%%: ",
-				     top_bits_sorted[i]->bit->name,
-				     percent);
-			print_percentage_bar (percent, len);
+			if (i < max_lines) {
+				percent = top_bits_sorted[i]->count / 
SAMPLES_TO_PERCENT_RATIO;
+				len = printf("%30s: %3d%%: ",
+					     top_bits_sorted[i]->bit->name,
+					     percent);
+				print_percentage_bar (percent, len);
+			}
 
 			top_bits_sorted[i]->count = 0;
 		}
-- 
1.6.5.5



More information about the Intel-gfx mailing list