All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/15] perf script python: add Python3 support
@ 2019-02-22 23:06 Tony Jones
  2019-02-22 23:06 ` [PATCH 01/15] perf script python: add Python3 support to netdev-times.py Tony Jones
                   ` (15 more replies)
  0 siblings, 16 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme

The following patches add Python3 support to the remainder of 
the scripts under scripts/python.

Minimum supported Python version is now v2.6

I tested everything against v2.7 (no patch), v2.7 (patch) and 
v3.7 (patch).  Seeteena also tested a subset (no SQL, no IPT) 
against v2.6

There are changes in order of output as key ordering is not 
consistent between v2 and v3 but format of each line should be 
unchanged.



^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 01/15] perf script python: add Python3 support to netdev-times.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-28  8:06   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py Tony Jones
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Koki Sanagi

Support both Python2 and Python3 in the netdev-times.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Koki Sanagi <sanagi.koki@jp.fujitsu.com>
---
 tools/perf/scripts/python/netdev-times.py | 82 ++++++++++++-----------
 1 file changed, 42 insertions(+), 40 deletions(-)

diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py
index 9b2050f778f1..267bda49325d 100644
--- a/tools/perf/scripts/python/netdev-times.py
+++ b/tools/perf/scripts/python/netdev-times.py
@@ -8,6 +8,8 @@
 # dev=: show only thing related to specified device
 # debug: work with debug mode. It shows buffer status.
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -17,6 +19,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 from perf_trace_context import *
 from Core import *
 from Util import *
+from functools import cmp_to_key
 
 all_event_list = []; # insert all tracepoint event related with this script
 irq_dic = {}; # key is cpu and value is a list which stacks irqs
@@ -61,12 +64,12 @@ def diff_msec(src, dst):
 def print_transmit(hunk):
 	if dev != 0 and hunk['dev'].find(dev) < 0:
 		return
-	print "%7s %5d %6d.%06dsec %12.3fmsec      %12.3fmsec" % \
+	print("%7s %5d %6d.%06dsec %12.3fmsec      %12.3fmsec" %
 		(hunk['dev'], hunk['len'],
 		nsecs_secs(hunk['queue_t']),
 		nsecs_nsecs(hunk['queue_t'])/1000,
 		diff_msec(hunk['queue_t'], hunk['xmit_t']),
-		diff_msec(hunk['xmit_t'], hunk['free_t']))
+		diff_msec(hunk['xmit_t'], hunk['free_t'])))
 
 # Format for displaying rx packet processing
 PF_IRQ_ENTRY= "  irq_entry(+%.3fmsec irq=%d:%s)"
@@ -98,55 +101,55 @@ def print_receive(hunk):
 	if show_hunk == 0:
 		return
 
-	print "%d.%06dsec cpu=%d" % \
-		(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)
+	print("%d.%06dsec cpu=%d" %
+		(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu))
 	for i in range(len(irq_list)):
-		print PF_IRQ_ENTRY % \
+		print(PF_IRQ_ENTRY %
 			(diff_msec(base_t, irq_list[i]['irq_ent_t']),
-			irq_list[i]['irq'], irq_list[i]['name'])
-		print PF_JOINT
+			irq_list[i]['irq'], irq_list[i]['name']))
+		print(PF_JOINT)
 		irq_event_list = irq_list[i]['event_list']
 		for j in range(len(irq_event_list)):
 			irq_event = irq_event_list[j]
 			if irq_event['event'] == 'netif_rx':
-				print PF_NET_RX % \
+				print(PF_NET_RX %
 					(diff_msec(base_t, irq_event['time']),
-					irq_event['skbaddr'])
-				print PF_JOINT
-	print PF_SOFT_ENTRY % \
-		diff_msec(base_t, hunk['sirq_ent_t'])
-	print PF_JOINT
+					irq_event['skbaddr']))
+				print(PF_JOINT)
+	print(PF_SOFT_ENTRY %
+		diff_msec(base_t, hunk['sirq_ent_t']))
+	print(PF_JOINT)
 	event_list = hunk['event_list']
 	for i in range(len(event_list)):
 		event = event_list[i]
 		if event['event_name'] == 'napi_poll':
-			print PF_NAPI_POLL % \
-			    (diff_msec(base_t, event['event_t']), event['dev'])
+			print(PF_NAPI_POLL %
+			    (diff_msec(base_t, event['event_t']), event['dev']))
 			if i == len(event_list) - 1:
-				print ""
+				print("")
 			else:
-				print PF_JOINT
+				print(PF_JOINT)
 		else:
-			print PF_NET_RECV % \
+			print(PF_NET_RECV %
 			    (diff_msec(base_t, event['event_t']), event['skbaddr'],
-				event['len'])
+				event['len']))
 			if 'comm' in event.keys():
-				print PF_WJOINT
-				print PF_CPY_DGRAM % \
+				print(PF_WJOINT)
+				print(PF_CPY_DGRAM %
 					(diff_msec(base_t, event['comm_t']),
-					event['pid'], event['comm'])
+					event['pid'], event['comm']))
 			elif 'handle' in event.keys():
-				print PF_WJOINT
+				print(PF_WJOINT)
 				if event['handle'] == "kfree_skb":
-					print PF_KFREE_SKB % \
+					print(PF_KFREE_SKB %
 						(diff_msec(base_t,
 						event['comm_t']),
-						event['location'])
+						event['location']))
 				elif event['handle'] == "consume_skb":
-					print PF_CONS_SKB % \
+					print(PF_CONS_SKB %
 						diff_msec(base_t,
-							event['comm_t'])
-			print PF_JOINT
+							event['comm_t']))
+			print(PF_JOINT)
 
 def trace_begin():
 	global show_tx
@@ -172,8 +175,7 @@ def trace_begin():
 
 def trace_end():
 	# order all events in time
-	all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME],
-					    b[EINFO_IDX_TIME]))
+	all_event_list.sort(key=cmp_to_key(lambda a,b :a[EINFO_IDX_TIME] < b[EINFO_IDX_TIME]))
 	# process all events
 	for i in range(len(all_event_list)):
 		event_info = all_event_list[i]
@@ -210,19 +212,19 @@ def trace_end():
 			print_receive(receive_hunk_list[i])
 	# display transmit hunks
 	if show_tx:
-		print "   dev    len      Qdisc        " \
-			"       netdevice             free"
+		print("   dev    len      Qdisc        "
+			"       netdevice             free")
 		for i in range(len(tx_free_list)):
 			print_transmit(tx_free_list[i])
 	if debug:
-		print "debug buffer status"
-		print "----------------------------"
-		print "xmit Qdisc:remain:%d overflow:%d" % \
-			(len(tx_queue_list), of_count_tx_queue_list)
-		print "xmit netdevice:remain:%d overflow:%d" % \
-			(len(tx_xmit_list), of_count_tx_xmit_list)
-		print "receive:remain:%d overflow:%d" % \
-			(len(rx_skb_list), of_count_rx_skb_list)
+		print("debug buffer status")
+		print("----------------------------")
+		print("xmit Qdisc:remain:%d overflow:%d" %
+			(len(tx_queue_list), of_count_tx_queue_list))
+		print("xmit netdevice:remain:%d overflow:%d" %
+			(len(tx_xmit_list), of_count_tx_xmit_list))
+		print("receive:remain:%d overflow:%d" %
+			(len(rx_skb_list), of_count_rx_skb_list))
 
 # called from perf, when it finds a correspoinding event
 def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec):
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
  2019-02-22 23:06 ` [PATCH 01/15] perf script python: add Python3 support to netdev-times.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:05   ` Arnaldo Carvalho de Melo
  2019-02-22 23:06 ` [PATCH 03/15] perf script python: add Python3 support to event_analyzing_sample.py Tony Jones
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Tom Zanussi

Support both Python 2 and Python 3 in the check-perf-trace.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.

Also correct inconsistent indentation which was being flagged by Python3.

The use of from __future__ implies the minimum supported version of
Python2 is now v2.6

Signed-off-by: Tony Jones <tonyj@suse.de>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/scripts/python/check-perf-trace.py | 68 ++++++++++---------
 1 file changed, 36 insertions(+), 32 deletions(-)

diff --git a/tools/perf/scripts/python/check-perf-trace.py b/tools/perf/scripts/python/check-perf-trace.py
index 334599c6032c..2851cf0e6b4b 100644
--- a/tools/perf/scripts/python/check-perf-trace.py
+++ b/tools/perf/scripts/python/check-perf-trace.py
@@ -7,11 +7,13 @@
 # events, etc.  Basically, if this script runs successfully and
 # displays expected results, Python scripting support should be ok.
 
+from __future__ import print_function
+
 import os
 import sys
 
-sys.path.append(os.environ['PERF_EXEC_PATH'] + \
-	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+sys.path.append(os.environ['PERF_EXEC_PATH'] +
+    '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
 
 from Core import *
 from perf_trace_context import *
@@ -19,37 +21,38 @@ from perf_trace_context import *
 unhandled = autodict()
 
 def trace_begin():
-	print "trace_begin"
-	pass
+    print("trace_begin")
+    pass
 
 def trace_end():
-        print_unhandled()
+    print_unhandled()
 
 def irq__softirq_entry(event_name, context, common_cpu,
-	common_secs, common_nsecs, common_pid, common_comm,
-	common_callchain, vec):
-		print_header(event_name, common_cpu, common_secs, common_nsecs,
-			common_pid, common_comm)
+    common_secs, common_nsecs, common_pid, common_comm,
+    common_callchain, vec):
+
+    print_header(event_name, common_cpu, common_secs, common_nsecs,
+        common_pid, common_comm)
 
-                print_uncommon(context)
+    print_uncommon(context)
 
-		print "vec=%s\n" % \
-		(symbol_str("irq__softirq_entry", "vec", vec)),
+    print("vec=%s" %
+        (symbol_str("irq__softirq_entry", "vec", vec)))
 
 def kmem__kmalloc(event_name, context, common_cpu,
-	common_secs, common_nsecs, common_pid, common_comm,
-	common_callchain, call_site, ptr, bytes_req, bytes_alloc,
-	gfp_flags):
-		print_header(event_name, common_cpu, common_secs, common_nsecs,
-			common_pid, common_comm)
+    common_secs, common_nsecs, common_pid, common_comm,
+    common_callchain, call_site, ptr, bytes_req, bytes_alloc,
+    gfp_flags):
 
-                print_uncommon(context)
+    print_header(event_name, common_cpu, common_secs, common_nsecs,
+        common_pid, common_comm)
 
-		print "call_site=%u, ptr=%u, bytes_req=%u, " \
-		"bytes_alloc=%u, gfp_flags=%s\n" % \
-		(call_site, ptr, bytes_req, bytes_alloc,
+    print_uncommon(context)
 
-		flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
+    print("call_site=%u, ptr=%u, bytes_req=%u, "
+        "bytes_alloc=%u, gfp_flags=%s\n" %
+        (call_site, ptr, bytes_req, bytes_alloc,
+        flag_str("kmem__kmalloc", "gfp_flags", gfp_flags))),
 
 def trace_unhandled(event_name, context, event_fields_dict):
     try:
@@ -58,25 +61,26 @@ def trace_unhandled(event_name, context, event_fields_dict):
         unhandled[event_name] = 1
 
 def print_header(event_name, cpu, secs, nsecs, pid, comm):
-	print "%-20s %5u %05u.%09u %8u %-20s " % \
-	(event_name, cpu, secs, nsecs, pid, comm),
+    print("%-20s %5u %05u.%09u %8u %-20s " %
+        (event_name, cpu, secs, nsecs, pid, comm),
+                end='')
 
 # print trace fields not included in handler args
 def print_uncommon(context):
-    print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
-        % (common_pc(context), trace_flag_str(common_flags(context)), \
-               common_lock_depth(context))
+    print("common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " %
+        (common_pc(context), trace_flag_str(common_flags(context)),
+        common_lock_depth(context))),
 
 def print_unhandled():
     keys = unhandled.keys()
     if not keys:
         return
 
-    print "\nunhandled events:\n\n",
+    print("\nunhandled events:\n")
 
-    print "%-40s  %10s\n" % ("event", "count"),
-    print "%-40s  %10s\n" % ("----------------------------------------", \
-                                 "-----------"),
+    print("%-40s  %10s" % ("event", "count"))
+    print("%-40s  %10s" % ("----------------------------------------",
+                 "-----------"))
 
     for event_name in keys:
-	print "%-40s  %10d\n" % (event_name, unhandled[event_name])
+        print("%-40s  %10d\n" % (event_name, unhandled[event_name]))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 03/15] perf script python: add Python3 support to event_analyzing_sample.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
  2019-02-22 23:06 ` [PATCH 01/15] perf script python: add Python3 support to netdev-times.py Tony Jones
  2019-02-22 23:06 ` [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:08   ` Arnaldo Carvalho de Melo
  2019-02-22 23:06 ` [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py Tony Jones
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek

Support both Python2 and Python3 in the event_analyzing_sample.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
---
 .../scripts/python/event_analyzing_sample.py  | 48 ++++++++++---------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/tools/perf/scripts/python/event_analyzing_sample.py b/tools/perf/scripts/python/event_analyzing_sample.py
index 4e843b9864ec..f4c4c7963451 100644
--- a/tools/perf/scripts/python/event_analyzing_sample.py
+++ b/tools/perf/scripts/python/event_analyzing_sample.py
@@ -15,6 +15,8 @@
 # for a x86 HW PMU event: PEBS with load latency data.
 #
 
+from __future__ import print_function
+
 import os
 import sys
 import math
@@ -37,7 +39,7 @@ con = sqlite3.connect("/dev/shm/perf.db")
 con.isolation_level = None
 
 def trace_begin():
-	print "In trace_begin:\n"
+        print("In trace_begin:\n")
 
         #
         # Will create several tables at the start, pebs_ll is for PEBS data with
@@ -76,12 +78,12 @@ def process_event(param_dict):
         name       = param_dict["ev_name"]
 
         # Symbol and dso info are not always resolved
-        if (param_dict.has_key("dso")):
+        if ("dso" in param_dict):
                 dso = param_dict["dso"]
         else:
                 dso = "Unknown_dso"
 
-        if (param_dict.has_key("symbol")):
+        if ("symbol" in param_dict):
                 symbol = param_dict["symbol"]
         else:
                 symbol = "Unknown_symbol"
@@ -102,7 +104,7 @@ def insert_db(event):
                                 event.ip, event.status, event.dse, event.dla, event.lat))
 
 def trace_end():
-	print "In trace_end:\n"
+        print("In trace_end:\n")
         # We show the basic info for the 2 type of event classes
         show_general_events()
         show_pebs_ll()
@@ -123,29 +125,29 @@ def show_general_events():
         # Check the total record number in the table
         count = con.execute("select count(*) from gen_events")
         for t in count:
-                print "There is %d records in gen_events table" % t[0]
+                print("There is %d records in gen_events table" % t[0])
                 if t[0] == 0:
                         return
 
-        print "Statistics about the general events grouped by thread/symbol/dso: \n"
+        print("Statistics about the general events grouped by thread/symbol/dso: \n")
 
          # Group by thread
         commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)")
-        print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
+        print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42))
         for row in commq:
-             print "%16s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%16s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
         # Group by symbol
-        print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
+        print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58))
         symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)")
         for row in symbolq:
-             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
         # Group by dso
-        print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)
+        print("\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74))
         dsoq = con.execute("select dso, count(dso) from gen_events group by dso order by -count(dso)")
         for row in dsoq:
-             print "%40s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%40s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
 #
 # This function just shows the basic info, and we could do more with the
@@ -156,35 +158,35 @@ def show_pebs_ll():
 
         count = con.execute("select count(*) from pebs_ll")
         for t in count:
-                print "There is %d records in pebs_ll table" % t[0]
+                print("There is %d records in pebs_ll table" % t[0])
                 if t[0] == 0:
                         return
 
-        print "Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n"
+        print("Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n")
 
         # Group by thread
         commq = con.execute("select comm, count(comm) from pebs_ll group by comm order by -count(comm)")
-        print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
+        print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42))
         for row in commq:
-             print "%16s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%16s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
         # Group by symbol
-        print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
+        print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58))
         symbolq = con.execute("select symbol, count(symbol) from pebs_ll group by symbol order by -count(symbol)")
         for row in symbolq:
-             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
         # Group by dse
         dseq = con.execute("select dse, count(dse) from pebs_ll group by dse order by -count(dse)")
-        print "\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58)
+        print("\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58))
         for row in dseq:
-             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
         # Group by latency
         latq = con.execute("select lat, count(lat) from pebs_ll group by lat order by lat")
-        print "\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58)
+        print("\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58))
         for row in latq:
-             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
+             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
 
 def trace_unhandled(event_name, context, event_fields_dict):
-		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
+        print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (2 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 03/15] perf script python: add Python3 support to event_analyzing_sample.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:09   ` Arnaldo Carvalho de Melo
  2019-02-28  8:06   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 05/15] perf script python: add Python3 support to futex-contention.py Tony Jones
                   ` (11 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Tom Zanussi

Support both Python2 and Python3 in the failed-syscalls-by-pid.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
---
 .../scripts/python/failed-syscalls-by-pid.py  | 21 ++++++++++---------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py
index cafeff3d74db..3648e8b986ec 100644
--- a/tools/perf/scripts/python/failed-syscalls-by-pid.py
+++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py
@@ -5,6 +5,8 @@
 # Displays system-wide failed system call totals, broken down by pid.
 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -32,7 +34,7 @@ if len(sys.argv) > 1:
 syscalls = autodict()
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	print_error_totals()
@@ -57,22 +59,21 @@ def syscalls__sys_exit(event_name, context, common_cpu,
 
 def print_error_totals():
     if for_comm is not None:
-	    print "\nsyscall errors for %s:\n\n" % (for_comm),
+	    print("\nsyscall errors for %s:\n" % (for_comm))
     else:
-	    print "\nsyscall errors:\n\n",
+	    print("\nsyscall errors:\n")
 
-    print "%-30s  %10s\n" % ("comm [pid]", "count"),
-    print "%-30s  %10s\n" % ("------------------------------", \
-                                 "----------"),
+    print("%-30s  %10s" % ("comm [pid]", "count"))
+    print("%-30s  %10s" % ("------------------------------", "----------"))
 
     comm_keys = syscalls.keys()
     for comm in comm_keys:
 	    pid_keys = syscalls[comm].keys()
 	    for pid in pid_keys:
-		    print "\n%s [%d]\n" % (comm, pid),
+		    print("\n%s [%d]" % (comm, pid))
 		    id_keys = syscalls[comm][pid].keys()
 		    for id in id_keys:
-			    print "  syscall: %-16s\n" % syscall_name(id),
+			    print("  syscall: %-16s" % syscall_name(id))
 			    ret_keys = syscalls[comm][pid][id].keys()
-			    for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k),  reverse = True):
-				    print "    err = %-20s  %10d\n" % (strerror(ret), val),
+			    for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]),  reverse = True):
+				    print("    err = %-20s  %10d" % (strerror(ret), val))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 05/15] perf script python: add Python3 support to futex-contention.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (3 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-22 23:06 ` [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py Tony Jones
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek,
	Arnaldo Carvalho de Melo

Support both Python2 and Python3 in the futex-contention.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/futex-contention.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/futex-contention.py b/tools/perf/scripts/python/futex-contention.py
index 0f5cf437b602..665a9d5355b8 100644
--- a/tools/perf/scripts/python/futex-contention.py
+++ b/tools/perf/scripts/python/futex-contention.py
@@ -10,6 +10,8 @@
 #
 # Measures futex contention
 
+from __future__ import print_function
+
 import os, sys
 sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
 from Util import *
@@ -33,18 +35,18 @@ def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain,
 
 def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain,
 			     nr, ret):
