perf tools: Generate a Python script compatible with Python 2 and 3
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/8 perf tools: Generate a Python script compatible with Python 2 and 3
When generating a Python script with "perf script -g python", produce one that is compatible with Python 2 and 3. The difference between the two generated scripts is:
--- python2-perf-script.py 2018-05-08 15:35:00.865889705 -0400
+++ python3-perf-script.py 2018-05-08 15:34:49.019789564 -0400
@@ -7,6 +7,8 @@
# be retrieved using Python functions of the form common_*(context). # See the perf-script-python Documentation for the list of available functions.
+from __future__ import print_function
+
import os
import sys
@@ -18,10 +20,10 @@
def trace_begin():
- print "in trace_begin"
+ print("in trace_begin")
def trace_end():
- print "in trace_end"
+ print("in trace_end")
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
@@ -29,26 +31,26 @@
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
- print "id=%d, args=%s" % \
- (id, args)
+ print("id=%d, args=%s" % \
+ (id, args)) - print 'Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'
+ print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
for node in common_callchain:
if 'sym' in node:
- print "\t[%x] %s" % (node['ip'], node['sym']['name'])
+ print("\t[%x] %s" % (node['ip'], node['sym']['name']))
else:
- print " [%x]" % (node['ip'])
+ print(" [%x]" % (node['ip']))
- print "\n"
+ print()
def trace_unhandled(event_name, context, event_fields_dict, perf_sample_dict):
- print get_dict_as_string(event_fields_dict)
- print 'Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'
+ print(get_dict_as_string(event_fields_dict))
+ print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
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="")
def get_dict_as_string(a_dict, delimiter=' '):
return delimiter.join(['%s=%s'%(k,str(v))for k,v in sorted(a_dict.items())])
--- .../scripting-engines/trace-event-python.c | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +15 -14
@@ -1393,6 +1393,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)fprintf (ofp,"# See the perf-script-python Documentation for the list " "of available functions.\n\n" ); +fprintf (ofp,"from __future__ import print_function\n\n" );fprintf (ofp,"import os\n" );fprintf (ofp,"import sys\n\n" );
@@ -1402,10 +1403,10 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)fprintf (ofp,"from Core import *\n\n\n" );fprintf (ofp,"def trace_begin():\n" ); -fprintf (ofp,"\tprint \"in trace_begin\"\n\n" ); +fprintf (ofp,"\tprint(\"in trace_begin\")\n\n" );fprintf (ofp,"def trace_end():\n" ); -fprintf (ofp,"\tprint \"in trace_end\"\n\n" ); +fprintf (ofp,"\tprint(\"in trace_end\")\n\n" );while ((event =trace_find_next_event (pevent, event))) {fprintf (ofp,"def %s__%s(" , event->system, event->name);
@@ -1441,7 +1442,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)"common_secs, common_nsecs,\n\t\t\t" "common_pid, common_comm)\n\n"); -fprintf (ofp,"\t\tprint \"" ); +fprintf (ofp,"\t\tprint(\"" ); not_first =0 ; count =0 ;
@@ -1502,31 +1503,31 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)fprintf (ofp,"%s" , f->name); } -fprintf (ofp,")\n\n" ); +fprintf (ofp,"))\n\n" ); -fprintf (ofp,"\t\tprint 'Sample: {'+" -"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n" ); +fprintf (ofp,"\t\tprint('Sample: {'+" +"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')\n\n" );fprintf (ofp,"\t\tfor node in common_callchain:" );fprintf (ofp,"\n\t\t\tif 'sym' in node:" ); -fprintf (ofp,"\n\t\t\t\tprint \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name'])" ); +fprintf (ofp,"\n\t\t\t\tprint(\"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name']))" );fprintf (ofp,"\n\t\t\telse:" ); -fprintf (ofp,"\n\t\t\t\tprint \"\t[%%x]\" %% (node['ip'])\n\n" ); -fprintf (ofp,"\t\tprint \"\\n\"\n\n" ); +fprintf (ofp,"\n\t\t\t\tprint(\"\t[%%x]\" %% (node['ip']))\n\n" ); +fprintf (ofp,"\t\tprint()\n\n" ); }fprintf (ofp,"def trace_unhandled(event_name, context, " "event_fields_dict, perf_sample_dict):\n" ); -fprintf (ofp,"\t\tprint get_dict_as_string(event_fields_dict)\n" ); -fprintf (ofp,"\t\tprint 'Sample: {'+" -"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n" ); +fprintf (ofp,"\t\tprint(get_dict_as_string(event_fields_dict))\n" ); +fprintf (ofp,"\t\tprint('Sample: {'+" +"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')\n\n" );fprintf (ofp,"def print_header(" "event_name, cpu, secs, nsecs, pid, comm):\n" -"\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" -"(event_name, cpu, secs, nsecs, pid, comm),\n\n" ); +"\tprint(\"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" +"(event_name, cpu, secs, nsecs, pid, comm), end=\"\")\n\n" );fprintf (ofp,"def get_dict_as_string(a_dict, delimiter=' '):\n" "\treturn delimiter.join"
Signature · 1 line
2.17.0
tip-bot for Jeremy Cline
merge botperf tools: Generate a Python script compatible with Python 2 and 3
Commit-ID: 877cc639686b68c7de179a485544f4761e376b30 Gitweb: https://git.kernel.org/tip/877cc639686b68c7de179a485544f4761e376b30 Author: Jeremy Cline <[email protected]> AuthorDate: Tue, 8 May 2018 21:27:43 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 10:01:50 -0300
perf tools: Generate a Python script compatible with Python 2 and 3
When generating a Python script with "perf script -g python", produce one that is compatible with Python 2 and 3. The difference between the two generated scripts is:
--- python2-perf-script.py 2018-05-08 15:35:00.865889705 -0400
+++ python3-perf-script.py 2018-05-08 15:34:49.019789564 -0400
@@ -7,6 +7,8 @@
# be retrieved using Python functions of the form common_*(context). # See the perf-script-python Documentation for the list of available functions.
+from __future__ import print_function
+
import os
import sys
@@ -18,10 +20,10 @@
def trace_begin():
- print "in trace_begin"
+ print("in trace_begin")
def trace_end():
- print "in trace_end"
+ print("in trace_end")
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
@@ -29,26 +31,26 @@
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
- print "id=%d, args=%s" % \
- (id, args)
+ print("id=%d, args=%s" % \
+ (id, args)) - print 'Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'
+ print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
for node in common_callchain:
if 'sym' in node:
- print "\t[%x] %s" % (node['ip'], node['sym']['name'])
+ print("\t[%x] %s" % (node['ip'], node['sym']['name']))
else:
- print " [%x]" % (node['ip'])
+ print(" [%x]" % (node['ip']))
- print "\n"
+ print()
def trace_unhandled(event_name, context, event_fields_dict, perf_sample_dict):
- print get_dict_as_string(event_fields_dict)
- print 'Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'
+ print(get_dict_as_string(event_fields_dict))
+ print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
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="")
def get_dict_as_string(a_dict, delimiter=' '):
return delimiter.join(['%s=%s'%(k,str(v))for k,v in sorted(a_dict.items())])
--- .../util/scripting-engines/trace-event-python.c | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +15 -14
@@ -1627,6 +1627,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)fprintf (ofp,"# See the perf-script-python Documentation for the list " "of available functions.\n\n" ); +fprintf (ofp,"from __future__ import print_function\n\n" );fprintf (ofp,"import os\n" );fprintf (ofp,"import sys\n\n" );
@@ -1636,10 +1637,10 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)fprintf (ofp,"from Core import *\n\n\n" );fprintf (ofp,"def trace_begin():\n" ); -fprintf (ofp,"\tprint \"in trace_begin\"\n\n" ); +fprintf (ofp,"\tprint(\"in trace_begin\")\n\n" );fprintf (ofp,"def trace_end():\n" ); -fprintf (ofp,"\tprint \"in trace_end\"\n\n" ); +fprintf (ofp,"\tprint(\"in trace_end\")\n\n" );while ((event =trace_find_next_event (pevent, event))) {fprintf (ofp,"def %s__%s(" , event->system, event->name);
@@ -1675,7 +1676,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)"common_secs, common_nsecs,\n\t\t\t" "common_pid, common_comm)\n\n"); -fprintf (ofp,"\t\tprint \"" ); +fprintf (ofp,"\t\tprint(\"" ); not_first =0 ; count =0 ;
@@ -1736,31 +1737,31 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)fprintf (ofp,"%s" , f->name); } -fprintf (ofp,")\n\n" ); +fprintf (ofp,"))\n\n" ); -fprintf (ofp,"\t\tprint 'Sample: {'+" -"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n" ); +fprintf (ofp,"\t\tprint('Sample: {'+" +"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')\n\n" );fprintf (ofp,"\t\tfor node in common_callchain:" );fprintf (ofp,"\n\t\t\tif 'sym' in node:" ); -fprintf (ofp,"\n\t\t\t\tprint \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name'])" ); +fprintf (ofp,"\n\t\t\t\tprint(\"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name']))" );fprintf (ofp,"\n\t\t\telse:" ); -fprintf (ofp,"\n\t\t\t\tprint \"\t[%%x]\" %% (node['ip'])\n\n" ); -fprintf (ofp,"\t\tprint \"\\n\"\n\n" ); +fprintf (ofp,"\n\t\t\t\tprint(\"\t[%%x]\" %% (node['ip']))\n\n" ); +fprintf (ofp,"\t\tprint()\n\n" ); }fprintf (ofp,"def trace_unhandled(event_name, context, " "event_fields_dict, perf_sample_dict):\n" ); -fprintf (ofp,"\t\tprint get_dict_as_string(event_fields_dict)\n" ); -fprintf (ofp,"\t\tprint 'Sample: {'+" -"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n" ); +fprintf (ofp,"\t\tprint(get_dict_as_string(event_fields_dict))\n" ); +fprintf (ofp,"\t\tprint('Sample: {'+" +"get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')\n\n" );fprintf (ofp,"def print_header(" "event_name, cpu, secs, nsecs, pid, comm):\n" -"\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" -"(event_name, cpu, secs, nsecs, pid, comm),\n\n" ); +"\tprint(\"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" +"(event_name, cpu, secs, nsecs, pid, comm), end=\"\")\n\n" );fprintf (ofp,"def get_dict_as_string(a_dict, delimiter=' '):\n" "\treturn delimiter.join"
PATCH 2/8 perf scripts python: Add Python 3 support to Core.py
In reply to a message not in the archiveSupport both Python 2 and Python 3 in Core.py. This should have no functional change.
--- .../Perf-Trace-Util/lib/Perf/Trace/Core.py | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py +17 -23
@@ -31,10 +31,8 @@ def flag_str(event_name, field_name, value): string = "" if flag_fields[event_name][field_name]: - print_delim = 0 - keys = flag_fields[event_name][field_name]['values'].keys() - keys.sort() - for idx in keys: + print_delim = 0 + for idx in sorted(flag_fields[event_name][field_name]['values']): if not value and not idx: string += flag_fields[event_name][field_name]['values'][idx] break
@@ -51,14 +49,12 @@ def symbol_str(event_name, field_name, value): string = "" if symbolic_fields[event_name][field_name]: - keys = symbolic_fields[event_name][field_name]['values'].keys() - keys.sort() - for idx in keys: + for idx in sorted(symbolic_fields[event_name][field_name]['values']): if not value and not idx: - string = symbolic_fields[event_name][field_name]['values'][idx] + string = symbolic_fields[event_name][field_name]['values'][idx] break - if (value == idx): - string = symbolic_fields[event_name][field_name]['values'][idx] + if (value == idx): + string = symbolic_fields[event_name][field_name]['values'][idx] break return string
@@ -74,19 +70,17 @@ def trace_flag_str(value): string = "" print_delim = 0 - keys = trace_flags.keys() - - for idx in keys: - if not value and not idx: - string += "NONE" - break - - if idx and (value & idx) == idx: - if print_delim: - string += " | "; - string += trace_flags[idx] - print_delim = 1 - value &= ~idx + for idx in trace_flags: + if not value and not idx: + string += "NONE" + break + + if idx and (value & idx) == idx: + if print_delim: + string += " | "; + string += trace_flags[idx] + print_delim = 1 + value &= ~idx return string
Signature · 1 line
2.17.0
tip-bot for Jeremy Cline
merge bot[tip:perf/urgent] perf scripts python: Add Python 3 support to Core.py
perf scripts python: Add Python 3 support to Core.py
Commit-ID: 770d2f86c0051d4f2c0ab9d74d68434cb383241d Gitweb: https://git.kernel.org/tip/770d2f86c0051d4f2c0ab9d74d68434cb383241d Author: Jeremy Cline <[email protected]> AuthorDate: Tue, 8 May 2018 21:27:45 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 10:01:50 -0300
perf scripts python: Add Python 3 support to Core.py
Support both Python 2 and Python 3 in Core.py. This should have no functional change.
--- .../python/Perf-Trace-Util/lib/Perf/Trace/Core.py | 40 +++++++++------------- 1 file changed, 17 insertions(+), 23 deletions(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py +17 -23
@@ -31,10 +31,8 @@ def flag_str(event_name, field_name, value): string = "" if flag_fields[event_name][field_name]: - print_delim = 0 - keys = flag_fields[event_name][field_name]['values'].keys() - keys.sort() - for idx in keys: + print_delim = 0 + for idx in sorted(flag_fields[event_name][field_name]['values']): if not value and not idx: string += flag_fields[event_name][field_name]['values'][idx] break
@@ -51,14 +49,12 @@ def symbol_str(event_name, field_name, value): string = "" if symbolic_fields[event_name][field_name]: - keys = symbolic_fields[event_name][field_name]['values'].keys() - keys.sort() - for idx in keys: + for idx in sorted(symbolic_fields[event_name][field_name]['values']): if not value and not idx: - string = symbolic_fields[event_name][field_name]['values'][idx] + string = symbolic_fields[event_name][field_name]['values'][idx] break - if (value == idx): - string = symbolic_fields[event_name][field_name]['values'][idx] + if (value == idx): + string = symbolic_fields[event_name][field_name]['values'][idx] break return string
@@ -74,19 +70,17 @@ def trace_flag_str(value): string = "" print_delim = 0 - keys = trace_flags.keys() - - for idx in keys: - if not value and not idx: - string += "NONE" - break - - if idx and (value & idx) == idx: - if print_delim: - string += " | "; - string += trace_flags[idx] - print_delim = 1 - value &= ~idx + for idx in trace_flags: + if not value and not idx: + string += "NONE" + break + + if idx and (value & idx) == idx: + if print_delim: + string += " | "; + string += trace_flags[idx] + print_delim = 1 + value &= ~idx return string
PATCH 3/8 perf scripts python: Add Python 3 support to SchedGui.py
In reply to a message not in the archiveFix a single syntax error in SchedGui.py to support both Python 2 and Python 3. This should have no functional change.
--- .../scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py +1 -1
@@ -11,7 +11,7 @@ try: import wx except ImportError: - raise ImportError, "You need to install the wxpython lib for this script" + raise ImportError("You need to install the wxpython lib for this script") class RootFrame(wx.Frame):
Signature · 1 line
2.17.0
tip-bot for Jeremy Cline
merge bot[tip:perf/urgent] perf scripts python: Add Python 3 support to SchedGui.py
perf scripts python: Add Python 3 support to SchedGui.py
Commit-ID: 2ab89262ff8895b8476b97345507c676fe3081fa Gitweb: https://git.kernel.org/tip/2ab89262ff8895b8476b97345507c676fe3081fa Author: Jeremy Cline <[email protected]> AuthorDate: Tue, 8 May 2018 21:27:45 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 10:01:50 -0300
perf scripts python: Add Python 3 support to SchedGui.py
Fix a single syntax error in SchedGui.py to support both Python 2 and Python 3. This should have no functional change.
--- tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py +1 -1
@@ -11,7 +11,7 @@ try: import wx except ImportError: - raise ImportError, "You need to install the wxpython lib for this script" + raise ImportError("You need to install the wxpython lib for this script") class RootFrame(wx.Frame):
PATCH 4/8 perf scripts python: Add Python 3 support to Util.py
In reply to a message not in the archiveSupport both Python 2 and Python 3 in Util.py. The dict class no longer has a ``has_key`` method and print is now a function rather than a statement. This should have no functional change.
--- .../python/Perf-Trace-Util/lib/Perf/Trace/Util.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +6 -5
@@ -5,6 +5,7 @@ # This software may be distributed under the terms of the GNU General # Public License ("GPL") version 2 as published by the Free Software # Foundation. +from __future__ import print_function import errno, os
@@ -33,7 +34,7 @@ def nsecs_str(nsecs): return str def add_stats(dict, key, value): - if not dict.has_key(key): + if key not in dict: dict[key] = (value, value, value, 1) else: min, max, avg, count = dict[key]
@@ -72,10 +73,10 @@ try: except: if not audit_package_warned: audit_package_warned = True - print "Install the audit-libs-python package to get syscall names.\n" \ - "For example:\n # apt-get install python-audit (Ubuntu)" \ - "\n # yum install audit-libs-python (Fedora)" \ - "\n etc.\n" + print("Install the audit-libs-python package to get syscall names.\n" + "For example:\n # apt-get install python-audit (Ubuntu)" + "\n # yum install audit-libs-python (Fedora)" + "\n etc.\n") def syscall_name(id): try:
Signature · 1 line
2.17.0
tip-bot for Jeremy Cline
merge bot[tip:perf/urgent] perf scripts python: Add Python 3 support to Util.py
perf scripts python: Add Python 3 support to Util.py
Commit-ID: c45b168effb12719f6dfc8d2c20ba8c057e8c16b Gitweb: https://git.kernel.org/tip/c45b168effb12719f6dfc8d2c20ba8c057e8c16b Author: Jeremy Cline <[email protected]> AuthorDate: Tue, 8 May 2018 21:27:46 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 10:01:50 -0300
perf scripts python: Add Python 3 support to Util.py
Support both Python 2 and Python 3 in Util.py. The dict class no longer has a ``has_key`` method and print is now a function rather than a statement. This should have no functional change.
--- .../scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +6 -5
@@ -5,6 +5,7 @@ # This software may be distributed under the terms of the GNU General # Public License ("GPL") version 2 as published by the Free Software # Foundation. +from __future__ import print_function import errno, os
@@ -33,7 +34,7 @@ def nsecs_str(nsecs): return str def add_stats(dict, key, value): - if not dict.has_key(key): + if key not in dict: dict[key] = (value, value, value, 1) else: min, max, avg, count = dict[key]
@@ -72,10 +73,10 @@ try: except: if not audit_package_warned: audit_package_warned = True - print "Install the audit-libs-python package to get syscall names.\n" \ - "For example:\n # apt-get install python-audit (Ubuntu)" \ - "\n # yum install audit-libs-python (Fedora)" \ - "\n etc.\n" + print("Install the audit-libs-python package to get syscall names.\n" + "For example:\n # apt-get install python-audit (Ubuntu)" + "\n # yum install audit-libs-python (Fedora)" + "\n etc.\n") def syscall_name(id): try:
PATCH 5/8 perf scripts python: Add Python 3 support to EventClass.py
In reply to a message not in the archiveSupport both Python 2 and Python 3 in EventClass.py. ``print`` is now a function rather than a statement. This should have no functional change.
--- .../python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py +3 -1
@@ -8,6 +8,7 @@ # PerfEvent is the base class for all perf event sample, PebsEvent # is a HW base Intel x86 PEBS event, and user could add more SW/HW # event classes based on requirements. +from __future__ import print_function import struct
@@ -44,7 +45,8 @@ class PerfEvent(object): PerfEvent.event_num += 1 def show(self): - print "PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % (self.name, self.symbol, self.comm, self.dso) + print("PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % + (self.name, self.symbol, self.comm, self.dso)) # # Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer
Signature · 1 line
2.17.0
tip-bot for Jeremy Cline
merge bot[tip:perf/urgent] perf scripts python: Add Python 3 support to EventClass.py
perf scripts python: Add Python 3 support to EventClass.py
Commit-ID: 12aa6c7389a321b4b5d921f89c3f83b9750598f7 Gitweb: https://git.kernel.org/tip/12aa6c7389a321b4b5d921f89c3f83b9750598f7 Author: Jeremy Cline <[email protected]> AuthorDate: Tue, 8 May 2018 21:27:48 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 10:01:50 -0300
perf scripts python: Add Python 3 support to EventClass.py
Support both Python 2 and Python 3 in EventClass.py. ``print`` is now a function rather than a statement. This should have no functional change.
--- .../perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py +3 -1
@@ -8,6 +8,7 @@ # PerfEvent is the base class for all perf event sample, PebsEvent # is a HW base Intel x86 PEBS event, and user could add more SW/HW # event classes based on requirements. +from __future__ import print_function import struct
@@ -44,7 +45,8 @@ class PerfEvent(object): PerfEvent.event_num += 1 def show(self): - print "PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % (self.name, self.symbol, self.comm, self.dso) + print("PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % + (self.name, self.symbol, self.comm, self.dso)) # # Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer
PATCH 6/8 perf scripts python: Add Python 3 support to sched-migration.py
In reply to a message not in the archiveSupport both Python 2 and Python 3 in the sched-migration.py script. This should have no functional change.
--- tools/perf/scripts/python/sched-migration.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tools/perf/scripts/python/sched-migration.py +9 -5
@@ -9,13 +9,17 @@ # This software is distributed under the terms of the GNU General # Public License ("GPL") version 2 as published by the Free Software # Foundation. - +from __future__ import print_function import os import sys from collections import defaultdict -from UserList import UserList +try: + from UserList import UserList +except ImportError: + # Python 3: UserList moved to the collections package + from collections import UserList sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -300,7 +304,7 @@ class TimeSliceList(UserList): if i == -1: return - for i in xrange(i, len(self.data)): + for i in range(i, len(self.data)): timeslice = self.data[i] if timeslice.start > end: return
@@ -336,8 +340,8 @@ class SchedEventProxy: on_cpu_task = self.current_tsk[headers.cpu] if on_cpu_task != -1 and on_cpu_task != prev_pid: - print "Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ - (headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) + print("Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ + headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) threads[prev_pid] = prev_comm threads[next_pid] = next_comm
Signature · 1 line
2.17.0
tip-bot for Jeremy Cline
merge bot[tip:perf/urgent] perf scripts python: Add Python 3 support to sched-migration.py
perf scripts python: Add Python 3 support to sched-migration.py
Commit-ID: 8c1c1ab2d2a77cb50841822168e56d11c4ebfd6e Gitweb: https://git.kernel.org/tip/8c1c1ab2d2a77cb50841822168e56d11c4ebfd6e Author: Jeremy Cline <[email protected]> AuthorDate: Tue, 8 May 2018 21:27:47 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 10:01:50 -0300
perf scripts python: Add Python 3 support to sched-migration.py
Support both Python 2 and Python 3 in the sched-migration.py script. This should have no functional change.
--- tools/perf/scripts/python/sched-migration.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tools/perf/scripts/python/sched-migration.py +9 -5
@@ -9,13 +9,17 @@ # This software is distributed under the terms of the GNU General # Public License ("GPL") version 2 as published by the Free Software # Foundation. - +from __future__ import print_function import os import sys from collections import defaultdict -from UserList import UserList +try: + from UserList import UserList +except ImportError: + # Python 3: UserList moved to the collections package + from collections import UserList sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -300,7 +304,7 @@ class TimeSliceList(UserList): if i == -1: return - for i in xrange(i, len(self.data)): + for i in range(i, len(self.data)): timeslice = self.data[i] if timeslice.start > end: return
@@ -336,8 +340,8 @@ class SchedEventProxy: on_cpu_task = self.current_tsk[headers.cpu] if on_cpu_task != -1 and on_cpu_task != prev_pid: - print "Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ - (headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) + print("Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ + headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) threads[prev_pid] = prev_comm threads[next_pid] = next_comm
PATCH 7/8 perf scripts python: Add Python 3 support to stat-cpi.py
In reply to a message not in the archiveSupport both Python 2 and Python 3 in stat-cpi.py. This should have no functional change.
--- tools/perf/scripts/python/stat-cpi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/scripts/python/stat-cpi.py +4 -1
@@ -1,6 +1,8 @@ #!/usr/bin/env python # SPDX-License-Identifier: GPL-2.0 +from __future__ import print_function + data = {} times = [] threads = []
@@ -59,7 +61,8 @@ 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
Signature · 1 line
2.17.0
PATCH 8/8 perf tests: Add Python 3 support to attr.py
In reply to a message not in the archiveSupport both Python 2 and Python 3 in attr.py. This should have no functional change.
--- tools/perf/tests/attr.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
tools/perf/tests/attr.py +19 -13
@@ -1,6 +1,8 @@ #! /usr/bin/python # SPDX-License-Identifier: GPL-2.0 +from __future__ import print_function + import os import sys import glob
@@ -8,7 +10,11 @@ import optparse import tempfile import logging import shutil -import ConfigParser +try: + import ConfigParser as configparser +except ImportError: + # Python 3 renamed ConfigParser to configparser + import configparser def data_equal(a, b): # Allow multiple values in assignment separated by '|'
@@ -100,23 +106,23 @@ class Event(dict): def equal(self, other): for t in Event.terms: log.debug(" [%s] %s %s" % (t, self[t], other[t])); - if not self.has_key(t) or not other.has_key(t): + if t not in self or t not in other: return False if not data_equal(self[t], other[t]): return False return True def optional(self): - if self.has_key('optional') and self['optional'] == '1': + if 'optional' in self and self['optional'] == '1': return True return False def diff(self, other): for t in Event.terms: - if not self.has_key(t) or not other.has_key(t): + if t not in self or t not in other: continue if not data_equal(self[t], other[t]): - log.warning("expected %s=%s, got %s" % (t, self[t], other[t])) + log.warning("expected %s=%s, got %s" % (t, self[t], other[t])) # Test file description needs to have following sections: # [config]
@@ -134,7 +140,7 @@ class Event(dict): # - expected values assignments class Test(object): def __init__(self, path, options): - parser = ConfigParser.SafeConfigParser() + parser = configparser.SafeConfigParser() parser.read(path) log.warning("running '%s'" % path)
@@ -193,7 +199,7 @@ class Test(object): return True def load_events(self, path, events): - parser_event = ConfigParser.SafeConfigParser() + parser_event = configparser.SafeConfigParser() parser_event.read(path) # The event record section header contains 'event' word,
@@ -207,7 +213,7 @@ class Test(object): # Read parent event if there's any if (':' in section): base = section[section.index(':') + 1:] - parser_base = ConfigParser.SafeConfigParser() + parser_base = configparser.SafeConfigParser() parser_base.read(self.test_dir + '/' + base) base_items = parser_base.items('event')
@@ -322,9 +328,9 @@ def run_tests(options): for f in glob.glob(options.test_dir + '/' + options.test): try: Test(f, options).run() - except Unsup, obj: + except Unsup as obj: log.warning("unsupp %s" % obj.getMsg()) - except Notest, obj: + except Notest as obj: log.warning("skipped %s" % obj.getMsg()) def setup_log(verbose):
@@ -373,7 +379,7 @@ def main(): setup_log(options.verbose) if not options.test_dir: - print 'FAILED no -d option specified' + print('FAILED no -d option specified') sys.exit(-1) if not options.test:
@@ -382,8 +388,8 @@ def main(): try: run_tests(options) - except Fail, obj: - print "FAILED %s" % obj.getMsg(); + except Fail as obj: + print("FAILED %s" % obj.getMsg()) sys.exit(-1) sys.exit(0)
Signature · 1 line
2.17.0