From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <zhaoshenglong@huawei.com>
Received: from szxga02-in.huawei.com (unknown [119.145.14.65])
 by dpdk.org (Postfix) with ESMTP id 49A46312
 for <dev@dpdk.org>; Thu, 29 May 2014 10:21:32 +0200 (CEST)
Received: from 172.24.2.119 (EHLO szxeml210-edg.china.huawei.com)
 ([172.24.2.119])
 by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued)
 with ESMTP id BUK37043; Thu, 29 May 2014 16:21:32 +0800 (CST)
Received: from SZXEML420-HUB.china.huawei.com (10.82.67.159) by
 szxeml210-edg.china.huawei.com (172.24.2.183) with Microsoft SMTP Server
 (TLS) id 14.3.158.1; Thu, 29 May 2014 16:20:36 +0800
Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by
 szxeml420-hub.china.huawei.com (10.82.67.159) with Microsoft SMTP Server id
 14.3.158.1; Thu, 29 May 2014 16:20:31 +0800
From: Shannon Zhao <zhaoshenglong@huawei.com>
To: <dev@dpdk.org>
Date: Thu, 29 May 2014 16:19:32 +0800
Message-ID: <1401351572-6944-1-git-send-email-zhaoshenglong@huawei.com>
X-Mailer: git-send-email 1.9.0.msysgit.0
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [10.177.16.142]
X-CFilter-Loop: Reflected
Subject: [dpdk-dev] [PATCH v3] cpu_layout.py: adjust output format to align
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 29 May 2014 08:21:35 -0000

Bug: when "core id" is greater than 9, the cpu_layout.py output doesn't align.

        Socket 0        Socket 1
        ---------       ---------
Core 9  [4, 16]         [10, 22]

Core 10         [5, 17]         [11, 23]

Solution: adjust output format to align based on the maximum length of the "core id" and "processor"

        Socket 0        Socket 1
        --------        --------
Core 9  [4, 16]         [10, 22]

Core 10 [5, 17]         [11, 23]

Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
---
 tools/cpu_layout.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/cpu_layout.py b/tools/cpu_layout.py
index 9eff9d7..52d01a8 100755
--- a/tools/cpu_layout.py
+++ b/tools/cpu_layout.py
@@ -75,15 +75,21 @@ print "cores = ",cores
 print "sockets = ", sockets
 print ""
 
+max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
+max_core_map_len = max_processor_len * 2 + len('[, ]') + len('Socket ')
+max_core_id_len = len(str(max(cores)))
+
+print " ".ljust(max_core_id_len + len('Core ')),
 for s in sockets:
-	print "\tSocket %s" % s,
+	print "Socket %s" % str(s).ljust(max_core_map_len - len('Socket ')),
 print ""
+print " ".ljust(max_core_id_len + len('Core ')),
 for s in sockets:
-	print "\t---------",
+	print "--------".ljust(max_core_map_len),
 print ""
 
 for c in cores:
-	print "Core %s" % c,
+	print "Core %s" % str(c).ljust(max_core_id_len),
 	for s in sockets:
-		print "\t", core_map[(s,c)],
+		print str(core_map[(s,c)]).ljust(max_core_map_len),
 	print "\n"
-- 
1.9.0.msysgit.0