-	if thread_blocktime.has_key(tid):
+	if tid in thread_blocktime:
 		elapsed = nsecs(s, ns) - thread_blocktime[tid]
 		add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
 		del thread_blocktime[tid]
 		del thread_thislock[tid]
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	for (tid, lock) in lock_waits:
 		min, max, avg, count = lock_waits[tid, lock]
-		print "%s[%d] lock %x contended %d times, %d avg ns" % \
-		      (process_names[tid], tid, lock, count, avg)
+		print("%s[%d] lock %x contended %d times, %d avg ns" %
+		      (process_names[tid], tid, lock, count, avg))
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (4 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 05/15] perf script python: add Python3 support to futex-contention.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25  7:07   ` Adrian Hunter
  2019-02-22 23:06 ` [PATCH 07/15] perf script python: add Python3 support to mem-phys-addr.py Tony Jones
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Adrian Hunter

Support both Python2 and Python3 in the intel-pt-events.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.

Fix space/tab inconsistency as python3 enforces consistency.

The use of 'from __future__' implies the minimum supported Python2 version
is now v2.6

Signed-off-by: Tony Jones <tonyj@suse.de>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/scripts/python/intel-pt-events.py | 138 ++++++++++---------
 1 file changed, 70 insertions(+), 68 deletions(-)

diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
index b19172d673af..aef54566af61 100644
--- a/tools/perf/scripts/python/intel-pt-events.py
+++ b/tools/perf/scripts/python/intel-pt-events.py
@@ -10,79 +10,81 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
+from __future__ import print_function
+
 import os
 import sys
 import struct
 
 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
-	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+        '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
 
 # These perf imports are not used at present
 #from perf_trace_context import *
 #from Core import *
 
 def trace_begin():
-	print "Intel PT Power Events and PTWRITE"
+        print("Intel PT Power Events and PTWRITE")
 
 def trace_end():
-	print "End"
+        print("End")
 
 def trace_unhandled(event_name, context, event_fields_dict):
-		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
+        print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
 
 def print_ptwrite(raw_buf):
-	data = struct.unpack_from("<IQ", raw_buf)
-	flags = data[0]
-	payload = data[1]
-	exact_ip = flags & 1
-	print "IP: %u payload: %#x" % (exact_ip, payload),
+        data = struct.unpack_from("<IQ", raw_buf)
+        flags = data[0]
+        payload = data[1]
+        exact_ip = flags & 1
+        print("IP: %u payload: %#x" % (exact_ip, payload), end='')
 
 def print_cbr(raw_buf):
-	data = struct.unpack_from("<BBBBII", raw_buf)
-	cbr = data[0]
-	f = (data[4] + 500) / 1000
-	p = ((cbr * 1000 / data[2]) + 5) / 10
-	print "%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p),
+        data = struct.unpack_from("<BBBBII", raw_buf)
+        cbr = data[0]
+        f = (data[4] + 500) / 1000
+        p = ((cbr * 1000 / data[2]) + 5) / 10
+        print("%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p), end='')
 
 def print_mwait(raw_buf):
-	data = struct.unpack_from("<IQ", raw_buf)
-	payload = data[1]
-	hints = payload & 0xff
-	extensions = (payload >> 32) & 0x3
-	print "hints: %#x extensions: %#x" % (hints, extensions),
+        data = struct.unpack_from("<IQ", raw_buf)
+        payload = data[1]
+        hints = payload & 0xff
+        extensions = (payload >> 32) & 0x3
+        print("hints: %#x extensions: %#x" % (hints, extensions), end='')
 
 def print_pwre(raw_buf):
-	data = struct.unpack_from("<IQ", raw_buf)
-	payload = data[1]
-	hw = (payload >> 7) & 1
-	cstate = (payload >> 12) & 0xf
-	subcstate = (payload >> 8) & 0xf
-	print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
+        data = struct.unpack_from("<IQ", raw_buf)
+        payload = data[1]
+        hw = (payload >> 7) & 1
+        cstate = (payload >> 12) & 0xf
+        subcstate = (payload >> 8) & 0xf
+        print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), end='')
 
 def print_exstop(raw_buf):
-	data = struct.unpack_from("<I", raw_buf)
-	flags = data[0]
-	exact_ip = flags & 1
-	print "IP: %u" % (exact_ip),
+        data = struct.unpack_from("<I", raw_buf)
+        flags = data[0]
+        exact_ip = flags & 1
+        print("IP: %u" % (exact_ip), end='')
 
 def print_pwrx(raw_buf):
-	data = struct.unpack_from("<IQ", raw_buf)
-	payload = data[1]
-	deepest_cstate = payload & 0xf
-	last_cstate = (payload >> 4) & 0xf
-	wake_reason = (payload >> 8) & 0xf
-	print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason),
+        data = struct.unpack_from("<IQ", raw_buf)
+        payload = data[1]
+        deepest_cstate = payload & 0xf
+        last_cstate = (payload >> 4) & 0xf
+        wake_reason = (payload >> 8) & 0xf
+        print("deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), end='')
 
 def print_common_start(comm, sample, name):
-	ts = sample["time"]
-	cpu = sample["cpu"]
-	pid = sample["pid"]
-	tid = sample["tid"]
-	print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
+        ts = sample["time"]
+        cpu = sample["cpu"]
+        pid = sample["pid"]
+        tid = sample["tid"]
+        print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), end='')
 
 def print_common_ip(sample, symbol, dso):
-	ip = sample["ip"]
-	print "%16x %s (%s)" % (ip, symbol, dso)
+        ip = sample["ip"]
+        print("%16x %s (%s)" % (ip, symbol, dso))
 
 def process_event(param_dict):
         event_attr = param_dict["attr"]
@@ -92,37 +94,37 @@ def process_event(param_dict):
         name       = param_dict["ev_name"]
 
         # Symbol and dso info are not always resolved
-        if (param_dict.has_key("dso")):
+        if "dso" in param_dict:
                 dso = param_dict["dso"]
         else:
                 dso = "[unknown]"
 
-        if (param_dict.has_key("symbol")):
+        if "symbol" in param_dict:
                 symbol = param_dict["symbol"]
         else:
                 symbol = "[unknown]"
 
-	if name == "ptwrite":
-		print_common_start(comm, sample, name)
-		print_ptwrite(raw_buf)
-		print_common_ip(sample, symbol, dso)
-	elif name == "cbr":
-		print_common_start(comm, sample, name)
-		print_cbr(raw_buf)
-		print_common_ip(sample, symbol, dso)
-	elif name == "mwait":
-		print_common_start(comm, sample, name)
-		print_mwait(raw_buf)
-		print_common_ip(sample, symbol, dso)
-	elif name == "pwre":
-		print_common_start(comm, sample, name)
-		print_pwre(raw_buf)
-		print_common_ip(sample, symbol, dso)
-	elif name == "exstop":
-		print_common_start(comm, sample, name)
-		print_exstop(raw_buf)
-		print_common_ip(sample, symbol, dso)
-	elif name == "pwrx":
-		print_common_start(comm, sample, name)
-		print_pwrx(raw_buf)
-		print_common_ip(sample, symbol, dso)
+        if name == "ptwrite":
+                print_common_start(comm, sample, name)
+                print_ptwrite(raw_buf)
+                print_common_ip(sample, symbol, dso)
+        elif name == "cbr":
+                print_common_start(comm, sample, name)
+                print_cbr(raw_buf)
+                print_common_ip(sample, symbol, dso)
+        elif name == "mwait":
+                print_common_start(comm, sample, name)
+                print_mwait(raw_buf)
+                print_common_ip(sample, symbol, dso)
+        elif name == "pwre":
+                print_common_start(comm, sample, name)
+                print_pwre(raw_buf)
+                print_common_ip(sample, symbol, dso)
+        elif name == "exstop":
+                print_common_start(comm, sample, name)
+                print_exstop(raw_buf)
+                print_common_ip(sample, symbol, dso)
+        elif name == "pwrx":
+                print_common_start(comm, sample, name)
+                print_pwrx(raw_buf)
+                print_common_ip(sample, symbol, dso)
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 07/15] perf script python: add Python3 support to mem-phys-addr.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (5 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-28  8:07   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py Tony Jones
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek

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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
---
 tools/perf/scripts/python/mem-phys-addr.py | 24 +++++++++++++---------
 1 file 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 @@
 # Copyright (c) 2018, Intel Corporation.
 
 from __future__ import division
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -31,21 +33,23 @@ def parse_iomem():
 	for i, j in enumerate(f):
 		m = re.split('-|:',j,2)
 		if m[2].strip() == 'System RAM':
-			system_ram.append(long(m[0], 16))
-			system_ram.append(long(m[1], 16))
+			system_ram.append(int(m[0], 16))
+			system_ram.append(int(m[1], 16))
 		if m[2].strip() == 'Persistent Memory':
-			pmem.append(long(m[0], 16))
-			pmem.append(long(m[1], 16))
+			pmem.append(int(m[0], 16))
+			pmem.append(int(m[1], 16))
 
 def print_memory_type():
-	print "Event: %s" % (event_name)
-	print "%-40s  %10s  %10s\n" % ("Memory type", "count", "percentage"),
-	print "%-40s  %10s  %10s\n" % ("----------------------------------------", \
+	print("Event: %s" % (event_name))
+	print("%-40s  %10s  %10s\n" % ("Memory type", "count", "percentage"), end='')
+	print("%-40s  %10s  %10s\n" % ("----------------------------------------",
 					"-----------", "-----------"),
+                                        end='');
 	total = sum(load_mem_type_cnt.values())
 	for mem_type, count in sorted(load_mem_type_cnt.most_common(), \
-					key = lambda(k, v): (v, k), reverse = True):
-		print "%-40s  %10d  %10.1f%%\n" % (mem_type, count, 100 * count / total),
+					key = lambda kv: (kv[1], kv[0]), reverse = True):
+		print("%-40s  %10d  %10.1f%%\n" % (mem_type, count, 100 * count / total),
+                        end='')
 
 def trace_begin():
 	parse_iomem()
@@ -80,7 +84,7 @@ def find_memory_type(phys_addr):
 	f.seek(0, 0)
 	for j in f:
 		m = re.split('-|:',j,2)
-		if long(m[0], 16) <= phys_addr <= long(m[1], 16):
+		if int(m[0], 16) <= phys_addr <= int(m[1], 16):
 			return m[2]
 	return "N/A"
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (6 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 07/15] perf script python: add Python3 support to mem-phys-addr.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 12:37   ` Neil Horman
  2019-02-28  8:08   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py Tony Jones
                   ` (7 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Neil Horman

Support both Python2 and Python3 in the net_dropmonitor.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
---
 tools/perf/scripts/python/net_dropmonitor.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py
index a150164b44a3..212557a02c50 100755
--- a/tools/perf/scripts/python/net_dropmonitor.py
+++ b/tools/perf/scripts/python/net_dropmonitor.py
@@ -1,6 +1,8 @@
 # Monitor the system for dropped packets and proudce a report of drop locations and counts
 # SPDX-License-Identifier: GPL-2.0
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -50,19 +52,19 @@ def get_sym(sloc):
 		return (None, 0)
 
 def print_drop_table():
-	print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
+	print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
 	for i in drop_log.keys():
 		(sym, off) = get_sym(i)
 		if sym == None:
 			sym = i
-		print "%25s %25s %25s" % (sym, off, drop_log[i])
+		print("%25s %25s %25s" % (sym, off, drop_log[i]))
 
 
 def trace_begin():
-	print "Starting trace (Ctrl-C to dump results)"
+	print("Starting trace (Ctrl-C to dump results)")
 
 def trace_end():
-	print "Gathering kallsyms data"
+	print("Gathering kallsyms data")
 	get_kallsyms_table()
 	print_drop_table()
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (7 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:44   ` Arnaldo Carvalho de Melo
  2019-02-28  8:08   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 10/15] perf script python: add Python3 support to sctop.py Tony Jones
                   ` (6 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Ravi Bangoria

Support both Python2 and Python3 in the powerpc-hcalls.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
---
 tools/perf/scripts/python/powerpc-hcalls.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py
index 00e0e7476e55..8b78dc790adb 100644
--- a/tools/perf/scripts/python/powerpc-hcalls.py
+++ b/tools/perf/scripts/python/powerpc-hcalls.py
@@ -4,6 +4,8 @@
 #
 # Hypervisor call statisics
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -149,7 +151,7 @@ hcall_table = {
 }
 
 def hcall_table_lookup(opcode):
-	if (hcall_table.has_key(opcode)):
+	if (opcode in hcall_table):
 		return hcall_table[opcode]
 	else:
 		return opcode
@@ -157,8 +159,8 @@ def hcall_table_lookup(opcode):
 print_ptrn = '%-28s%10s%10s%10s%10s'
 
 def trace_end():
-	print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')
-	print '-' * 68
+	print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)'))
+	print('-' * 68)
 	for opcode in output:
 		h_name = hcall_table_lookup(opcode)
 		time = output[opcode]['time']
@@ -166,14 +168,14 @@ def trace_end():
 		min_t = output[opcode]['min']
 		max_t = output[opcode]['max']
 
-		print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt)
+		print(print_ptrn % (h_name, cnt, min_t, max_t, time//cnt))
 
 def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
 			opcode, retval):
-	if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)):
+	if (cpu in d_enter and opcode in d_enter[cpu]):
 		diff = nsecs(sec, nsec) - d_enter[cpu][opcode]
 
-		if (output.has_key(opcode)):
+		if (opcode in output):
 			output[opcode]['time'] += diff
 			output[opcode]['cnt'] += 1
 			if (output[opcode]['min'] > diff):
@@ -190,11 +192,11 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
 
 		del d_enter[cpu][opcode]
 #	else:
-#		print "Can't find matching hcall_enter event. Ignoring sample"
+#		print("Can't find matching hcall_enter event. Ignoring sample")
 
 def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm,
 			 callchain, opcode):
