aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/mem-phys-addr.py
diff options
context:
space:
mode:
authorTony Jones <tonyj@suse.de>2019-02-22 18:06:11 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-02-25 15:16:51 -0500
commite4d053ddb4c48cbde27b4c5edd3cc8f957684e4f (patch)
treeacc46f1758db146f8584d55c9c7ab7c5f38879f2 /tools/perf/scripts/python/mem-phys-addr.py
parent9b2700efc57f46fe63beee5f64fcfe2746936b4e (diff)
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 Signed-off-by: Tony Jones <tonyj@suse.de> Link: http://lkml.kernel.org/r/20190222230619.17887-8-tonyj@suse.de Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts/python/mem-phys-addr.py')
-rw-r--r--tools/perf/scripts/python/mem-phys-addr.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py
index ebee2c5ae496..fb0bbcbfa0f0 100644
--- a/tools/perf/scripts/python/mem-phys-addr.py
+++ b/tools/perf/scripts/python/mem-phys-addr.py
@@ -4,6 +4,8 @@
4# Copyright (c) 2018, Intel Corporation. 4# Copyright (c) 2018, Intel Corporation.
5 5
6from __future__ import division 6from __future__ import division
7from __future__ import print_function
8
7import os 9import os
8import sys 10import sys
9import struct 11import struct
@@ -31,21 +33,23 @@ def parse_iomem():
31 for i, j in enumerate(f): 33 for i, j in enumerate(f):
32 m = re.split('-|:',j,2) 34 m = re.split('-|:',j,2)
33 if m[2].strip() == 'System RAM': 35 if m[2].strip() == 'System RAM':
34 system_ram.append(long(m[0], 16)) 36 system_ram.append(int(m[0], 16))
35 system_ram.append(long(m[1], 16)) 37 system_ram.append(int(m[1], 16))
36 if m[2].strip() == 'Persistent Memory': 38 if m[2].strip() == 'Persistent Memory':
37 pmem.append(long(m[0], 16)) 39 pmem.append(int(m[0], 16))
38 pmem.append(long(m[1], 16)) 40 pmem.append(int(m[1], 16))
39 41
40def print_memory_type(): 42def print_memory_type():
41 print "Event: %s" % (event_name) 43 print("Event: %s" % (event_name))
42 print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), 44 print("%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), end='')
43 print "%-40s %10s %10s\n" % ("----------------------------------------", \ 45 print("%-40s %10s %10s\n" % ("----------------------------------------",
44 "-----------", "-----------"), 46 "-----------", "-----------"),
47 end='');
45 total = sum(load_mem_type_cnt.values()) 48 total = sum(load_mem_type_cnt.values())
46 for mem_type, count in sorted(load_mem_type_cnt.most_common(), \ 49 for mem_type, count in sorted(load_mem_type_cnt.most_common(), \
47 key = lambda(k, v): (v, k), reverse = True): 50 key = lambda kv: (kv[1], kv[0]), reverse = True):
48 print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total), 51 print("%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total),
52 end='')
49 53
50def trace_begin(): 54def trace_begin():
51 parse_iomem() 55 parse_iomem()
@@ -80,7 +84,7 @@ def find_memory_type(phys_addr):
80 f.seek(0, 0) 84 f.seek(0, 0)
81 for j in f: 85 for j in f:
82 m = re.split('-|:',j,2) 86 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):
84 return m[2] 88 return m[2]
85 return "N/A" 89 return "N/A"
86 90