History

perf script python: Add Python3 support to mem-phys-addr.py

Support both Python2 and Python3 in the mem-phys-addr.py script There may be differences in the ordering of output lines due to differences in dictionary ordering etc. However the format within lines should be unchanged. The use of 'from __future__' implies the minimum supported Python2 version is now v2.6

Tony Jones committed 7 years ago

Commit e4d053d1 parent 9b2700e1 file · +14 −10Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/mem-phys-addr.py+14−10
@@ -4,6 +4,8 @@ · 3 unmodified lines
44 # Copyright (c) 2018, Intel Corporation.
55
66 from __future__ import division
7+from __future__ import print_function
8+
79 import os
810 import sys
911 import struct
@@ -31,21 +33,23 @@ def parse_iomem(): · 21 unmodified lines
3133 for i, j in enumerate(f):
3234 m = re.split('-|:',j,2)
3335 if m[2].strip() == 'System RAM':
34− system_ram.append(long(m[0], 16))
35− system_ram.append(long(m[1], 16))
36+ system_ram.append(int(m[0], 16))
37+ system_ram.append(int(m[1], 16))
3638 if m[2].strip() == 'Persistent Memory':
37− pmem.append(long(m[0], 16))
38− pmem.append(long(m[1], 16))
39+ pmem.append(int(m[0], 16))
40+ pmem.append(int(m[1], 16))
3941
4042 def print_memory_type():
41− print "Event: %s" % (event_name)
42− print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"),
43− print "%-40s %10s %10s\n" % ("----------------------------------------", \
43+ print("Event: %s" % (event_name))
44+ print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), end='')
45+ print("%-40s %10s %10s\n" % ("----------------------------------------",
4446 "-----------", "-----------"),
47+ end='');
4548 total = sum(load_mem_type_cnt.values())
4649 for mem_type, count in sorted(load_mem_type_cnt.most_common(), \
47− key = lambda(k, v): (v, k), reverse = True):
48− print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total),
50+ key = lambda kv: (kv[1], kv[0]), reverse = True):
51+ print("%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total),
52+ end='')
4953
5054 def trace_begin():
5155 parse_iomem()
@@ -80,7 +84,7 @@ def find_memory_type(phys_addr): · 28 unmodified lines
8084 f.seek(0, 0)
8185 for j in f:
8286 m = re.split('-|:',j,2)
83− if long(m[0], 16) <= phys_addr <= long(m[1], 16):
87+ if int(m[0], 16) <= phys_addr <= int(m[1], 16):
8488 return m[2]
8589 return "N/A"
8690