-		if (d_enter.has_key(cpu)):
+		if (cpu in d_enter):
 			d_enter[cpu][opcode] = nsecs(sec, nsec)
 		else:
 			d_enter[cpu] = {opcode: nsecs(sec, nsec)}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 10/15] perf script python: add Python3 support to sctop.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (8 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:44   ` Arnaldo Carvalho de Melo
  2019-02-28  8:09   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py Tony Jones
                   ` (5 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Tom Zanussi

Support both Python2 and Python3 in the sctop.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/scripts/python/sctop.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py
index 61621b93affb..987ffae7c8ca 100644
--- a/tools/perf/scripts/python/sctop.py
+++ b/tools/perf/scripts/python/sctop.py
@@ -8,7 +8,14 @@
 # will be refreshed every [interval] seconds.  The default interval is
 # 3 seconds.
 
-import os, sys, thread, time
+from __future__ import print_function
+
+import os, sys, time
+
+try:
+        import thread
+except ImportError:
+        import _thread as thread
 
 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -62,18 +69,19 @@ def print_syscall_totals(interval):
 	while 1:
 		clear_term()
 		if for_comm is not None:
-			print "\nsyscall events for %s:\n\n" % (for_comm),
+			print("\nsyscall events for %s:\n" % (for_comm))
 		else:
-			print "\nsyscall events:\n\n",
+			print("\nsyscall events:\n")
 
-		print "%-40s  %10s\n" % ("event", "count"),
-		print "%-40s  %10s\n" % ("----------------------------------------", \
-						 "----------"),
+		print("%-40s  %10s" % ("event", "count"))
+		print("%-40s  %10s" %
+                        ("----------------------------------------",
+                        "----------"))
 
-		for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
+		for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
 					      reverse = True):
 			try:
-				print "%-40s  %10d\n" % (syscall_name(id), val),
+				print("%-40s  %10d" % (syscall_name(id), val))
 			except TypeError:
 				pass
 		syscalls.clear()
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (9 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 10/15] perf script python: add Python3 support to sctop.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:46   ` Arnaldo Carvalho de Melo
  2019-02-28  8:09   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py Tony Jones
                   ` (4 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Paolo Bonzini

Support both Python2 and Python3 in the stackcollapse.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
 tools/perf/scripts/python/stackcollapse.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
index 1697b5e18c96..5e703efaddcc 100755
--- a/tools/perf/scripts/python/stackcollapse.py
+++ b/tools/perf/scripts/python/stackcollapse.py
@@ -19,6 +19,8 @@
 # Written by Paolo Bonzini <pbonzini@redhat.com>
 # Based on Brendan Gregg's stackcollapse-perf.pl script.
 
+from __future__ import print_function
+
 import os
 import sys
 from collections import defaultdict
@@ -120,7 +122,6 @@ def process_event(param_dict):
     lines[stack_string] = lines[stack_string] + 1
 
 def trace_end():
-    list = lines.keys()
-    list.sort()
+    list = sorted(lines)
     for stack in list:
-        print "%s %d" % (stack, lines[stack])
+        print("%s %d" % (stack, lines[stack]))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (10 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:46   ` Arnaldo Carvalho de Melo
  2019-02-28  8:10   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py Tony Jones
                   ` (3 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek, Jiri Olsa

Support both Python2 and Python3 in the stat-cpi.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/scripts/python/stat-cpi.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py
index a81ad8835a74..01fa933ff3cf 100644
--- a/tools/perf/scripts/python/stat-cpi.py
+++ b/tools/perf/scripts/python/stat-cpi.py
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
+from __future__ import print_function
+
 data    = {}
 times   = []
 threads = []
@@ -19,8 +21,8 @@ def store_key(time, cpu, thread):
         threads.append(thread)
 
 def store(time, event, cpu, thread, val, ena, run):
-    #print "event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" % \
-    #      (event, cpu, thread, time, val, ena, run)
+    #print("event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" %
+    #      (event, cpu, thread, time, val, ena, run))
 
     store_key(time, cpu, thread)
     key = get_key(time, event, cpu, thread)
@@ -58,7 +60,7 @@ def stat__interval(time):
             if ins != 0:
                 cpi = cyc/float(ins)
 
-            print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins)
+            print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins))
 
 def trace_end():
     pass
@@ -74,4 +76,4 @@ def trace_end():
 #                if ins != 0:
 #                    cpi = cyc/float(ins)
 #
-#                print "time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi)
+#                print("time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (11 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:47   ` Arnaldo Carvalho de Melo
  2019-02-28  8:11   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py Tony Jones
                   ` (2 subsequent siblings)
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek

Support both Python2 and Python3 in the syscall-counts.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
---
 tools/perf/scripts/python/syscall-counts.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py
index e66a7730aeb5..0ebd89cfd42c 100644
--- a/tools/perf/scripts/python/syscall-counts.py
+++ b/tools/perf/scripts/python/syscall-counts.py
@@ -5,6 +5,8 @@
 # Displays system-wide system call totals, broken down by syscall.
 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -28,7 +30,7 @@ if len(sys.argv) > 1:
 syscalls = autodict()
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	print_syscall_totals()
@@ -51,14 +53,14 @@ def syscalls__sys_enter(event_name, context, common_cpu,
 
 def print_syscall_totals():
     if for_comm is not None:
-	    print "\nsyscall events for %s:\n\n" % (for_comm),
+	    print("\nsyscall events for %s:\n" % (for_comm))
     else:
-	    print "\nsyscall events:\n\n",
+	    print("\nsyscall events:\n")
 
-    print "%-40s  %10s\n" % ("event", "count"),
-    print "%-40s  %10s\n" % ("----------------------------------------", \
-                                 "-----------"),
+    print("%-40s  %10s" % ("event", "count"))
+    print("%-40s  %10s" % ("----------------------------------------",
+                              "-----------"))
 
-    for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
+    for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
 				  reverse = True):
-	    print "%-40s  %10d\n" % (syscall_name(id), val),
+	    print("%-40s  %10d" % (syscall_name(id), val))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (12 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:48   ` Arnaldo Carvalho de Melo
  2019-02-28  8:11   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  2019-02-22 23:06 ` [PATCH 15/15] perf script python: add Python3 support to sql scripts Tony Jones
  2019-02-23 21:06 ` [PATCH 00/15] perf script python: add Python3 support Tony Jones
  15 siblings, 2 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek

Support both Python2 and Python3 in the syscall-counts-by-pid.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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
---
 .../scripts/python/syscall-counts-by-pid.py   | 22 ++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py
index daf314cc5dd3..42782487b0e9 100644
--- a/tools/perf/scripts/python/syscall-counts-by-pid.py
+++ b/tools/perf/scripts/python/syscall-counts-by-pid.py
@@ -5,6 +5,8 @@
 # Displays system-wide system call totals, broken down by syscall.
 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
 
+from __future__ import print_function
+
 import os, sys
 
 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
@@ -31,7 +33,7 @@ if len(sys.argv) > 1:
 syscalls = autodict()
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	print_syscall_totals()
@@ -55,20 +57,20 @@ def syscalls__sys_enter(event_name, context, common_cpu,
 
 def print_syscall_totals():
     if for_comm is not None:
-	    print "\nsyscall events for %s:\n\n" % (for_comm),
+	    print("\nsyscall events for %s:\n" % (for_comm))
     else:
-	    print "\nsyscall events by comm/pid:\n\n",
+	    print("\nsyscall events by comm/pid:\n")
 
-    print "%-40s  %10s\n" % ("comm [pid]/syscalls", "count"),
-    print "%-40s  %10s\n" % ("----------------------------------------", \
-                                 "----------"),
+    print("%-40s  %10s" % ("comm [pid]/syscalls", "count"))
+    print("%-40s  %10s" % ("----------------------------------------",
+                            "----------"))
 
     comm_keys = syscalls.keys()
     for comm in comm_keys:
 	    pid_keys = syscalls[comm].keys()
 	    for pid in pid_keys:
-		    print "\n%s [%d]\n" % (comm, pid),
+		    print("\n%s [%d]" % (comm, pid))
 		    id_keys = syscalls[comm][pid].keys()
-		    for id, val in sorted(syscalls[comm][pid].iteritems(), \
-				  key = lambda(k, v): (v, k),  reverse = True):
-			    print "  %-38s  %10d\n" % (syscall_name(id), val),
+		    for id, val in sorted(syscalls[comm][pid].items(), \
+				  key = lambda kv: (kv[1], kv[0]),  reverse = True):
+			    print("  %-38s  %10d" % (syscall_name(id), val))
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* [PATCH 15/15] perf script python: add Python3 support to sql scripts
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (13 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py Tony Jones
@ 2019-02-22 23:06 ` Tony Jones
  2019-02-25 14:51   ` Arnaldo Carvalho de Melo
  2019-02-23 21:06 ` [PATCH 00/15] perf script python: add Python3 support Tony Jones
  15 siblings, 1 reply; 45+ messages in thread
From: Tony Jones @ 2019-02-22 23:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme, Tony Jones, Seeteena Thoufeek

Support both Python2 and Python3 in the exported-sql-viewer.py,
export-to-postgresql.py and export-to-sqlite.py scripts

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>
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
---
 .../scripts/python/export-to-postgresql.py    | 31 ++++++----
 tools/perf/scripts/python/export-to-sqlite.py | 26 ++++++---
 .../scripts/python/exported-sql-viewer.py     | 56 ++++++++++++-------
 3 files changed, 71 insertions(+), 42 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index 30130213da7e..baf972680dc7 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -10,6 +10,8 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -234,12 +236,17 @@ perf_db_export_mode = True
 perf_db_export_calls = False
 perf_db_export_callchains = False
 
+def printerr(*args, **kw_args):
+    print(*args, file=sys.stderr, **kw_args)
+
+def printdate(*args, **kw_args):
+        print(datetime.datetime.today(), *args, sep=' ', **kw_args)
 
 def usage():
-	print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]"
-	print >> sys.stderr, "where:	columns		'all' or 'branches'"
-	print >> sys.stderr, "		calls		'calls' => create calls and call_paths table"
-	print >> sys.stderr, "		callchains	'callchains' => create call_paths table"
+	printerr("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]")
+	printerr("where:	columns		'all' or 'branches'")
+	printerr("		calls		'calls' => create calls and call_paths table")
+	printerr("		callchains	'callchains' => create call_paths table")
 	raise Exception("Too few arguments")
 
 if (len(sys.argv) < 2):
@@ -273,7 +280,7 @@ def do_query(q, s):
 		return
 	raise Exception("Query failed: " + q.lastError().text())
 
-print datetime.datetime.today(), "Creating database..."
+printdate("Creating database...")
 
 db = QSqlDatabase.addDatabase('QPSQL')
 query = QSqlQuery(db)
@@ -564,7 +571,7 @@ if perf_db_export_calls:
 	call_file		= open_output_file("call_table.bin")
 
 def trace_begin():
-	print datetime.datetime.today(), "Writing to intermediate files..."
+	printdate("Writing to intermediate files...")
 	# id == 0 means unknown.  It is easier to create records for them than replace the zeroes with NULLs
 	evsel_table(0, "unknown")
 	machine_table(0, 0, "unknown")
@@ -579,7 +586,7 @@ def trace_begin():
 unhandled_count = 0
 
 def trace_end():
-	print datetime.datetime.today(), "Copying to database..."
+	printdate("Copying to database...")
 	copy_output_file(evsel_file,		"selected_events")
 	copy_output_file(machine_file,		"machines")
 	copy_output_file(thread_file,		"threads")
@@ -594,7 +601,7 @@ def trace_end():
 	if perf_db_export_calls:
 		copy_output_file(call_file,		"calls")
 
-	print datetime.datetime.today(), "Removing intermediate files..."
+	printdate("Removing intermediate files...")
 	remove_output_file(evsel_file)
 	remove_output_file(machine_file)
 	remove_output_file(thread_file)
@@ -609,7 +616,7 @@ def trace_end():
 	if perf_db_export_calls:
 		remove_output_file(call_file)
 	os.rmdir(output_dir_name)
-	print datetime.datetime.today(), "Adding primary keys"
+	printdate("Adding primary keys")
 	do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE machines        ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE threads         ADD PRIMARY KEY (id)')
@@ -624,7 +631,7 @@ def trace_end():
 	if perf_db_export_calls:
 		do_query(query, 'ALTER TABLE calls           ADD PRIMARY KEY (id)')
 
-	print datetime.datetime.today(), "Adding foreign keys"
+	printdate("Adding foreign keys")
 	do_query(query, 'ALTER TABLE threads '
 					'ADD CONSTRAINT machinefk  FOREIGN KEY (machine_id)   REFERENCES machines   (id),'
 					'ADD CONSTRAINT processfk  FOREIGN KEY (process_id)   REFERENCES threads    (id)')
@@ -659,8 +666,8 @@ def trace_end():
 		do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
 
 	if (unhandled_count):
-		print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
-	print datetime.datetime.today(), "Done"
+		printdate("Warning: ", unhandled_count, " unhandled events")
+	printdate("Done")
 
 def trace_unhandled(event_name, context, event_fields_dict):
 	global unhandled_count
diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py
index ed237f2ed03f..f56222d22a6e 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -10,6 +10,8 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -60,11 +62,17 @@ perf_db_export_mode = True
 perf_db_export_calls = False
 perf_db_export_callchains = False
 
+def printerr(*args, **keyword_args):
+    print(*args, file=sys.stderr, **keyword_args)
+
+def printdate(*args, **kw_args):
+        print(datetime.datetime.today(), *args, sep=' ', **kw_args)
+
 def usage():
-	print >> sys.stderr, "Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]"
-	print >> sys.stderr, "where:	columns		'all' or 'branches'"
-	print >> sys.stderr, "		calls		'calls' => create calls and call_paths table"
-	print >> sys.stderr, "		callchains	'callchains' => create call_paths table"
+	printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]");
+	printerr("where:	columns		'all' or 'branches'");
+	printerr("		calls		'calls' => create calls and call_paths table");
+	printerr("		callchains	'callchains' => create call_paths table");
 	raise Exception("Too few arguments")
 
 if (len(sys.argv) < 2):
@@ -100,7 +108,7 @@ def do_query_(q):
 		return
 	raise Exception("Query failed: " + q.lastError().text())
 
-print datetime.datetime.today(), "Creating database..."
+printdate("Creating database ...")
 
 db_exists = False
 try:
@@ -376,7 +384,7 @@ if perf_db_export_calls:
 	call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
 
 def trace_begin():
-	print datetime.datetime.today(), "Writing records..."
+	printdate("Writing records...")
 	do_query(query, 'BEGIN TRANSACTION')
 	# id == 0 means unknown.  It is easier to create records for them than replace the zeroes with NULLs
 	evsel_table(0, "unknown")
@@ -394,13 +402,13 @@ unhandled_count = 0
 def trace_end():
 	do_query(query, 'END TRANSACTION')
 
-	print datetime.datetime.today(), "Adding indexes"
+	printdate("Adding indexes")
 	if perf_db_export_calls:
 		do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
 
 	if (unhandled_count):
-		print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
-	print datetime.datetime.today(), "Done"
+		printdate("Warning: ", unhandled_count, " unhandled events")
+	printdate("Done")
 
 def trace_unhandled(event_name, context, event_fields_dict):
 	global unhandled_count
diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py
index c3091401df91..9bc03b8f77a5 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -87,11 +87,20 @@
 #                                                                              7fab593ea956 48 89 15 3b 13 22 00                            movq  %rdx, 0x22133b(%rip)
 # 8107675243232  2    ls       22011  22011  hardware interrupt     No         7fab593ea956 _dl_start+0x26 (ld-2.19.so) -> ffffffff86a012e0 page_fault ([kernel])
 
+from __future__ import print_function
+
 import sys
 import weakref
 import threading
 import string
-import cPickle
+try:
+    # Python2
+    import cPickle as pickle
+    # size of pickled integer big enough for record size
+    glb_nsz = 8
+except ImportError:
+    import pickle
+    glb_nsz = 16
 import re
 import os
 from PySide.QtCore import *
@@ -101,6 +110,15 @@ from decimal import *
 from ctypes import *
 from multiprocessing import Process, Array, Value, Event
 
+# xrange is range in Python3
+try:
+    xrange
+except NameError:
+    xrange = range
+
+def printerr(*args, **keyword_args):
+    print(*args, file=sys.stderr, **keyword_args)
+
 # Data formatting helpers
 
 def tohex(ip):
@@ -811,10 +829,6 @@ class ChildDataItemFinder():
 
 glb_chunk_sz = 10000
 
-# size of pickled integer big enough for record size
-
-glb_nsz = 8
-
 # Background process for SQL data fetcher
 
 class SQLFetcherProcess():
@@ -873,7 +887,7 @@ class SQLFetcherProcess():
 				return True
 			if space >= glb_nsz:
 				# Use 0 (or space < glb_nsz) to mean there is no more at the top of the buffer
-				nd = cPickle.dumps(0, cPickle.HIGHEST_PROTOCOL)
+				nd = pickle.dumps(0, pickle.HIGHEST_PROTOCOL)
 				self.buffer[self.local_head : self.local_head + len(nd)] = nd
 			self.local_head = 0
 		if self.local_tail - self.local_head > sz:
@@ -891,9 +905,9 @@ class SQLFetcherProcess():
 			self.wait_event.wait()
 
 	def AddToBuffer(self, obj):
-		d = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL)
+		d = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
 		n = len(d)
-		nd = cPickle.dumps(n, cPickle.HIGHEST_PROTOCOL)
+		nd = pickle.dumps(n, pickle.HIGHEST_PROTOCOL)
 		sz = n + glb_nsz
 		self.WaitForSpace(sz)
 		pos = self.local_head
@@ -1005,12 +1019,12 @@ class SQLFetcher(QObject):
 		pos = self.local_tail
 		if len(self.buffer) - pos < glb_nsz:
 			pos = 0
-		n = cPickle.loads(self.buffer[pos : pos + glb_nsz])
+		n = pickle.loads(self.buffer[pos : pos + glb_nsz])
 		if n == 0:
 			pos = 0
-			n = cPickle.loads(self.buffer[0 : glb_nsz])
+			n = pickle.loads(self.buffer[0 : glb_nsz])
 		pos += glb_nsz
-		obj = cPickle.loads(self.buffer[pos : pos + n])
+		obj = pickle.loads(self.buffer[pos : pos + n])
 		self.local_tail = pos + n
 		return obj
 
@@ -1559,7 +1573,7 @@ class SQLTableDialogDataItem():
 					return str(lower_id)
 
 	def ConvertRelativeTime(self, val):
-		print "val ", val
+		print("val ", val)
 		mult = 1
 		suffix = val[-2:]
 		if suffix == "ms":
@@ -1581,29 +1595,29 @@ class SQLTableDialogDataItem():
 		return str(val)
 
 	def ConvertTimeRange(self, vrange):
-		print "vrange ", vrange
+		print("vrange ", vrange)
 		if vrange[0] == "":
 			vrange[0] = str(self.first_time)
 		if vrange[1] == "":
 			vrange[1] = str(self.last_time)
 		vrange[0] = self.ConvertRelativeTime(vrange[0])
 		vrange[1] = self.ConvertRelativeTime(vrange[1])
-		print "vrange2 ", vrange
+		print("vrange2 ", vrange)
 		if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]):
 			return False
-		print "ok1"
+		print("ok1")
 		beg_range = max(int(vrange[0]), self.first_time)
 		end_range = min(int(vrange[1]), self.last_time)
 		if beg_range > self.last_time or end_range < self.first_time:
 			return False
-		print "ok2"
+		print("ok2")
 		vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True)
 		vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False)
-		print "vrange3 ", vrange
+		print("vrange3 ", vrange)
 		return True
 
 	def AddTimeRange(self, value, ranges):
-		print "value ", value
+		print("value ", value)
 		n = value.count("-")
 		if n == 1:
 			pass
@@ -2577,7 +2591,7 @@ class DBRef():
 
 def Main():
 	if (len(sys.argv) < 2):
-		print >> sys.stderr, "Usage is: exported-sql-viewer.py {<database name> | --help-only}"
+		printerr("Usage is: exported-sql-viewer.py {<database name> | --help-only}");
 		raise Exception("Too few arguments")
 
 	dbname = sys.argv[1]
@@ -2590,8 +2604,8 @@ def Main():
 
 	is_sqlite3 = False
 	try:
-		f = open(dbname)
-		if f.read(15) == "SQLite format 3":
+		f = open(dbname, "rb")
+		if f.read(15) == b'SQLite format 3':
 			is_sqlite3 = True
 		f.close()
 	except:
-- 
2.20.1


^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 00/15] perf script python: add Python3 support
  2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
                   ` (14 preceding siblings ...)
  2019-02-22 23:06 ` [PATCH 15/15] perf script python: add Python3 support to sql scripts Tony Jones
@ 2019-02-23 21:06 ` Tony Jones
  15 siblings, 0 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-23 21:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme

On 2/22/19 3:06 PM, Tony Jones wrote:
> The following patches add Python3 support to the remainder of 
> the scripts under scripts/python.

I should possibly have labeled this V3.  Seeteena had submitted prior patches but they had issues and since I already had (better tested) patches in OpenSUSE and SLES that I was about to submit, we decided I would submit those patches under a joint signed-off-by,  which is what I've done here. Apologies for any confusion.

Tony

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py
  2019-02-22 23:06 ` [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py Tony Jones
@ 2019-02-25  7:07   ` Adrian Hunter
  2019-02-25 14:03     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 45+ messages in thread
From: Adrian Hunter @ 2019-02-25  7:07 UTC (permalink / raw)
  To: Tony Jones, linux-kernel; +Cc: linux-perf-users, acme, Seeteena Thoufeek

On 23/02/19 1:06 AM, Tony Jones wrote:
> Support both Python2 and Python3 in the intel-pt-events.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.
> 
> Fix space/tab inconsistency as python3 enforces consistency.

It would be better for the white space changes to be a separate patch.

But I am not in favour of using spaces instead of tabs because it is the
opposite of what we tend to do with C.

Arnaldo, can you provide a guideline on this?

> 
> The use of 'from __future__' implies the minimum supported Python2 version
> is now v2.6
> 
> Signed-off-by: Tony Jones <tonyj@suse.de>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/scripts/python/intel-pt-events.py | 138 ++++++++++---------
>  1 file changed, 70 insertions(+), 68 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
> index b19172d673af..aef54566af61 100644
> --- a/tools/perf/scripts/python/intel-pt-events.py
> +++ b/tools/perf/scripts/python/intel-pt-events.py
> @@ -10,79 +10,81 @@
>  # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>  # more details.
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  import struct
>  
>  sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> -	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> +        '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
>  
>  # These perf imports are not used at present
>  #from perf_trace_context import *
>  #from Core import *
>  
>  def trace_begin():
> -	print "Intel PT Power Events and PTWRITE"
> +        print("Intel PT Power Events and PTWRITE")
>  
>  def trace_end():
> -	print "End"
> +        print("End")
>  
>  def trace_unhandled(event_name, context, event_fields_dict):
> -		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
> +        print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
>  
>  def print_ptwrite(raw_buf):
> -	data = struct.unpack_from("<IQ", raw_buf)
> -	flags = data[0]
> -	payload = data[1]
> -	exact_ip = flags & 1
> -	print "IP: %u payload: %#x" % (exact_ip, payload),
> +        data = struct.unpack_from("<IQ", raw_buf)
> +        flags = data[0]
> +        payload = data[1]
> +        exact_ip = flags & 1
> +        print("IP: %u payload: %#x" % (exact_ip, payload), end='')
>  
>  def print_cbr(raw_buf):
> -	data = struct.unpack_from("<BBBBII", raw_buf)
> -	cbr = data[0]
> -	f = (data[4] + 500) / 1000
> -	p = ((cbr * 1000 / data[2]) + 5) / 10
> -	print "%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p),
> +        data = struct.unpack_from("<BBBBII", raw_buf)
> +        cbr = data[0]
> +        f = (data[4] + 500) / 1000
> +        p = ((cbr * 1000 / data[2]) + 5) / 10
> +        print("%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p), end='')
>  
>  def print_mwait(raw_buf):
> -	data = struct.unpack_from("<IQ", raw_buf)
> -	payload = data[1]
> -	hints = payload & 0xff
> -	extensions = (payload >> 32) & 0x3
> -	print "hints: %#x extensions: %#x" % (hints, extensions),
> +        data = struct.unpack_from("<IQ", raw_buf)
> +        payload = data[1]
> +        hints = payload & 0xff
> +        extensions = (payload >> 32) & 0x3
> +        print("hints: %#x extensions: %#x" % (hints, extensions), end='')
>  
>  def print_pwre(raw_buf):
> -	data = struct.unpack_from("<IQ", raw_buf)
> -	payload = data[1]
> -	hw = (payload >> 7) & 1
> -	cstate = (payload >> 12) & 0xf
> -	subcstate = (payload >> 8) & 0xf
> -	print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
> +        data = struct.unpack_from("<IQ", raw_buf)
> +        payload = data[1]
> +        hw = (payload >> 7) & 1
> +        cstate = (payload >> 12) & 0xf
> +        subcstate = (payload >> 8) & 0xf
> +        print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), end='')
>  
>  def print_exstop(raw_buf):
> -	data = struct.unpack_from("<I", raw_buf)
> -	flags = data[0]
> -	exact_ip = flags & 1
> -	print "IP: %u" % (exact_ip),
> +        data = struct.unpack_from("<I", raw_buf)
> +        flags = data[0]
> +        exact_ip = flags & 1
> +        print("IP: %u" % (exact_ip), end='')
>  
>  def print_pwrx(raw_buf):
> -	data = struct.unpack_from("<IQ", raw_buf)
> -	payload = data[1]
> -	deepest_cstate = payload & 0xf
> -	last_cstate = (payload >> 4) & 0xf
> -	wake_reason = (payload >> 8) & 0xf
> -	print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason),
> +        data = struct.unpack_from("<IQ", raw_buf)
> +        payload = data[1]
> +        deepest_cstate = payload & 0xf
> +        last_cstate = (payload >> 4) & 0xf
> +        wake_reason = (payload >> 8) & 0xf
> +        print("deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), end='')
>  
>  def print_common_start(comm, sample, name):
> -	ts = sample["time"]
> -	cpu = sample["cpu"]
> -	pid = sample["pid"]
> -	tid = sample["tid"]
> -	print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
> +        ts = sample["time"]
> +        cpu = sample["cpu"]
> +        pid = sample["pid"]
> +        tid = sample["tid"]
> +        print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), end='')
>  
>  def print_common_ip(sample, symbol, dso):
> -	ip = sample["ip"]
> -	print "%16x %s (%s)" % (ip, symbol, dso)
> +        ip = sample["ip"]
> +        print("%16x %s (%s)" % (ip, symbol, dso))
>  
>  def process_event(param_dict):
>          event_attr = param_dict["attr"]
> @@ -92,37 +94,37 @@ def process_event(param_dict):
>          name       = param_dict["ev_name"]
>  
>          # Symbol and dso info are not always resolved
> -        if (param_dict.has_key("dso")):
> +        if "dso" in param_dict:
>                  dso = param_dict["dso"]
>          else:
>                  dso = "[unknown]"
>  
> -        if (param_dict.has_key("symbol")):
> +        if "symbol" in param_dict:
>                  symbol = param_dict["symbol"]
>          else:
>                  symbol = "[unknown]"
>  
> -	if name == "ptwrite":
> -		print_common_start(comm, sample, name)
> -		print_ptwrite(raw_buf)
> -		print_common_ip(sample, symbol, dso)
> -	elif name == "cbr":
> -		print_common_start(comm, sample, name)
> -		print_cbr(raw_buf)
> -		print_common_ip(sample, symbol, dso)
> -	elif name == "mwait":
> -		print_common_start(comm, sample, name)
> -		print_mwait(raw_buf)
> -		print_common_ip(sample, symbol, dso)
> -	elif name == "pwre":
> -		print_common_start(comm, sample, name)
> -		print_pwre(raw_buf)
> -		print_common_ip(sample, symbol, dso)
> -	elif name == "exstop":
> -		print_common_start(comm, sample, name)
> -		print_exstop(raw_buf)
> -		print_common_ip(sample, symbol, dso)
> -	elif name == "pwrx":
> -		print_common_start(comm, sample, name)
> -		print_pwrx(raw_buf)
> -		print_common_ip(sample, symbol, dso)
> +        if name == "ptwrite":
> +                print_common_start(comm, sample, name)
> +                print_ptwrite(raw_buf)
> +                print_common_ip(sample, symbol, dso)
> +        elif name == "cbr":
> +                print_common_start(comm, sample, name)
> +                print_cbr(raw_buf)
> +                print_common_ip(sample, symbol, dso)
> +        elif name == "mwait":
> +                print_common_start(comm, sample, name)
> +                print_mwait(raw_buf)
> +                print_common_ip(sample, symbol, dso)
> +        elif name == "pwre":
> +                print_common_start(comm, sample, name)
> +                print_pwre(raw_buf)
> +                print_common_ip(sample, symbol, dso)
> +        elif name == "exstop":
> +                print_common_start(comm, sample, name)
> +                print_exstop(raw_buf)
> +                print_common_ip(sample, symbol, dso)
> +        elif name == "pwrx":
> +                print_common_start(comm, sample, name)
> +                print_pwrx(raw_buf)
> +                print_common_ip(sample, symbol, dso)
> 


