Skip to contentSkip to conversation

cpu_layout.py: adjust output format to align

PATCH Superseded Shannon Zhao 2 participants 4 messages May 27, 2014 – May 28, 2014 2 messages not in the archive

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu_layout.py: adjust output format to align

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

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

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

---
 tools/cpu_layout.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/cpu_layout.py +2 -2
index 9eff9d7..4768551 100755
@@ -83,7 +83,7 @@ for s in sockets:
 print ""
 
 for c in cores:
-       print "Core %s" % c,
+       print "Core %s" % str(c).ljust(2),
        for s in sockets:
-               print "\t", core_map[(s,c)],
+               print core_map[(s,c)],"\t",
        print "\n"

--
1.7.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi,

Your patch doesn't apply correctly.
Could you check it, please?

I have also a comment inlined:

2014-05-27 17:41, Shannon Zhao:

tools/cpu_layout.py for s in sockets: · line 88

Quoted 2 lines
tools/cpu_layout.py +1 -1
-               print "\t", core_map[(s,c)],
+               print core_map[(s,c)],"\t",

Is it possible to fix a minimum alignment of 2 characters? It could prevent from such alignment problem:

Core 11 [9, 33] [21, 45]
Core 12 [10, 34] [22, 46]

Thanks

Signature · 1 line
Thomas
#3 lore raw

Hi Thomas,

Thanks for your reply.

I have checked my patch. It doesn't apply correctly when "core id" is greater than 2 characters.

Following is my revised patch. It's based on the maximum length of the "core id" and "processor" to adjust the alignment length.

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

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

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

---
 tools/cpu_layout.py |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
tools/cpu_layout.py +12 -4
index 9eff9d7..eeda17e 100755
@@ -75,15 +75,23 @@ 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+4
+if max_core_map_len < 12:
+        max_core_map_len = 12
+max_core_id_len=len(str(max(cores)))
+
+print " ".ljust(max_core_id_len+5),
 for s in sockets:
-       print "\tSocket %s" % s,
+       print "Socket %s" % str(s).ljust(max_core_map_len-7),
 print ""
+print " ".ljust(max_core_id_len+5),
 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.7.1

Quoted 19 lines · Thomas Monjalon

Hi,

Your patch doesn't apply correctly.
Could you check it, please?

I have also a comment inlined:

2014-05-27 17:41, Shannon Zhao:

Review

Quoted 2 lines
(quoted diff) +1 -1
-               print "\t", core_map[(s,c)],
+               print core_map[(s,c)],"\t",

Is it possible to fix a minimum alignment of 2 characters? It could prevent from such alignment problem:

Core 11 [9, 33] [21, 45]
Core 12 [10, 34] [22, 46]

Thanks

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Hi,

2014-05-28 11:02, Shannon Zhao:

Quoted 5 lines

I have checked my patch. It doesn't apply correctly when "core id" is greater than 2 characters.

Following is my revised patch. It's based on the maximum length of the "core id" and "processor" to adjust the alignment length.

Thank you for reworking your patch.

Please, could you send your patch as v2 with "git send-email"? There are some guidelines here:
http://dpdk.org/dev#send

Thanks

Signature · 1 line
Thomas