Hi,

The attached patch detects if kerneltop deals with 32 or 64 bit
addresses, and aligns later printing accordingly.

Best regards,

V.
>From 7f8955a324ca98c51630a1bd905f13dba2cbb5c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vincent=20Stehl=C3=A9?= <vincent.ste...@laposte.net>
Date: Wed, 5 Sep 2012 23:04:28 +0200
Subject: [PATCH] Adapt printing alignment to 32/64 bit addresses
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Detect if start/end addresses are 32 bit or 64 bit, and align printing
accordingly. On my 64 bit PC, this results in a more readable display.

Signed-off-by: Vincent Stehlé <vincent.ste...@laposte.net>
---
 kerneltop.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/kerneltop.c b/kerneltop.c
index 56546c0..e418b3b 100644
--- a/kerneltop.c
+++ b/kerneltop.c
@@ -777,6 +777,7 @@ main (int argc, char **argv) {
 	int valid;
 	int first = 1;
 	char ch;
+	int aw;		// Addresses width, in number of hex characters.
 
 #ifdef NLS
 	setlocale (LC_ALL, "");
@@ -836,6 +837,12 @@ main (int argc, char **argv) {
 	freqs = (int *) xmalloc (sizeof(int) * (text_lines + 1));
 	memset (freqs, 0, sizeof(int) * (text_lines + 1));
 
+	// Detect addresses width.
+	aw = 8;
+
+	if ((adr0 > 0xffffffffu) || (adrz > 0xffffffffu))
+		aw = 16;
+
 	heading ();
 
     while (1) {		// get profile data, put it into symbol buckets, print
@@ -851,9 +858,9 @@ main (int argc, char **argv) {
 	dttm = localtime (&timer);
 	vid_curpos (ROW_HEADINGS, 1);
 	vid_attr (ATTR_REVERSE_ON);
-	printf (_("address  function ...... %d-%02d-%02d/%02d:%02d:%02d ...... ticks"),
-		dttm->tm_year + 1900, dttm->tm_mon + 1, dttm->tm_mday,
-		dttm->tm_hour, dttm->tm_min, dttm->tm_sec);
+	printf (_("%-*s function ...... %d-%02d-%02d/%02d:%02d:%02d ...... ticks"),
+		aw, "address", dttm->tm_year + 1900, dttm->tm_mon + 1,
+		dttm->tm_mday, dttm->tm_hour, dttm->tm_min, dttm->tm_sec);
 
 #ifdef OPT_REVERSE
 	if (optReverse) {	// reverse the byte order in the profile
@@ -906,8 +913,8 @@ main (int argc, char **argv) {
 		textsym = (struct text_symbol *) ((char *)textsymroot + text_entry_size * freqtable[ix].textindex);
 		vid_curpos (ROW_DATA + ix, 1);
 		vid_clear_curtoend();
-		printf ("%08lx %-41s %6i\n",
-			textsym->textadr, textsym->textname, ticks);
+		printf ("%0*lx %-*s %6i\n",
+			aw, textsym->textadr, 33 + aw, textsym->textname, ticks);
 	}
 
 	total_ticks = 0;
-- 
1.7.10.4

Reply via email to