^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py
  2019-02-22 23:06 ` [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py Tony Jones
@ 2019-02-25 12:37   ` Neil Horman
  2019-02-25 14:43     ` Arnaldo Carvalho de Melo
  2019-02-28  8:08   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 1 reply; 45+ messages in thread
From: Neil Horman @ 2019-02-25 12:37 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, acme, Seeteena Thoufeek

On Fri, Feb 22, 2019 at 03:06:12PM -0800, Tony Jones wrote:
> Support both Python2 and Python3 in the net_dropmonitor.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>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> Cc: Neil Horman <nhorman@tuxdriver.com>
> ---
>  tools/perf/scripts/python/net_dropmonitor.py | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py
> index a150164b44a3..212557a02c50 100755
> --- a/tools/perf/scripts/python/net_dropmonitor.py
> +++ b/tools/perf/scripts/python/net_dropmonitor.py
> @@ -1,6 +1,8 @@
>  # Monitor the system for dropped packets and proudce a report of drop locations and counts
>  # SPDX-License-Identifier: GPL-2.0
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  
> @@ -50,19 +52,19 @@ def get_sym(sloc):
>  		return (None, 0)
>  
>  def print_drop_table():
> -	print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
> +	print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
>  	for i in drop_log.keys():
>  		(sym, off) = get_sym(i)
>  		if sym == None:
>  			sym = i
> -		print "%25s %25s %25s" % (sym, off, drop_log[i])
> +		print("%25s %25s %25s" % (sym, off, drop_log[i]))
>  
>  
>  def trace_begin():
> -	print "Starting trace (Ctrl-C to dump results)"
> +	print("Starting trace (Ctrl-C to dump results)")
>  
>  def trace_end():
> -	print "Gathering kallsyms data"
> +	print("Gathering kallsyms data")
>  	get_kallsyms_table()
>  	print_drop_table()
>  
> -- 
> 2.20.1
> 
> 
Acked-by: Neil Horman <nhorman@tuxdriver.com>

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py
  2019-02-25  7:07   ` Adrian Hunter
@ 2019-02-25 14:03     ` Arnaldo Carvalho de Melo
  2019-02-25 17:18       ` Tony Jones
  0 siblings, 1 reply; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:03 UTC (permalink / raw)
  To: Adrian Hunter, Tony Jones
  Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Mon, Feb 25, 2019 at 09:07:03AM +0200, Adrian Hunter escreveu:
> On 23/02/19 1:06 AM, Tony Jones wrote:
> > Support both Python2 and Python3 in the intel-pt-events.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.
> > 
> > Fix space/tab inconsistency as python3 enforces consistency.
> 
> It would be better for the white space changes to be a separate patch.
> 
> But I am not in favour of using spaces instead of tabs because it is the
> opposite of what we tend to do with C.
> 
> Arnaldo, can you provide a guideline on this?

Yeah, please separate things, this would help me now to pick the
uncontroversial part while we discuss the other.

And I'm in favour of being consistent with what we do for C code, i.e.
use TABs.

I'm now processing the other patches.

- Arnaldo
 
> > 
> > The use of 'from __future__' implies the minimum supported Python2 version
> > is now v2.6
> > 
> > Signed-off-by: Tony Jones <tonyj@suse.de>
> > Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> > Cc: Adrian Hunter <adrian.hunter@intel.com>
> > ---
> >  tools/perf/scripts/python/intel-pt-events.py | 138 ++++++++++---------
> >  1 file changed, 70 insertions(+), 68 deletions(-)
> > 
> > diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
> > index b19172d673af..aef54566af61 100644
> > --- a/tools/perf/scripts/python/intel-pt-events.py
> > +++ b/tools/perf/scripts/python/intel-pt-events.py
> > @@ -10,79 +10,81 @@
> >  # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> >  # more details.
> >  
> > +from __future__ import print_function
> > +
> >  import os
> >  import sys
> >  import struct
> >  
> >  sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> > -	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> > +        '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> >  
> >  # These perf imports are not used at present
> >  #from perf_trace_context import *
> >  #from Core import *
> >  
> >  def trace_begin():
> > -	print "Intel PT Power Events and PTWRITE"
> > +        print("Intel PT Power Events and PTWRITE")
> >  
> >  def trace_end():
> > -	print "End"
> > +        print("End")
> >  
> >  def trace_unhandled(event_name, context, event_fields_dict):
> > -		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
> > +        print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
> >  
> >  def print_ptwrite(raw_buf):
> > -	data = struct.unpack_from("<IQ", raw_buf)
> > -	flags = data[0]
> > -	payload = data[1]
> > -	exact_ip = flags & 1
> > -	print "IP: %u payload: %#x" % (exact_ip, payload),
> > +        data = struct.unpack_from("<IQ", raw_buf)
> > +        flags = data[0]
> > +        payload = data[1]
> > +        exact_ip = flags & 1
> > +        print("IP: %u payload: %#x" % (exact_ip, payload), end='')
> >  
> >  def print_cbr(raw_buf):
> > -	data = struct.unpack_from("<BBBBII", raw_buf)
> > -	cbr = data[0]
> > -	f = (data[4] + 500) / 1000
> > -	p = ((cbr * 1000 / data[2]) + 5) / 10
> > -	print "%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p),
> > +        data = struct.unpack_from("<BBBBII", raw_buf)
> > +        cbr = data[0]
> > +        f = (data[4] + 500) / 1000
> > +        p = ((cbr * 1000 / data[2]) + 5) / 10
> > +        print("%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p), end='')
> >  
> >  def print_mwait(raw_buf):
> > -	data = struct.unpack_from("<IQ", raw_buf)
> > -	payload = data[1]
> > -	hints = payload & 0xff
> > -	extensions = (payload >> 32) & 0x3
> > -	print "hints: %#x extensions: %#x" % (hints, extensions),
> > +        data = struct.unpack_from("<IQ", raw_buf)
> > +        payload = data[1]
> > +        hints = payload & 0xff
> > +        extensions = (payload >> 32) & 0x3
> > +        print("hints: %#x extensions: %#x" % (hints, extensions), end='')
> >  
> >  def print_pwre(raw_buf):
> > -	data = struct.unpack_from("<IQ", raw_buf)
> > -	payload = data[1]
> > -	hw = (payload >> 7) & 1
> > -	cstate = (payload >> 12) & 0xf
> > -	subcstate = (payload >> 8) & 0xf
> > -	print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
> > +        data = struct.unpack_from("<IQ", raw_buf)
> > +        payload = data[1]
> > +        hw = (payload >> 7) & 1
> > +        cstate = (payload >> 12) & 0xf
> > +        subcstate = (payload >> 8) & 0xf
> > +        print("hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), end='')
> >  
> >  def print_exstop(raw_buf):
> > -	data = struct.unpack_from("<I", raw_buf)
> > -	flags = data[0]
> > -	exact_ip = flags & 1
> > -	print "IP: %u" % (exact_ip),
> > +        data = struct.unpack_from("<I", raw_buf)
> > +        flags = data[0]
> > +        exact_ip = flags & 1
> > +        print("IP: %u" % (exact_ip), end='')
> >  
> >  def print_pwrx(raw_buf):
> > -	data = struct.unpack_from("<IQ", raw_buf)
> > -	payload = data[1]
> > -	deepest_cstate = payload & 0xf
> > -	last_cstate = (payload >> 4) & 0xf
> > -	wake_reason = (payload >> 8) & 0xf
> > -	print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason),
> > +        data = struct.unpack_from("<IQ", raw_buf)
> > +        payload = data[1]
> > +        deepest_cstate = payload & 0xf
> > +        last_cstate = (payload >> 4) & 0xf
> > +        wake_reason = (payload >> 8) & 0xf
> > +        print("deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), end='')
> >  
> >  def print_common_start(comm, sample, name):
> > -	ts = sample["time"]
> > -	cpu = sample["cpu"]
> > -	pid = sample["pid"]
> > -	tid = sample["tid"]
> > -	print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
> > +        ts = sample["time"]
> > +        cpu = sample["cpu"]
> > +        pid = sample["pid"]
> > +        tid = sample["tid"]
> > +        print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), end='')
> >  
> >  def print_common_ip(sample, symbol, dso):
> > -	ip = sample["ip"]
> > -	print "%16x %s (%s)" % (ip, symbol, dso)
> > +        ip = sample["ip"]
> > +        print("%16x %s (%s)" % (ip, symbol, dso))
> >  
> >  def process_event(param_dict):
> >          event_attr = param_dict["attr"]
> > @@ -92,37 +94,37 @@ def process_event(param_dict):
> >          name       = param_dict["ev_name"]
> >  
> >          # Symbol and dso info are not always resolved
> > -        if (param_dict.has_key("dso")):
> > +        if "dso" in param_dict:
> >                  dso = param_dict["dso"]
> >          else:
> >                  dso = "[unknown]"
> >  
> > -        if (param_dict.has_key("symbol")):
> > +        if "symbol" in param_dict:
> >                  symbol = param_dict["symbol"]
> >          else:
> >                  symbol = "[unknown]"
> >  
> > -	if name == "ptwrite":
> > -		print_common_start(comm, sample, name)
> > -		print_ptwrite(raw_buf)
> > -		print_common_ip(sample, symbol, dso)
> > -	elif name == "cbr":
> > -		print_common_start(comm, sample, name)
> > -		print_cbr(raw_buf)
> > -		print_common_ip(sample, symbol, dso)
> > -	elif name == "mwait":
> > -		print_common_start(comm, sample, name)
> > -		print_mwait(raw_buf)
> > -		print_common_ip(sample, symbol, dso)
> > -	elif name == "pwre":
> > -		print_common_start(comm, sample, name)
> > -		print_pwre(raw_buf)
> > -		print_common_ip(sample, symbol, dso)
> > -	elif name == "exstop":
> > -		print_common_start(comm, sample, name)
> > -		print_exstop(raw_buf)
> > -		print_common_ip(sample, symbol, dso)
> > -	elif name == "pwrx":
> > -		print_common_start(comm, sample, name)
> > -		print_pwrx(raw_buf)
> > -		print_common_ip(sample, symbol, dso)
> > +        if name == "ptwrite":
> > +                print_common_start(comm, sample, name)
> > +                print_ptwrite(raw_buf)
> > +                print_common_ip(sample, symbol, dso)
> > +        elif name == "cbr":
> > +                print_common_start(comm, sample, name)
> > +                print_cbr(raw_buf)
> > +                print_common_ip(sample, symbol, dso)
> > +        elif name == "mwait":
> > +                print_common_start(comm, sample, name)
> > +                print_mwait(raw_buf)
> > +                print_common_ip(sample, symbol, dso)
> > +        elif name == "pwre":
> > +                print_common_start(comm, sample, name)
> > +                print_pwre(raw_buf)
> > +                print_common_ip(sample, symbol, dso)
> > +        elif name == "exstop":
> > +                print_common_start(comm, sample, name)
> > +                print_exstop(raw_buf)
> > +                print_common_ip(sample, symbol, dso)
> > +        elif name == "pwrx":
> > +                print_common_start(comm, sample, name)
> > +                print_pwrx(raw_buf)
> > +                print_common_ip(sample, symbol, dso)
> > 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py
  2019-02-22 23:06 ` [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py Tony Jones
@ 2019-02-25 14:05   ` Arnaldo Carvalho de Melo
  2019-02-25 18:05     ` Tony Jones
  0 siblings, 1 reply; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:05 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Tom Zanussi

Em Fri, Feb 22, 2019 at 03:06:06PM -0800, Tony Jones escreveu:
> Support both Python 2 and Python 3 in the check-perf-trace.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.
> 
> Also correct inconsistent indentation which was being flagged by Python3.

When we have "Also" in a patch, usually it need to be split :-)

- Arnaldo
 
> The use of from __future__ implies the minimum supported version of
> Python2 is now v2.6
> 
> Signed-off-by: Tony Jones <tonyj@suse.de>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> Cc: Tom Zanussi <tzanussi@gmail.com>
> ---
>  tools/perf/scripts/python/check-perf-trace.py | 68 ++++++++++---------
>  1 file changed, 36 insertions(+), 32 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/check-perf-trace.py b/tools/perf/scripts/python/check-perf-trace.py
> index 334599c6032c..2851cf0e6b4b 100644
> --- a/tools/perf/scripts/python/check-perf-trace.py
> +++ b/tools/perf/scripts/python/check-perf-trace.py
> @@ -7,11 +7,13 @@
>  # events, etc.  Basically, if this script runs successfully and
>  # displays expected results, Python scripting support should be ok.
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  
> -sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> -	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> +sys.path.append(os.environ['PERF_EXEC_PATH'] +
> +    '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
>  
>  from Core import *
>  from perf_trace_context import *
> @@ -19,37 +21,38 @@ from perf_trace_context import *
>  unhandled = autodict()
>  
>  def trace_begin():
> -	print "trace_begin"
> -	pass
> +    print("trace_begin")
> +    pass
>  
>  def trace_end():
> -        print_unhandled()
> +    print_unhandled()
>  
>  def irq__softirq_entry(event_name, context, common_cpu,
> -	common_secs, common_nsecs, common_pid, common_comm,
> -	common_callchain, vec):
> -		print_header(event_name, common_cpu, common_secs, common_nsecs,
> -			common_pid, common_comm)
> +    common_secs, common_nsecs, common_pid, common_comm,
> +    common_callchain, vec):
> +
> +    print_header(event_name, common_cpu, common_secs, common_nsecs,
> +        common_pid, common_comm)
>  
> -                print_uncommon(context)
> +    print_uncommon(context)
>  
> -		print "vec=%s\n" % \
> -		(symbol_str("irq__softirq_entry", "vec", vec)),
> +    print("vec=%s" %
> +        (symbol_str("irq__softirq_entry", "vec", vec)))
>  
>  def kmem__kmalloc(event_name, context, common_cpu,
> -	common_secs, common_nsecs, common_pid, common_comm,
> -	common_callchain, call_site, ptr, bytes_req, bytes_alloc,
> -	gfp_flags):
> -		print_header(event_name, common_cpu, common_secs, common_nsecs,
> -			common_pid, common_comm)
> +    common_secs, common_nsecs, common_pid, common_comm,
> +    common_callchain, call_site, ptr, bytes_req, bytes_alloc,
> +    gfp_flags):
>  
> -                print_uncommon(context)
> +    print_header(event_name, common_cpu, common_secs, common_nsecs,
> +        common_pid, common_comm)
>  
> -		print "call_site=%u, ptr=%u, bytes_req=%u, " \
> -		"bytes_alloc=%u, gfp_flags=%s\n" % \
> -		(call_site, ptr, bytes_req, bytes_alloc,
> +    print_uncommon(context)
>  
> -		flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
> +    print("call_site=%u, ptr=%u, bytes_req=%u, "
> +        "bytes_alloc=%u, gfp_flags=%s\n" %
> +        (call_site, ptr, bytes_req, bytes_alloc,
> +        flag_str("kmem__kmalloc", "gfp_flags", gfp_flags))),
>  
>  def trace_unhandled(event_name, context, event_fields_dict):
>      try:
> @@ -58,25 +61,26 @@ def trace_unhandled(event_name, context, event_fields_dict):
>          unhandled[event_name] = 1
>  
>  def print_header(event_name, cpu, secs, nsecs, pid, comm):
> -	print "%-20s %5u %05u.%09u %8u %-20s " % \
> -	(event_name, cpu, secs, nsecs, pid, comm),
> +    print("%-20s %5u %05u.%09u %8u %-20s " %
> +        (event_name, cpu, secs, nsecs, pid, comm),
> +                end='')
>  
>  # print trace fields not included in handler args
>  def print_uncommon(context):
> -    print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
> -        % (common_pc(context), trace_flag_str(common_flags(context)), \
> -               common_lock_depth(context))
> +    print("common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " %
> +        (common_pc(context), trace_flag_str(common_flags(context)),
> +        common_lock_depth(context))),
>  
>  def print_unhandled():
>      keys = unhandled.keys()
>      if not keys:
>          return
>  
> -    print "\nunhandled events:\n\n",
> +    print("\nunhandled events:\n")
>  
> -    print "%-40s  %10s\n" % ("event", "count"),
> -    print "%-40s  %10s\n" % ("----------------------------------------", \
> -                                 "-----------"),
> +    print("%-40s  %10s" % ("event", "count"))
> +    print("%-40s  %10s" % ("----------------------------------------",
> +                 "-----------"))
>  
>      for event_name in keys:
> -	print "%-40s  %10d\n" % (event_name, unhandled[event_name])
> +        print("%-40s  %10d\n" % (event_name, unhandled[event_name]))
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 03/15] perf script python: add Python3 support to event_analyzing_sample.py
  2019-02-22 23:06 ` [PATCH 03/15] perf script python: add Python3 support to event_analyzing_sample.py Tony Jones
@ 2019-02-25 14:08   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:08 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Fri, Feb 22, 2019 at 03:06:07PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the event_analyzing_sample.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

This also has indentation changes :-\

The first one I processed, as its already TAB based and the changes are
just for the output part.

- Arnaldo
 
> Signed-off-by: Tony Jones <tonyj@suse.de>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> ---
>  .../scripts/python/event_analyzing_sample.py  | 48 ++++++++++---------
>  1 file changed, 25 insertions(+), 23 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/event_analyzing_sample.py b/tools/perf/scripts/python/event_analyzing_sample.py
> index 4e843b9864ec..f4c4c7963451 100644
> --- a/tools/perf/scripts/python/event_analyzing_sample.py
> +++ b/tools/perf/scripts/python/event_analyzing_sample.py
> @@ -15,6 +15,8 @@
>  # for a x86 HW PMU event: PEBS with load latency data.
>  #
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  import math
> @@ -37,7 +39,7 @@ con = sqlite3.connect("/dev/shm/perf.db")
>  con.isolation_level = None
>  
>  def trace_begin():
> -	print "In trace_begin:\n"
> +        print("In trace_begin:\n")
>  
>          #
>          # Will create several tables at the start, pebs_ll is for PEBS data with
> @@ -76,12 +78,12 @@ def process_event(param_dict):
>          name       = param_dict["ev_name"]
>  
>          # Symbol and dso info are not always resolved
> -        if (param_dict.has_key("dso")):
> +        if ("dso" in param_dict):
>                  dso = param_dict["dso"]
>          else:
>                  dso = "Unknown_dso"
>  
> -        if (param_dict.has_key("symbol")):
> +        if ("symbol" in param_dict):
>                  symbol = param_dict["symbol"]
>          else:
>                  symbol = "Unknown_symbol"
> @@ -102,7 +104,7 @@ def insert_db(event):
>                                  event.ip, event.status, event.dse, event.dla, event.lat))
>  
>  def trace_end():
> -	print "In trace_end:\n"
> +        print("In trace_end:\n")
>          # We show the basic info for the 2 type of event classes
>          show_general_events()
>          show_pebs_ll()
> @@ -123,29 +125,29 @@ def show_general_events():
>          # Check the total record number in the table
>          count = con.execute("select count(*) from gen_events")
>          for t in count:
> -                print "There is %d records in gen_events table" % t[0]
> +                print("There is %d records in gen_events table" % t[0])
>                  if t[0] == 0:
>                          return
>  
> -        print "Statistics about the general events grouped by thread/symbol/dso: \n"
> +        print("Statistics about the general events grouped by thread/symbol/dso: \n")
>  
>           # Group by thread
>          commq = con.execute("select comm, count(comm) from gen_events group by comm order by -count(comm)")
> -        print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
> +        print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42))
>          for row in commq:
> -             print "%16s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%16s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>          # Group by symbol
> -        print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
> +        print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58))
>          symbolq = con.execute("select symbol, count(symbol) from gen_events group by symbol order by -count(symbol)")
>          for row in symbolq:
> -             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>          # Group by dso
> -        print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)
> +        print("\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74))
>          dsoq = con.execute("select dso, count(dso) from gen_events group by dso order by -count(dso)")
>          for row in dsoq:
> -             print "%40s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%40s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>  #
>  # This function just shows the basic info, and we could do more with the
> @@ -156,35 +158,35 @@ def show_pebs_ll():
>  
>          count = con.execute("select count(*) from pebs_ll")
>          for t in count:
> -                print "There is %d records in pebs_ll table" % t[0]
> +                print("There is %d records in pebs_ll table" % t[0])
>                  if t[0] == 0:
>                          return
>  
> -        print "Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n"
> +        print("Statistics about the PEBS Load Latency events grouped by thread/symbol/dse/latency: \n")
>  
>          # Group by thread
>          commq = con.execute("select comm, count(comm) from pebs_ll group by comm order by -count(comm)")
> -        print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
> +        print("\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42))
>          for row in commq:
> -             print "%16s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%16s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>          # Group by symbol
> -        print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
> +        print("\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58))
>          symbolq = con.execute("select symbol, count(symbol) from pebs_ll group by symbol order by -count(symbol)")
>          for row in symbolq:
> -             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>          # Group by dse
>          dseq = con.execute("select dse, count(dse) from pebs_ll group by dse order by -count(dse)")
> -        print "\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58)
> +        print("\n%32s %8s %16s\n%s" % ("dse", "number", "histogram", "="*58))
>          for row in dseq:
> -             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>          # Group by latency
>          latq = con.execute("select lat, count(lat) from pebs_ll group by lat order by lat")
> -        print "\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58)
> +        print("\n%32s %8s %16s\n%s" % ("latency", "number", "histogram", "="*58))
>          for row in latq:
> -             print "%32s %8d     %s" % (row[0], row[1], num2sym(row[1]))
> +             print("%32s %8d     %s" % (row[0], row[1], num2sym(row[1])))
>  
>  def trace_unhandled(event_name, context, event_fields_dict):
> -		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
> +        print(' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]))
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py
  2019-02-22 23:06 ` [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py Tony Jones
@ 2019-02-25 14:09   ` Arnaldo Carvalho de Melo
  2019-02-28  8:06   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:09 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Tom Zanussi

Em Fri, Feb 22, 2019 at 03:06:08PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the failed-syscalls-by-pid.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

Applied
 
> Signed-off-by: Tony Jones <tonyj@suse.de>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> Cc: Tom Zanussi <tzanussi@gmail.com>
> ---
>  .../scripts/python/failed-syscalls-by-pid.py  | 21 ++++++++++---------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py
> index cafeff3d74db..3648e8b986ec 100644
> --- a/tools/perf/scripts/python/failed-syscalls-by-pid.py
> +++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py
> @@ -5,6 +5,8 @@
>  # Displays system-wide failed system call totals, broken down by pid.
>  # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  
> @@ -32,7 +34,7 @@ if len(sys.argv) > 1:
>  syscalls = autodict()
>  
>  def trace_begin():
> -	print "Press control+C to stop and show the summary"
> +	print("Press control+C to stop and show the summary")
>  
>  def trace_end():
>  	print_error_totals()
> @@ -57,22 +59,21 @@ def syscalls__sys_exit(event_name, context, common_cpu,
>  
>  def print_error_totals():
>      if for_comm is not None:
> -	    print "\nsyscall errors for %s:\n\n" % (for_comm),
> +	    print("\nsyscall errors for %s:\n" % (for_comm))
>      else:
> -	    print "\nsyscall errors:\n\n",
> +	    print("\nsyscall errors:\n")
>  
> -    print "%-30s  %10s\n" % ("comm [pid]", "count"),
> -    print "%-30s  %10s\n" % ("------------------------------", \
> -                                 "----------"),
> +    print("%-30s  %10s" % ("comm [pid]", "count"))
> +    print("%-30s  %10s" % ("------------------------------", "----------"))
>  
>      comm_keys = syscalls.keys()
>      for comm in comm_keys:
>  	    pid_keys = syscalls[comm].keys()
>  	    for pid in pid_keys:
> -		    print "\n%s [%d]\n" % (comm, pid),
> +		    print("\n%s [%d]" % (comm, pid))
>  		    id_keys = syscalls[comm][pid].keys()
>  		    for id in id_keys:
> -			    print "  syscall: %-16s\n" % syscall_name(id),
> +			    print("  syscall: %-16s" % syscall_name(id))
>  			    ret_keys = syscalls[comm][pid][id].keys()
> -			    for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k),  reverse = True):
> -				    print "    err = %-20s  %10d\n" % (strerror(ret), val),
> +			    for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]),  reverse = True):
> +				    print("    err = %-20s  %10d" % (strerror(ret), val))
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py
  2019-02-25 12:37   ` Neil Horman
@ 2019-02-25 14:43     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:43 UTC (permalink / raw)
  To: Neil Horman; +Cc: Tony Jones, linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Mon, Feb 25, 2019 at 07:37:55AM -0500, Neil Horman escreveu:
> On Fri, Feb 22, 2019 at 03:06:12PM -0800, Tony Jones wrote:
> > Support both Python2 and Python3 in the net_dropmonitor.py script

> Acked-by: Neil Horman <nhorman@tuxdriver.com>

Applied.

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py
  2019-02-22 23:06 ` [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py Tony Jones
@ 2019-02-25 14:44   ` Arnaldo Carvalho de Melo
  2019-02-28  8:08   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:44 UTC (permalink / raw)
  To: Tony Jones
  Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Ravi Bangoria

Em Fri, Feb 22, 2019 at 03:06:13PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the powerpc-hcalls.py script

Applied

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 10/15] perf script python: add Python3 support to sctop.py
  2019-02-22 23:06 ` [PATCH 10/15] perf script python: add Python3 support to sctop.py Tony Jones
@ 2019-02-25 14:44   ` Arnaldo Carvalho de Melo
  2019-02-28  8:09   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:44 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Tom Zanussi

Em Fri, Feb 22, 2019 at 03:06:14PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the sctop.py script

Applied

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py
  2019-02-22 23:06 ` [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py Tony Jones
@ 2019-02-25 14:46   ` Arnaldo Carvalho de Melo
  2019-02-28  8:09   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:46 UTC (permalink / raw)
  To: Tony Jones
  Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Paolo Bonzini

Em Fri, Feb 22, 2019 at 03:06:15PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the stackcollapse.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.

Applied
 
> The use of 'from __future__' implies the minimum supported Python2 version
> is now v2.6
> 
> Signed-off-by: Tony Jones <tonyj@suse.de>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tools/perf/scripts/python/stackcollapse.py | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
> index 1697b5e18c96..5e703efaddcc 100755
> --- a/tools/perf/scripts/python/stackcollapse.py
> +++ b/tools/perf/scripts/python/stackcollapse.py
> @@ -19,6 +19,8 @@
>  # Written by Paolo Bonzini <pbonzini@redhat.com>
>  # Based on Brendan Gregg's stackcollapse-perf.pl script.
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  from collections import defaultdict
> @@ -120,7 +122,6 @@ def process_event(param_dict):
>      lines[stack_string] = lines[stack_string] + 1
>  
>  def trace_end():
> -    list = lines.keys()
> -    list.sort()
> +    list = sorted(lines)
>      for stack in list:
> -        print "%s %d" % (stack, lines[stack])
> +        print("%s %d" % (stack, lines[stack]))
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py
  2019-02-22 23:06 ` [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py Tony Jones
@ 2019-02-25 14:46   ` Arnaldo Carvalho de Melo
  2019-02-28  8:10   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:46 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Jiri Olsa

Em Fri, Feb 22, 2019 at 03:06:16PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the stat-cpi.py script

Applied

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py
  2019-02-22 23:06 ` [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py Tony Jones
@ 2019-02-25 14:47   ` Arnaldo Carvalho de Melo
  2019-02-28  8:11   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:47 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Fri, Feb 22, 2019 at 03:06:17PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the syscall-counts.py script

applied

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py
  2019-02-22 23:06 ` [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py Tony Jones
@ 2019-02-25 14:48   ` Arnaldo Carvalho de Melo
  2019-02-28  8:11   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:48 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Fri, Feb 22, 2019 at 03:06:18PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the syscall-counts-by-pid.py script

Applied

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 15/15] perf script python: add Python3 support to sql scripts
  2019-02-22 23:06 ` [PATCH 15/15] perf script python: add Python3 support to sql scripts Tony Jones
@ 2019-02-25 14:51   ` Arnaldo Carvalho de Melo
  2019-02-25 14:54     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:51 UTC (permalink / raw)
  To: Tony Jones; +Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Fri, Feb 22, 2019 at 03:06:19PM -0800, Tony Jones escreveu:
> Support both Python2 and Python3 in the exported-sql-viewer.py,
> export-to-postgresql.py and export-to-sqlite.py scripts
> 
> 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>
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> ---
>  .../scripts/python/export-to-postgresql.py    | 31 ++++++----
>  tools/perf/scripts/python/export-to-sqlite.py | 26 ++++++---
>  .../scripts/python/exported-sql-viewer.py     | 56 ++++++++++++-------
>  3 files changed, 71 insertions(+), 42 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
> index 30130213da7e..baf972680dc7 100644
> --- a/tools/perf/scripts/python/export-to-postgresql.py
> +++ b/tools/perf/scripts/python/export-to-postgresql.py
> @@ -10,6 +10,8 @@
>  # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>  # more details.
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  import struct
> @@ -234,12 +236,17 @@ perf_db_export_mode = True
>  perf_db_export_calls = False
>  perf_db_export_callchains = False
>  
> +def printerr(*args, **kw_args):
> +    print(*args, file=sys.stderr, **kw_args)
> +
> +def printdate(*args, **kw_args):
> +        print(datetime.datetime.today(), *args, sep=' ', **kw_args)

So this one introduces inconsistencies in indentation, i.e. the above
two routines don't use tabs and one uses 4 spaces while the other uses 8
spaces :-\

I'm converting them to use tabs, like the rest of this script, ok?

- Arnaldo
  
>  def usage():
> -	print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]"
> -	print >> sys.stderr, "where:	columns		'all' or 'branches'"
> -	print >> sys.stderr, "		calls		'calls' => create calls and call_paths table"
> -	print >> sys.stderr, "		callchains	'callchains' => create call_paths table"
> +	printerr("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]")
> +	printerr("where:	columns		'all' or 'branches'")
> +	printerr("		calls		'calls' => create calls and call_paths table")
> +	printerr("		callchains	'callchains' => create call_paths table")
>  	raise Exception("Too few arguments")
>  
>  if (len(sys.argv) < 2):
> @@ -273,7 +280,7 @@ def do_query(q, s):
>  		return
>  	raise Exception("Query failed: " + q.lastError().text())
>  
> -print datetime.datetime.today(), "Creating database..."
> +printdate("Creating database...")
>  
>  db = QSqlDatabase.addDatabase('QPSQL')
>  query = QSqlQuery(db)
> @@ -564,7 +571,7 @@ if perf_db_export_calls:
>  	call_file		= open_output_file("call_table.bin")
>  
>  def trace_begin():
> -	print datetime.datetime.today(), "Writing to intermediate files..."
> +	printdate("Writing to intermediate files...")
>  	# id == 0 means unknown.  It is easier to create records for them than replace the zeroes with NULLs
>  	evsel_table(0, "unknown")
>  	machine_table(0, 0, "unknown")
> @@ -579,7 +586,7 @@ def trace_begin():
>  unhandled_count = 0
>  
>  def trace_end():
> -	print datetime.datetime.today(), "Copying to database..."
> +	printdate("Copying to database...")
>  	copy_output_file(evsel_file,		"selected_events")
>  	copy_output_file(machine_file,		"machines")
>  	copy_output_file(thread_file,		"threads")
> @@ -594,7 +601,7 @@ def trace_end():
>  	if perf_db_export_calls:
>  		copy_output_file(call_file,		"calls")
>  
> -	print datetime.datetime.today(), "Removing intermediate files..."
> +	printdate("Removing intermediate files...")
>  	remove_output_file(evsel_file)
>  	remove_output_file(machine_file)
>  	remove_output_file(thread_file)
> @@ -609,7 +616,7 @@ def trace_end():
>  	if perf_db_export_calls:
>  		remove_output_file(call_file)
>  	os.rmdir(output_dir_name)
> -	print datetime.datetime.today(), "Adding primary keys"
> +	printdate("Adding primary keys")
>  	do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
>  	do_query(query, 'ALTER TABLE machines        ADD PRIMARY KEY (id)')
>  	do_query(query, 'ALTER TABLE threads         ADD PRIMARY KEY (id)')
> @@ -624,7 +631,7 @@ def trace_end():
>  	if perf_db_export_calls:
>  		do_query(query, 'ALTER TABLE calls           ADD PRIMARY KEY (id)')
>  
> -	print datetime.datetime.today(), "Adding foreign keys"
> +	printdate("Adding foreign keys")
>  	do_query(query, 'ALTER TABLE threads '
>  					'ADD CONSTRAINT machinefk  FOREIGN KEY (machine_id)   REFERENCES machines   (id),'
>  					'ADD CONSTRAINT processfk  FOREIGN KEY (process_id)   REFERENCES threads    (id)')
> @@ -659,8 +666,8 @@ def trace_end():
>  		do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
>  
>  	if (unhandled_count):
> -		print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
> -	print datetime.datetime.today(), "Done"
> +		printdate("Warning: ", unhandled_count, " unhandled events")
> +	printdate("Done")
>  
>  def trace_unhandled(event_name, context, event_fields_dict):
>  	global unhandled_count
> diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py
> index ed237f2ed03f..f56222d22a6e 100644
> --- a/tools/perf/scripts/python/export-to-sqlite.py
> +++ b/tools/perf/scripts/python/export-to-sqlite.py
> @@ -10,6 +10,8 @@
>  # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>  # more details.
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  import struct
> @@ -60,11 +62,17 @@ perf_db_export_mode = True
>  perf_db_export_calls = False
>  perf_db_export_callchains = False
>  
> +def printerr(*args, **keyword_args):
> +    print(*args, file=sys.stderr, **keyword_args)
> +
> +def printdate(*args, **kw_args):
> +        print(datetime.datetime.today(), *args, sep=' ', **kw_args)
> +
>  def usage():
> -	print >> sys.stderr, "Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]"
> -	print >> sys.stderr, "where:	columns		'all' or 'branches'"
> -	print >> sys.stderr, "		calls		'calls' => create calls and call_paths table"
> -	print >> sys.stderr, "		callchains	'callchains' => create call_paths table"
> +	printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]");
> +	printerr("where:	columns		'all' or 'branches'");
> +	printerr("		calls		'calls' => create calls and call_paths table");
> +	printerr("		callchains	'callchains' => create call_paths table");
>  	raise Exception("Too few arguments")
>  
>  if (len(sys.argv) < 2):
> @@ -100,7 +108,7 @@ def do_query_(q):
>  		return
>  	raise Exception("Query failed: " + q.lastError().text())
>  
> -print datetime.datetime.today(), "Creating database..."
> +printdate("Creating database ...")
>  
>  db_exists = False
>  try:
> @@ -376,7 +384,7 @@ if perf_db_export_calls:
>  	call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
>  
>  def trace_begin():
> -	print datetime.datetime.today(), "Writing records..."
> +	printdate("Writing records...")
>  	do_query(query, 'BEGIN TRANSACTION')
>  	# id == 0 means unknown.  It is easier to create records for them than replace the zeroes with NULLs
>  	evsel_table(0, "unknown")
> @@ -394,13 +402,13 @@ unhandled_count = 0
>  def trace_end():
>  	do_query(query, 'END TRANSACTION')
>  
> -	print datetime.datetime.today(), "Adding indexes"
> +	printdate("Adding indexes")
>  	if perf_db_export_calls:
>  		do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
>  
>  	if (unhandled_count):
> -		print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
> -	print datetime.datetime.today(), "Done"
> +		printdate("Warning: ", unhandled_count, " unhandled events")
> +	printdate("Done")
>  
>  def trace_unhandled(event_name, context, event_fields_dict):
>  	global unhandled_count
> diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py
> index c3091401df91..9bc03b8f77a5 100755
> --- a/tools/perf/scripts/python/exported-sql-viewer.py
> +++ b/tools/perf/scripts/python/exported-sql-viewer.py
> @@ -87,11 +87,20 @@
>  #                                                                              7fab593ea956 48 89 15 3b 13 22 00                            movq  %rdx, 0x22133b(%rip)
>  # 8107675243232  2    ls       22011  22011  hardware interrupt     No         7fab593ea956 _dl_start+0x26 (ld-2.19.so) -> ffffffff86a012e0 page_fault ([kernel])
>  
> +from __future__ import print_function
> +
>  import sys
>  import weakref
>  import threading
>  import string
> -import cPickle
> +try:
> +    # Python2
> +    import cPickle as pickle
> +    # size of pickled integer big enough for record size
> +    glb_nsz = 8
> +except ImportError:
> +    import pickle
> +    glb_nsz = 16
>  import re
>  import os
>  from PySide.QtCore import *
> @@ -101,6 +110,15 @@ from decimal import *
>  from ctypes import *
>  from multiprocessing import Process, Array, Value, Event
>  
> +# xrange is range in Python3
> +try:
> +    xrange
> +except NameError:
> +    xrange = range
> +
> +def printerr(*args, **keyword_args):
> +    print(*args, file=sys.stderr, **keyword_args)
> +
>  # Data formatting helpers
>  
>  def tohex(ip):
> @@ -811,10 +829,6 @@ class ChildDataItemFinder():
>  
>  glb_chunk_sz = 10000
>  
> -# size of pickled integer big enough for record size
> -
> -glb_nsz = 8
> -
>  # Background process for SQL data fetcher
>  
>  class SQLFetcherProcess():
> @@ -873,7 +887,7 @@ class SQLFetcherProcess():
>  				return True
>  			if space >= glb_nsz:
>  				# Use 0 (or space < glb_nsz) to mean there is no more at the top of the buffer
> -				nd = cPickle.dumps(0, cPickle.HIGHEST_PROTOCOL)
> +				nd = pickle.dumps(0, pickle.HIGHEST_PROTOCOL)
>  				self.buffer[self.local_head : self.local_head + len(nd)] = nd
>  			self.local_head = 0
>  		if self.local_tail - self.local_head > sz:
> @@ -891,9 +905,9 @@ class SQLFetcherProcess():
>  			self.wait_event.wait()
>  
>  	def AddToBuffer(self, obj):
> -		d = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL)
> +		d = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
>  		n = len(d)
> -		nd = cPickle.dumps(n, cPickle.HIGHEST_PROTOCOL)
> +		nd = pickle.dumps(n, pickle.HIGHEST_PROTOCOL)
>  		sz = n + glb_nsz
>  		self.WaitForSpace(sz)
>  		pos = self.local_head
> @@ -1005,12 +1019,12 @@ class SQLFetcher(QObject):
>  		pos = self.local_tail
>  		if len(self.buffer) - pos < glb_nsz:
>  			pos = 0
> -		n = cPickle.loads(self.buffer[pos : pos + glb_nsz])
> +		n = pickle.loads(self.buffer[pos : pos + glb_nsz])
>  		if n == 0:
>  			pos = 0
> -			n = cPickle.loads(self.buffer[0 : glb_nsz])
> +			n = pickle.loads(self.buffer[0 : glb_nsz])
>  		pos += glb_nsz
> -		obj = cPickle.loads(self.buffer[pos : pos + n])
> +		obj = pickle.loads(self.buffer[pos : pos + n])
>  		self.local_tail = pos + n
>  		return obj
>  
> @@ -1559,7 +1573,7 @@ class SQLTableDialogDataItem():
>  					return str(lower_id)
>  
>  	def ConvertRelativeTime(self, val):
> -		print "val ", val
> +		print("val ", val)
>  		mult = 1
>  		suffix = val[-2:]
>  		if suffix == "ms":
> @@ -1581,29 +1595,29 @@ class SQLTableDialogDataItem():
>  		return str(val)
>  
>  	def ConvertTimeRange(self, vrange):
> -		print "vrange ", vrange
> +		print("vrange ", vrange)
>  		if vrange[0] == "":
>  			vrange[0] = str(self.first_time)
>  		if vrange[1] == "":
>  			vrange[1] = str(self.last_time)
>  		vrange[0] = self.ConvertRelativeTime(vrange[0])
>  		vrange[1] = self.ConvertRelativeTime(vrange[1])
> -		print "vrange2 ", vrange
> +		print("vrange2 ", vrange)
>  		if not self.IsNumber(vrange[0]) or not self.IsNumber(vrange[1]):
>  			return False
> -		print "ok1"
> +		print("ok1")
>  		beg_range = max(int(vrange[0]), self.first_time)
>  		end_range = min(int(vrange[1]), self.last_time)
>  		if beg_range > self.last_time or end_range < self.first_time:
>  			return False
> -		print "ok2"
> +		print("ok2")
>  		vrange[0] = self.BinarySearchTime(0, self.last_id, beg_range, True)
>  		vrange[1] = self.BinarySearchTime(1, self.last_id + 1, end_range, False)
> -		print "vrange3 ", vrange
> +		print("vrange3 ", vrange)
>  		return True
>  
>  	def AddTimeRange(self, value, ranges):
> -		print "value ", value
> +		print("value ", value)
>  		n = value.count("-")
>  		if n == 1:
>  			pass
> @@ -2577,7 +2591,7 @@ class DBRef():
>  
>  def Main():
>  	if (len(sys.argv) < 2):
> -		print >> sys.stderr, "Usage is: exported-sql-viewer.py {<database name> | --help-only}"
> +		printerr("Usage is: exported-sql-viewer.py {<database name> | --help-only}");
>  		raise Exception("Too few arguments")
>  
>  	dbname = sys.argv[1]
> @@ -2590,8 +2604,8 @@ def Main():
>  
>  	is_sqlite3 = False
>  	try:
> -		f = open(dbname)
> -		if f.read(15) == "SQLite format 3":
> +		f = open(dbname, "rb")
> +		if f.read(15) == b'SQLite format 3':
>  			is_sqlite3 = True
>  		f.close()
>  	except:
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 15/15] perf script python: add Python3 support to sql scripts
  2019-02-25 14:51   ` Arnaldo Carvalho de Melo
@ 2019-02-25 14:54     ` Arnaldo Carvalho de Melo
  2019-02-25 17:20       ` Tony Jones
  0 siblings, 1 reply; 45+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-02-25 14:54 UTC (permalink / raw)
  To: Tony Jones
  Cc: Adrian Hunter, linux-kernel, linux-perf-users, Seeteena Thoufeek

Em Mon, Feb 25, 2019 at 11:51:19AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Feb 22, 2019 at 03:06:19PM -0800, Tony Jones escreveu:
> > Support both Python2 and Python3 in the exported-sql-viewer.py,
> > export-to-postgresql.py and export-to-sqlite.py scripts
<SNIP>
> > @@ -234,12 +236,17 @@ perf_db_export_mode = True
> >  perf_db_export_calls = False
> >  perf_db_export_callchains = False
> >  
> > +def printerr(*args, **kw_args):
> > +    print(*args, file=sys.stderr, **kw_args)
> > +
> > +def printdate(*args, **kw_args):
> > +        print(datetime.datetime.today(), *args, sep=' ', **kw_args)
> 
> So this one introduces inconsistencies in indentation, i.e. the above
> two routines don't use tabs and one uses 4 spaces while the other uses 8
> spaces :-\
> 
> I'm converting them to use tabs, like the rest of this script, ok?

But it is not applying, Adrian did work recently here, can you please
address this and resubmit?

I'm pushing what I have already merged, please update your
acme/perf/core branch and continue from there.

Thanks!

- Arnaldo

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py
  2019-02-25 14:03     ` Arnaldo Carvalho de Melo
@ 2019-02-25 17:18       ` Tony Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-25 17:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Adrian Hunter
  Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek

On 2/25/19 6:03 AM, Arnaldo Carvalho de Melo wrote:
> Em Mon, Feb 25, 2019 at 09:07:03AM +0200, Adrian Hunter escreveu:
>> On 23/02/19 1:06 AM, Tony Jones wrote:
>>> Support both Python2 and Python3 in the intel-pt-events.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.
>>>
>>> Fix space/tab inconsistency as python3 enforces consistency.
>>
>> It would be better for the white space changes to be a separate patch.
>>
>> But I am not in favour of using spaces instead of tabs because it is the
>> opposite of what we tend to do with C.
>>
>> Arnaldo, can you provide a guideline on this?
> 
> Yeah, please separate things, this would help me now to pick the
> uncontroversial part while we discuss the other.
> 
> And I'm in favour of being consistent with what we do for C code, i.e.
> use TABs.
> 
> I'm now processing the other patches.

I'll split and resubmit.

Also, FYI, PEP8 states "Spaces are the preferred indentation method".



^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 15/15] perf script python: add Python3 support to sql scripts
  2019-02-25 14:54     ` Arnaldo Carvalho de Melo
@ 2019-02-25 17:20       ` Tony Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-25 17:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Adrian Hunter, linux-kernel, linux-perf-users, Seeteena Thoufeek

On 2/25/19 6:54 AM, Arnaldo Carvalho de Melo wrote:
> Em Mon, Feb 25, 2019 at 11:51:19AM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Feb 22, 2019 at 03:06:19PM -0800, Tony Jones escreveu:
>>> Support both Python2 and Python3 in the exported-sql-viewer.py,
>>> export-to-postgresql.py and export-to-sqlite.py scripts
> <SNIP>
>>> @@ -234,12 +236,17 @@ perf_db_export_mode = True
>>>  perf_db_export_calls = False
>>>  perf_db_export_callchains = False
>>>  
>>> +def printerr(*args, **kw_args):
>>> +    print(*args, file=sys.stderr, **kw_args)
>>> +
>>> +def printdate(*args, **kw_args):
>>> +        print(datetime.datetime.today(), *args, sep=' ', **kw_args)
>>
>> So this one introduces inconsistencies in indentation, i.e. the above
>> two routines don't use tabs and one uses 4 spaces while the other uses 8
>> spaces :-\
>>
>> I'm converting them to use tabs, like the rest of this script, ok?
> 
> But it is not applying, Adrian did work recently here, can you please
> address this and resubmit?

I was using perf/perf/core.   I'll take a look.

Also, I agree we should be consistent on indentation.    

^ permalink raw reply	[flat|nested] 45+ messages in thread

* Re: [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py
  2019-02-25 14:05   ` Arnaldo Carvalho de Melo
@ 2019-02-25 18:05     ` Tony Jones
  0 siblings, 0 replies; 45+ messages in thread
From: Tony Jones @ 2019-02-25 18:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-perf-users, Seeteena Thoufeek, Tom Zanussi

On 2/25/19 6:05 AM, Arnaldo Carvalho de Melo wrote:
> Em Fri, Feb 22, 2019 at 03:06:06PM -0800, Tony Jones escreveu:
>> Support both Python 2 and Python 3 in the check-perf-trace.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.
>>
>> Also correct inconsistent indentation which was being flagged by Python3.
> 
> When we have "Also" in a patch, usually it need to be split :-)

The indentation changes were required for Python3. So I viewed them as part of the change
to support Python3 ;-)  However, splitting them is no problem.    I'll resubmit.

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to netdev-times.py
  2019-02-22 23:06 ` [PATCH 01/15] perf script python: add Python3 support to netdev-times.py Tony Jones
@ 2019-02-28  8:06   ` tip-bot for Tony Jones
  0 siblings, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:06 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tonyj, sanagi.koki, mingo, hpa, acme, tglx, s1seetee, linux-kernel

Commit-ID:  02b03ec383e0c79d73aa4b402b3427a8b490ef9f
Gitweb:     https://git.kernel.org/tip/02b03ec383e0c79d73aa4b402b3427a8b490ef9f
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:05 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:16:42 -0300

perf script python: Add Python3 support to netdev-times.py

Support both Python2 and Python3 in the netdev-times.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>
Cc: Sanagi Koki <sanagi.koki@jp.fujitsu.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-2-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/netdev-times.py | 82 ++++++++++++++++---------------
 1 file changed, 42 insertions(+), 40 deletions(-)

diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py
index 9b2050f778f1..267bda49325d 100644
--- a/tools/perf/scripts/python/netdev-times.py
+++ b/tools/perf/scripts/python/netdev-times.py
@@ -8,6 +8,8 @@
 # dev=: show only thing related to specified device
 # debug: work with debug mode. It shows buffer status.
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -17,6 +19,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 from perf_trace_context import *
 from Core import *
 from Util import *
+from functools import cmp_to_key
 
 all_event_list = []; # insert all tracepoint event related with this script
 irq_dic = {}; # key is cpu and value is a list which stacks irqs
@@ -61,12 +64,12 @@ def diff_msec(src, dst):
 def print_transmit(hunk):
 	if dev != 0 and hunk['dev'].find(dev) < 0:
 		return
-	print "%7s %5d %6d.%06dsec %12.3fmsec      %12.3fmsec" % \
+	print("%7s %5d %6d.%06dsec %12.3fmsec      %12.3fmsec" %
 		(hunk['dev'], hunk['len'],
 		nsecs_secs(hunk['queue_t']),
 		nsecs_nsecs(hunk['queue_t'])/1000,
 		diff_msec(hunk['queue_t'], hunk['xmit_t']),
-		diff_msec(hunk['xmit_t'], hunk['free_t']))
+		diff_msec(hunk['xmit_t'], hunk['free_t'])))
 
 # Format for displaying rx packet processing
 PF_IRQ_ENTRY= "  irq_entry(+%.3fmsec irq=%d:%s)"
@@ -98,55 +101,55 @@ def print_receive(hunk):
 	if show_hunk == 0:
 		return
 
-	print "%d.%06dsec cpu=%d" % \
-		(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)
+	print("%d.%06dsec cpu=%d" %
+		(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu))
 	for i in range(len(irq_list)):
-		print PF_IRQ_ENTRY % \
+		print(PF_IRQ_ENTRY %
 			(diff_msec(base_t, irq_list[i]['irq_ent_t']),
-			irq_list[i]['irq'], irq_list[i]['name'])
-		print PF_JOINT
+			irq_list[i]['irq'], irq_list[i]['name']))
+		print(PF_JOINT)
 		irq_event_list = irq_list[i]['event_list']
 		for j in range(len(irq_event_list)):
 			irq_event = irq_event_list[j]
 			if irq_event['event'] == 'netif_rx':
-				print PF_NET_RX % \
+				print(PF_NET_RX %
 					(diff_msec(base_t, irq_event['time']),
-					irq_event['skbaddr'])
-				print PF_JOINT
-	print PF_SOFT_ENTRY % \
-		diff_msec(base_t, hunk['sirq_ent_t'])
-	print PF_JOINT
+					irq_event['skbaddr']))
+				print(PF_JOINT)
+	print(PF_SOFT_ENTRY %
+		diff_msec(base_t, hunk['sirq_ent_t']))
+	print(PF_JOINT)
 	event_list = hunk['event_list']
 	for i in range(len(event_list)):
 		event = event_list[i]
 		if event['event_name'] == 'napi_poll':
-			print PF_NAPI_POLL % \
-			    (diff_msec(base_t, event['event_t']), event['dev'])
+			print(PF_NAPI_POLL %
+			    (diff_msec(base_t, event['event_t']), event['dev']))
 			if i == len(event_list) - 1:
-				print ""
+				print("")
 			else:
-				print PF_JOINT
+				print(PF_JOINT)
 		else:
-			print PF_NET_RECV % \
+			print(PF_NET_RECV %
 			    (diff_msec(base_t, event['event_t']), event['skbaddr'],
-				event['len'])
+				event['len']))
 			if 'comm' in event.keys():
-				print PF_WJOINT
-				print PF_CPY_DGRAM % \
+				print(PF_WJOINT)
+				print(PF_CPY_DGRAM %
 					(diff_msec(base_t, event['comm_t']),
-					event['pid'], event['comm'])
+					event['pid'], event['comm']))
 			elif 'handle' in event.keys():
-				print PF_WJOINT
+				print(PF_WJOINT)
 				if event['handle'] == "kfree_skb":
-					print PF_KFREE_SKB % \
+					print(PF_KFREE_SKB %
 						(diff_msec(base_t,
 						event['comm_t']),
-						event['location'])
+						event['location']))
 				elif event['handle'] == "consume_skb":
-					print PF_CONS_SKB % \
+					print(PF_CONS_SKB %
 						diff_msec(base_t,
-							event['comm_t'])
-			print PF_JOINT
+							event['comm_t']))
+			print(PF_JOINT)
 
 def trace_begin():
 	global show_tx
@@ -172,8 +175,7 @@ def trace_begin():
 
 def trace_end():
 	# order all events in time
-	all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME],
-					    b[EINFO_IDX_TIME]))
+	all_event_list.sort(key=cmp_to_key(lambda a,b :a[EINFO_IDX_TIME] < b[EINFO_IDX_TIME]))
 	# process all events
 	for i in range(len(all_event_list)):
 		event_info = all_event_list[i]
@@ -210,19 +212,19 @@ def trace_end():
 			print_receive(receive_hunk_list[i])
 	# display transmit hunks
 	if show_tx:
-		print "   dev    len      Qdisc        " \
-			"       netdevice             free"
+		print("   dev    len      Qdisc        "
+			"       netdevice             free")
 		for i in range(len(tx_free_list)):
 			print_transmit(tx_free_list[i])
 	if debug:
-		print "debug buffer status"
-		print "----------------------------"
-		print "xmit Qdisc:remain:%d overflow:%d" % \
-			(len(tx_queue_list), of_count_tx_queue_list)
-		print "xmit netdevice:remain:%d overflow:%d" % \
-			(len(tx_xmit_list), of_count_tx_xmit_list)
-		print "receive:remain:%d overflow:%d" % \
-			(len(rx_skb_list), of_count_rx_skb_list)
+		print("debug buffer status")
+		print("----------------------------")
+		print("xmit Qdisc:remain:%d overflow:%d" %
+			(len(tx_queue_list), of_count_tx_queue_list))
+		print("xmit netdevice:remain:%d overflow:%d" %
+			(len(tx_xmit_list), of_count_tx_xmit_list))
+		print("receive:remain:%d overflow:%d" %
+			(len(rx_skb_list), of_count_rx_skb_list))
 
 # called from perf, when it finds a correspoinding event
 def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec):

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to failed-syscalls-by-pid.py
  2019-02-22 23:06 ` [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py Tony Jones
  2019-02-25 14:09   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:06   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:06 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, acme, mingo, s1seetee, tonyj, tglx, tzanussi, linux-kernel

Commit-ID:  9b2700efc57f46fe63beee5f64fcfe2746936b4e
Gitweb:     https://git.kernel.org/tip/9b2700efc57f46fe63beee5f64fcfe2746936b4e
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:08 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:16:48 -0300

perf script python: Add Python3 support to failed-syscalls-by-pid.py

Support both Python2 and Python3 in the failed-syscalls-by-pid.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>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-5-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/failed-syscalls-by-pid.py | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py
index cafeff3d74db..3648e8b986ec 100644
--- a/tools/perf/scripts/python/failed-syscalls-by-pid.py
+++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py
@@ -5,6 +5,8 @@
 # Displays system-wide failed system call totals, broken down by pid.
 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -32,7 +34,7 @@ if len(sys.argv) > 1:
 syscalls = autodict()
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	print_error_totals()
@@ -57,22 +59,21 @@ def syscalls__sys_exit(event_name, context, common_cpu,
 
 def print_error_totals():
     if for_comm is not None:
-	    print "\nsyscall errors for %s:\n\n" % (for_comm),
+	    print("\nsyscall errors for %s:\n" % (for_comm))
     else:
-	    print "\nsyscall errors:\n\n",
+	    print("\nsyscall errors:\n")
 
-    print "%-30s  %10s\n" % ("comm [pid]", "count"),
-    print "%-30s  %10s\n" % ("------------------------------", \
-                                 "----------"),
+    print("%-30s  %10s" % ("comm [pid]", "count"))
+    print("%-30s  %10s" % ("------------------------------", "----------"))
 
     comm_keys = syscalls.keys()
     for comm in comm_keys:
 	    pid_keys = syscalls[comm].keys()
 	    for pid in pid_keys:
-		    print "\n%s [%d]\n" % (comm, pid),
+		    print("\n%s [%d]" % (comm, pid))
 		    id_keys = syscalls[comm][pid].keys()
 		    for id in id_keys:
-			    print "  syscall: %-16s\n" % syscall_name(id),
+			    print("  syscall: %-16s" % syscall_name(id))
 			    ret_keys = syscalls[comm][pid][id].keys()
-			    for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k),  reverse = True):
-				    print "    err = %-20s  %10d\n" % (strerror(ret), val),
+			    for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]),  reverse = True):
+				    print("    err = %-20s  %10d" % (strerror(ret), val))

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to mem-phys-addr.py
  2019-02-22 23:06 ` [PATCH 07/15] perf script python: add Python3 support to mem-phys-addr.py Tony Jones
@ 2019-02-28  8:07   ` tip-bot for Tony Jones
  0 siblings, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:07 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: s1seetee, tonyj, linux-kernel, tglx, hpa, acme, mingo

Commit-ID:  e4d053ddb4c48cbde27b4c5edd3cc8f957684e4f
Gitweb:     https://git.kernel.org/tip/e4d053ddb4c48cbde27b4c5edd3cc8f957684e4f
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:11 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:16:51 -0300

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>
---
 tools/perf/scripts/python/mem-phys-addr.py | 24 ++++++++++++++----------
 1 file 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 @@
 # Copyright (c) 2018, Intel Corporation.
 
 from __future__ import division
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -31,21 +33,23 @@ def parse_iomem():
 	for i, j in enumerate(f):
 		m = re.split('-|:',j,2)
 		if m[2].strip() == 'System RAM':
-			system_ram.append(long(m[0], 16))
-			system_ram.append(long(m[1], 16))
+			system_ram.append(int(m[0], 16))
+			system_ram.append(int(m[1], 16))
 		if m[2].strip() == 'Persistent Memory':
-			pmem.append(long(m[0], 16))
-			pmem.append(long(m[1], 16))
+			pmem.append(int(m[0], 16))
+			pmem.append(int(m[1], 16))
 
 def print_memory_type():
-	print "Event: %s" % (event_name)
-	print "%-40s  %10s  %10s\n" % ("Memory type", "count", "percentage"),
-	print "%-40s  %10s  %10s\n" % ("----------------------------------------", \
+	print("Event: %s" % (event_name))
+	print("%-40s  %10s  %10s\n" % ("Memory type", "count", "percentage"), end='')
+	print("%-40s  %10s  %10s\n" % ("----------------------------------------",
 					"-----------", "-----------"),
+                                        end='');
 	total = sum(load_mem_type_cnt.values())
 	for mem_type, count in sorted(load_mem_type_cnt.most_common(), \
-					key = lambda(k, v): (v, k), reverse = True):
-		print "%-40s  %10d  %10.1f%%\n" % (mem_type, count, 100 * count / total),
+					key = lambda kv: (kv[1], kv[0]), reverse = True):
+		print("%-40s  %10d  %10.1f%%\n" % (mem_type, count, 100 * count / total),
+                        end='')
 
 def trace_begin():
 	parse_iomem()
@@ -80,7 +84,7 @@ def find_memory_type(phys_addr):
 	f.seek(0, 0)
 	for j in f:
 		m = re.split('-|:',j,2)
-		if long(m[0], 16) <= phys_addr <= long(m[1], 16):
+		if int(m[0], 16) <= phys_addr <= int(m[1], 16):
 			return m[2]
 	return "N/A"
 

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to net_dropmonitor.py
  2019-02-22 23:06 ` [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py Tony Jones
  2019-02-25 12:37   ` Neil Horman
@ 2019-02-28  8:08   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, nhorman, mingo, s1seetee, acme, linux-kernel, hpa, tonyj

Commit-ID:  8c42b9600e561666233b9c557a5209d0dc853ba1
Gitweb:     https://git.kernel.org/tip/8c42b9600e561666233b9c557a5209d0dc853ba1
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:12 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:16:55 -0300

perf script python: Add Python3 support to net_dropmonitor.py

Support both Python2 and Python3 in the net_dropmonitor.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>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-9-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/net_dropmonitor.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py
index a150164b44a3..212557a02c50 100755
--- a/tools/perf/scripts/python/net_dropmonitor.py
+++ b/tools/perf/scripts/python/net_dropmonitor.py
@@ -1,6 +1,8 @@
 # Monitor the system for dropped packets and proudce a report of drop locations and counts
 # SPDX-License-Identifier: GPL-2.0
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -50,19 +52,19 @@ def get_sym(sloc):
 		return (None, 0)
 
 def print_drop_table():
-	print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
+	print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
 	for i in drop_log.keys():
 		(sym, off) = get_sym(i)
 		if sym == None:
 			sym = i
-		print "%25s %25s %25s" % (sym, off, drop_log[i])
+		print("%25s %25s %25s" % (sym, off, drop_log[i]))
 
 
 def trace_begin():
-	print "Starting trace (Ctrl-C to dump results)"
+	print("Starting trace (Ctrl-C to dump results)")
 
 def trace_end():
-	print "Gathering kallsyms data"
+	print("Gathering kallsyms data")
 	get_kallsyms_table()
 	print_drop_table()
 

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to powerpc-hcalls.py
  2019-02-22 23:06 ` [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py Tony Jones
  2019-02-25 14:44   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:08   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tonyj, tglx, linux-kernel, acme, s1seetee, ravi.bangoria, mingo, hpa

Commit-ID:  118af5bf799bd1876c3999766d1d2f845d45f019
Gitweb:     https://git.kernel.org/tip/118af5bf799bd1876c3999766d1d2f845d45f019
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:13 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:16:57 -0300

perf script python: Add Python3 support to powerpc-hcalls.py

Support both Python2 and Python3 in the powerpc-hcalls.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>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-10-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/powerpc-hcalls.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py
index 00e0e7476e55..8b78dc790adb 100644
--- a/tools/perf/scripts/python/powerpc-hcalls.py
+++ b/tools/perf/scripts/python/powerpc-hcalls.py
@@ -4,6 +4,8 @@
 #
 # Hypervisor call statisics
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -149,7 +151,7 @@ hcall_table = {
 }
 
 def hcall_table_lookup(opcode):
-	if (hcall_table.has_key(opcode)):
+	if (opcode in hcall_table):
 		return hcall_table[opcode]
 	else:
 		return opcode
@@ -157,8 +159,8 @@ def hcall_table_lookup(opcode):
 print_ptrn = '%-28s%10s%10s%10s%10s'
 
 def trace_end():
-	print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)')
-	print '-' * 68
+	print(print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)'))
+	print('-' * 68)
 	for opcode in output:
 		h_name = hcall_table_lookup(opcode)
 		time = output[opcode]['time']
@@ -166,14 +168,14 @@ def trace_end():
 		min_t = output[opcode]['min']
 		max_t = output[opcode]['max']
 
-		print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt)
+		print(print_ptrn % (h_name, cnt, min_t, max_t, time//cnt))
 
 def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
 			opcode, retval):
-	if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)):
+	if (cpu in d_enter and opcode in d_enter[cpu]):
 		diff = nsecs(sec, nsec) - d_enter[cpu][opcode]
 
-		if (output.has_key(opcode)):
+		if (opcode in output):
 			output[opcode]['time'] += diff
 			output[opcode]['cnt'] += 1
 			if (output[opcode]['min'] > diff):
@@ -190,11 +192,11 @@ def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain,
 
 		del d_enter[cpu][opcode]
 #	else:
-#		print "Can't find matching hcall_enter event. Ignoring sample"
+#		print("Can't find matching hcall_enter event. Ignoring sample")
 
 def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm,
 			 callchain, opcode):
-		if (d_enter.has_key(cpu)):
+		if (cpu in d_enter):
 			d_enter[cpu][opcode] = nsecs(sec, nsec)
 		else:
 			d_enter[cpu] = {opcode: nsecs(sec, nsec)}

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to sctop.py
  2019-02-22 23:06 ` [PATCH 10/15] perf script python: add Python3 support to sctop.py Tony Jones
  2019-02-25 14:44   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:09   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, tglx, mingo, tonyj, tzanussi, acme, hpa, s1seetee

Commit-ID:  ee75a896ae535d4219a82cc361be96394536f3ba
Gitweb:     https://git.kernel.org/tip/ee75a896ae535d4219a82cc361be96394536f3ba
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:14 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:17:03 -0300

perf script python: Add Python3 support to sctop.py

Support both Python2 and Python3 in the sctop.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>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-11-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/sctop.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py
index 61621b93affb..987ffae7c8ca 100644
--- a/tools/perf/scripts/python/sctop.py
+++ b/tools/perf/scripts/python/sctop.py
@@ -8,7 +8,14 @@
 # will be refreshed every [interval] seconds.  The default interval is
 # 3 seconds.
 
-import os, sys, thread, time
+from __future__ import print_function
+
+import os, sys, time
+
+try:
+        import thread
+except ImportError:
+        import _thread as thread
 
 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -62,18 +69,19 @@ def print_syscall_totals(interval):
 	while 1:
 		clear_term()
 		if for_comm is not None:
-			print "\nsyscall events for %s:\n\n" % (for_comm),
+			print("\nsyscall events for %s:\n" % (for_comm))
 		else:
-			print "\nsyscall events:\n\n",
+			print("\nsyscall events:\n")
 
-		print "%-40s  %10s\n" % ("event", "count"),
-		print "%-40s  %10s\n" % ("----------------------------------------", \
-						 "----------"),
+		print("%-40s  %10s" % ("event", "count"))
+		print("%-40s  %10s" %
+                        ("----------------------------------------",
+                        "----------"))
 
-		for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
+		for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
 					      reverse = True):
 			try:
-				print "%-40s  %10d\n" % (syscall_name(id), val),
+				print("%-40s  %10d" % (syscall_name(id), val))
 			except TypeError:
 				pass
 		syscalls.clear()

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to stackcollapse.py
  2019-02-22 23:06 ` [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py Tony Jones
  2019-02-25 14:46   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:09   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, tonyj, pbonzini, hpa, acme, mingo, s1seetee, linux-kernel

Commit-ID:  6d22d9991cf37edfe861569e2433342ad56206a7
Gitweb:     https://git.kernel.org/tip/6d22d9991cf37edfe861569e2433342ad56206a7
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:15 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:17:05 -0300

perf script python: Add Python3 support to stackcollapse.py

Support both Python2 and Python3 in the stackcollapse.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>
Cc: Paolo Bonzini <pbonzini@redhat.com> <pbonzini@redhat.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-12-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/stackcollapse.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py
index 1697b5e18c96..5e703efaddcc 100755
--- a/tools/perf/scripts/python/stackcollapse.py
+++ b/tools/perf/scripts/python/stackcollapse.py
@@ -19,6 +19,8 @@
 # Written by Paolo Bonzini <pbonzini@redhat.com>
 # Based on Brendan Gregg's stackcollapse-perf.pl script.
 
+from __future__ import print_function
+
 import os
 import sys
 from collections import defaultdict
@@ -120,7 +122,6 @@ def process_event(param_dict):
     lines[stack_string] = lines[stack_string] + 1
 
 def trace_end():
-    list = lines.keys()
-    list.sort()
+    list = sorted(lines)
     for stack in list:
-        print "%s %d" % (stack, lines[stack])
+        print("%s %d" % (stack, lines[stack]))

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to stat-cpi.py
  2019-02-22 23:06 ` [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py Tony Jones
  2019-02-25 14:46   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:10   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: s1seetee, tonyj, acme, jolsa, tglx, hpa, mingo, linux-kernel

Commit-ID:  e985bf761db7646cebcd236249da08bd264069de
Gitweb:     https://git.kernel.org/tip/e985bf761db7646cebcd236249da08bd264069de
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:16 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:17:07 -0300

perf script python: Add Python3 support to stat-cpi.py

Support both Python2 and Python3 in the stat-cpi.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: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20190222230619.17887-13-tonyj@suse.de
Signed-off-by: Tony Jones <tonyj@suse.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/stat-cpi.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py
index a81ad8835a74..01fa933ff3cf 100644
--- a/tools/perf/scripts/python/stat-cpi.py
+++ b/tools/perf/scripts/python/stat-cpi.py
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
+from __future__ import print_function
+
 data    = {}
 times   = []
 threads = []
@@ -19,8 +21,8 @@ def store_key(time, cpu, thread):
         threads.append(thread)
 
 def store(time, event, cpu, thread, val, ena, run):
-    #print "event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" % \
-    #      (event, cpu, thread, time, val, ena, run)
+    #print("event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" %
+    #      (event, cpu, thread, time, val, ena, run))
 
     store_key(time, cpu, thread)
     key = get_key(time, event, cpu, thread)
@@ -58,7 +60,7 @@ def stat__interval(time):
             if ins != 0:
                 cpi = cyc/float(ins)
 
-            print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins)
+            print("%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins))
 
 def trace_end():
     pass
@@ -74,4 +76,4 @@ def trace_end():
 #                if ins != 0:
 #                    cpi = cyc/float(ins)
 #
-#                print "time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi)
+#                print("time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi))

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to syscall-counts.py
  2019-02-22 23:06 ` [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py Tony Jones
  2019-02-25 14:47   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:11   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:11 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, tglx, s1seetee, acme, tonyj, mingo, hpa

Commit-ID:  1d1b0dbb859d175eb512a9f0e1ca7e44bd0192cd
Gitweb:     https://git.kernel.org/tip/1d1b0dbb859d175eb512a9f0e1ca7e44bd0192cd
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:17 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:17:10 -0300

perf script python: Add Python3 support to syscall-counts.py

Support both Python2 and Python3 in the syscall-counts.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-14-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/syscall-counts.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py
index e66a7730aeb5..0ebd89cfd42c 100644
--- a/tools/perf/scripts/python/syscall-counts.py
+++ b/tools/perf/scripts/python/syscall-counts.py
@@ -5,6 +5,8 @@
 # Displays system-wide system call totals, broken down by syscall.
 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
 
+from __future__ import print_function
+
 import os
 import sys
 
@@ -28,7 +30,7 @@ if len(sys.argv) > 1:
 syscalls = autodict()
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	print_syscall_totals()
@@ -51,14 +53,14 @@ def syscalls__sys_enter(event_name, context, common_cpu,
 
 def print_syscall_totals():
     if for_comm is not None:
-	    print "\nsyscall events for %s:\n\n" % (for_comm),
+	    print("\nsyscall events for %s:\n" % (for_comm))
     else:
-	    print "\nsyscall events:\n\n",
+	    print("\nsyscall events:\n")
 
-    print "%-40s  %10s\n" % ("event", "count"),
-    print "%-40s  %10s\n" % ("----------------------------------------", \
-                                 "-----------"),
+    print("%-40s  %10s" % ("event", "count"))
+    print("%-40s  %10s" % ("----------------------------------------",
+                              "-----------"))
 
-    for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
+    for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
 				  reverse = True):
-	    print "%-40s  %10d\n" % (syscall_name(id), val),
+	    print("%-40s  %10d" % (syscall_name(id), val))

^ permalink raw reply	[flat|nested] 45+ messages in thread

* [tip:perf/core] perf script python: Add Python3 support to syscall-counts-by-pid.py
  2019-02-22 23:06 ` [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py Tony Jones
  2019-02-25 14:48   ` Arnaldo Carvalho de Melo
@ 2019-02-28  8:11   ` tip-bot for Tony Jones
  1 sibling, 0 replies; 45+ messages in thread
From: tip-bot for Tony Jones @ 2019-02-28  8:11 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, tglx, tonyj, mingo, acme, linux-kernel, s1seetee

Commit-ID:  de667cce7f4f96b6e22da8fd9c065b961f355080
Gitweb:     https://git.kernel.org/tip/de667cce7f4f96b6e22da8fd9c065b961f355080
Author:     Tony Jones <tonyj@suse.de>
AuthorDate: Fri, 22 Feb 2019 15:06:18 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 25 Feb 2019 17:17:13 -0300

perf script python: Add Python3 support to syscall-counts-by-pid.py

Support both Python2 and Python3 in the syscall-counts-by-pid.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-15-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/scripts/python/syscall-counts-by-pid.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py
index daf314cc5dd3..42782487b0e9 100644
--- a/tools/perf/scripts/python/syscall-counts-by-pid.py
+++ b/tools/perf/scripts/python/syscall-counts-by-pid.py
@@ -5,6 +5,8 @@
 # Displays system-wide system call totals, broken down by syscall.
 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
 
+from __future__ import print_function
+
 import os, sys
 
 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
@@ -31,7 +33,7 @@ if len(sys.argv) > 1:
 syscalls = autodict()
 
 def trace_begin():
-	print "Press control+C to stop and show the summary"
+	print("Press control+C to stop and show the summary")
 
 def trace_end():
 	print_syscall_totals()
@@ -55,20 +57,20 @@ def syscalls__sys_enter(event_name, context, common_cpu,
 
 def print_syscall_totals():
     if for_comm is not None:
-	    print "\nsyscall events for %s:\n\n" % (for_comm),
+	    print("\nsyscall events for %s:\n" % (for_comm))
     else:
-	    print "\nsyscall events by comm/pid:\n\n",
+	    print("\nsyscall events by comm/pid:\n")
 
-    print "%-40s  %10s\n" % ("comm [pid]/syscalls", "count"),
-    print "%-40s  %10s\n" % ("----------------------------------------", \
-                                 "----------"),
+    print("%-40s  %10s" % ("comm [pid]/syscalls", "count"))
+    print("%-40s  %10s" % ("----------------------------------------",
+                            "----------"))
 
     comm_keys = syscalls.keys()
     for comm in comm_keys:
 	    pid_keys = syscalls[comm].keys()
 	    for pid in pid_keys:
-		    print "\n%s [%d]\n" % (comm, pid),
+		    print("\n%s [%d]" % (comm, pid))
 		    id_keys = syscalls[comm][pid].keys()
-		    for id, val in sorted(syscalls[comm][pid].iteritems(), \
-				  key = lambda(k, v): (v, k),  reverse = True):
-			    print "  %-38s  %10d\n" % (syscall_name(id), val),
+		    for id, val in sorted(syscalls[comm][pid].items(), \
+				  key = lambda kv: (kv[1], kv[0]),  reverse = True):
+			    print("  %-38s  %10d" % (syscall_name(id), val))

^ permalink raw reply	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2019-02-28  8:12 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-22 23:06 [PATCH 00/15] perf script python: add Python3 support Tony Jones
2019-02-22 23:06 ` [PATCH 01/15] perf script python: add Python3 support to netdev-times.py Tony Jones
2019-02-28  8:06   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 02/15] perf script python: add Python3 support to check-perf-trace.py Tony Jones
2019-02-25 14:05   ` Arnaldo Carvalho de Melo
2019-02-25 18:05     ` Tony Jones
2019-02-22 23:06 ` [PATCH 03/15] perf script python: add Python3 support to event_analyzing_sample.py Tony Jones
2019-02-25 14:08   ` Arnaldo Carvalho de Melo
2019-02-22 23:06 ` [PATCH 04/15] perf script python: add Python3 support to failed-syscalls-by-pid.py Tony Jones
2019-02-25 14:09   ` Arnaldo Carvalho de Melo
2019-02-28  8:06   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 05/15] perf script python: add Python3 support to futex-contention.py Tony Jones
2019-02-22 23:06 ` [PATCH 06/15] perf script python: add Python3 support to intel-pt-events.py Tony Jones
2019-02-25  7:07   ` Adrian Hunter
2019-02-25 14:03     ` Arnaldo Carvalho de Melo
2019-02-25 17:18       ` Tony Jones
2019-02-22 23:06 ` [PATCH 07/15] perf script python: add Python3 support to mem-phys-addr.py Tony Jones
2019-02-28  8:07   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 08/15] perf script python: add Python3 support to net_dropmonitor.py Tony Jones
2019-02-25 12:37   ` Neil Horman
2019-02-25 14:43     ` Arnaldo Carvalho de Melo
2019-02-28  8:08   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 09/15] perf script python: add Python3 support to powerpc-hcalls.py Tony Jones
2019-02-25 14:44   ` Arnaldo Carvalho de Melo
2019-02-28  8:08   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 10/15] perf script python: add Python3 support to sctop.py Tony Jones
2019-02-25 14:44   ` Arnaldo Carvalho de Melo
2019-02-28  8:09   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 11/15] perf script python: add Python3 support to stackcollapse.py Tony Jones
2019-02-25 14:46   ` Arnaldo Carvalho de Melo
2019-02-28  8:09   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 12/15] perf script python: add Python3 support to stat-cpi.py Tony Jones
2019-02-25 14:46   ` Arnaldo Carvalho de Melo
2019-02-28  8:10   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 13/15] perf script python: add Python3 support to syscall-counts.py Tony Jones
2019-02-25 14:47   ` Arnaldo Carvalho de Melo
2019-02-28  8:11   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 14/15] perf script python: add Python3 support to syscall-counts-by-pid.py Tony Jones
2019-02-25 14:48   ` Arnaldo Carvalho de Melo
2019-02-28  8:11   ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-22 23:06 ` [PATCH 15/15] perf script python: add Python3 support to sql scripts Tony Jones
2019-02-25 14:51   ` Arnaldo Carvalho de Melo
2019-02-25 14:54     ` Arnaldo Carvalho de Melo
2019-02-25 17:20       ` Tony Jones
2019-02-23 21:06 ` [PATCH 00/15] perf script python: add Python3 support Tony Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.