* [PATCH 0/2] perf scripts python: exported-sql-viewer.py: Fix python3 support
@ 2019-03-27 7:28 Adrian Hunter
2019-03-27 7:28 ` [PATCH 1/2] perf scripts python: exported-sql-viewer.py: Fix never-ending loop Adrian Hunter
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Adrian Hunter @ 2019-03-27 7:28 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel
Hi
Here are a couple for fixes.
Adrian Hunter (2):
perf scripts python: exported-sql-viewer.py: Fix never-ending loop
perf scripts python: exported-sql-viewer.py: Fix python3 support
tools/perf/scripts/python/exported-sql-viewer.py | 77 +++++++++++++++++++-----
1 file changed, 63 insertions(+), 14 deletions(-)
Regards
Adrian
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] perf scripts python: exported-sql-viewer.py: Fix never-ending loop 2019-03-27 7:28 [PATCH 0/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter @ 2019-03-27 7:28 ` Adrian Hunter 2019-03-29 20:41 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2019-03-27 7:28 ` [PATCH 2/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter 2019-03-27 13:47 ` [PATCH 0/2] " Arnaldo Carvalho de Melo 2 siblings, 1 reply; 6+ messages in thread From: Adrian Hunter @ 2019-03-27 7:28 UTC (permalink / raw) To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel pyside version 1 fails to handle python3 large integers in some cases, resulting in Qt getting into a never-ending loop. This affects: samples Table samples_view Table All branches Report Selected branches Report Add workarounds for those cases. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Fixes: beda0e725e5f ("perf script python: Add Python3 support to exported-sql-viewer.py") --- .../scripts/python/exported-sql-viewer.py | 60 +++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py index e38518cdcbc3..0cf30956064a 100755 --- a/tools/perf/scripts/python/exported-sql-viewer.py +++ b/tools/perf/scripts/python/exported-sql-viewer.py @@ -107,6 +107,7 @@ import os from PySide.QtCore import * from PySide.QtGui import * from PySide.QtSql import * +pyside_version_1 = True from decimal import * from ctypes import * from multiprocessing import Process, Array, Value, Event @@ -1526,6 +1527,19 @@ def BranchDataPrep(query): " (" + dsoname(query.value(15)) + ")") return data +def BranchDataPrepWA(query): + data = [] + data.append(query.value(0)) + # Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string + data.append("{:>19}".format(query.value(1))) + for i in xrange(2, 8): + data.append(query.value(i)) + data.append(tohex(query.value(8)).rjust(16) + " " + query.value(9) + offstr(query.value(10)) + + " (" + dsoname(query.value(11)) + ")" + " -> " + + tohex(query.value(12)) + " " + query.value(13) + offstr(query.value(14)) + + " (" + dsoname(query.value(15)) + ")") + return data + # Branch data model class BranchModel(TreeModel): @@ -1553,7 +1567,11 @@ class BranchModel(TreeModel): " AND evsel_id = " + str(self.event_id) + " ORDER BY samples.id" " LIMIT " + str(glb_chunk_sz)) - self.fetcher = SQLFetcher(glb, sql, BranchDataPrep, self.AddSample) + if pyside_version_1 and sys.version_info[0] == 3: + prep = BranchDataPrepWA + else: + prep = BranchDataPrep + self.fetcher = SQLFetcher(glb, sql, prep, self.AddSample) self.fetcher.done.connect(self.Update) self.fetcher.Fetch(glb_chunk_sz) @@ -2079,14 +2097,6 @@ def IsSelectable(db, table, sql = ""): return False return True -# SQL data preparation - -def SQLTableDataPrep(query, count): - data = [] - for i in xrange(count): - data.append(query.value(i)) - return data - # SQL table data model item class SQLTableItem(): @@ -2110,7 +2120,7 @@ class SQLTableModel(TableModel): self.more = True self.populated = 0 self.column_headers = column_headers - self.fetcher = SQLFetcher(glb, sql, lambda x, y=len(column_headers): SQLTableDataPrep(x, y), self.AddSample) + self.fetcher = SQLFetcher(glb, sql, lambda x, y=len(column_headers): self.SQLTableDataPrep(x, y), self.AddSample) self.fetcher.done.connect(self.Update) self.fetcher.Fetch(glb_chunk_sz) @@ -2154,6 +2164,12 @@ class SQLTableModel(TableModel): def columnHeader(self, column): return self.column_headers[column] + def SQLTableDataPrep(self, query, count): + data = [] + for i in xrange(count): + data.append(query.value(i)) + return data + # SQL automatic table data model class SQLAutoTableModel(SQLTableModel): @@ -2182,8 +2198,32 @@ class SQLAutoTableModel(SQLTableModel): QueryExec(query, "SELECT column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' and table_name = '" + select_table_name + "'") while query.next(): column_headers.append(query.value(0)) + if pyside_version_1 and sys.version_info[0] == 3: + if table_name == "samples_view": + self.SQLTableDataPrep = self.samples_view_DataPrep + if table_name == "samples": + self.SQLTableDataPrep = self.samples_DataPrep super(SQLAutoTableModel, self).__init__(glb, sql, column_headers, parent) + def samples_view_DataPrep(self, query, count): + data = [] + data.append(query.value(0)) + # Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string + data.append("{:>19}".format(query.value(1))) + for i in xrange(2, count): + data.append(query.value(i)) + return data + + def samples_DataPrep(self, query, count): + data = [] + for i in xrange(9): + data.append(query.value(i)) + # Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string + data.append("{:>19}".format(query.value(9))) + for i in xrange(10, count): + data.append(query.value(i)) + return data + # Base class for custom ResizeColumnsToContents class ResizeColumnsToContentsBase(QObject): -- 2.17.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [tip:perf/urgent] perf scripts python: exported-sql-viewer.py: Fix never-ending loop 2019-03-27 7:28 ` [PATCH 1/2] perf scripts python: exported-sql-viewer.py: Fix never-ending loop Adrian Hunter @ 2019-03-29 20:41 ` tip-bot for Adrian Hunter 0 siblings, 0 replies; 6+ messages in thread From: tip-bot for Adrian Hunter @ 2019-03-29 20:41 UTC (permalink / raw) To: linux-tip-commits Cc: tglx, hpa, adrian.hunter, jolsa, linux-kernel, acme, mingo Commit-ID: 8453c936db20489dbf0957187dca9a2656a2a7b6 Gitweb: https://git.kernel.org/tip/8453c936db20489dbf0957187dca9a2656a2a7b6 Author: Adrian Hunter <adrian.hunter@intel.com> AuthorDate: Wed, 27 Mar 2019 09:28:25 +0200 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Thu, 28 Mar 2019 14:41:21 -0300 perf scripts python: exported-sql-viewer.py: Fix never-ending loop pyside version 1 fails to handle python3 large integers in some cases, resulting in Qt getting into a never-ending loop. This affects: samples Table samples_view Table All branches Report Selected branches Report Add workarounds for those cases. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Fixes: beda0e725e5f ("perf script python: Add Python3 support to exported-sql-viewer.py") Link: http://lkml.kernel.org/r/20190327072826.19168-2-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/scripts/python/exported-sql-viewer.py | 60 ++++++++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py index e38518cdcbc3..0cf30956064a 100755 --- a/tools/perf/scripts/python/exported-sql-viewer.py +++ b/tools/perf/scripts/python/exported-sql-viewer.py @@ -107,6 +107,7 @@ import os from PySide.QtCore import * from PySide.QtGui import * from PySide.QtSql import * +pyside_version_1 = True from decimal import * from ctypes import * from multiprocessing import Process, Array, Value, Event @@ -1526,6 +1527,19 @@ def BranchDataPrep(query): " (" + dsoname(query.value(15)) + ")") return data +def BranchDataPrepWA(query): + data = [] + data.append(query.value(0)) + # Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string + data.append("{:>19}".format(query.value(1))) + for i in xrange(2, 8): + data.append(query.value(i)) + data.append(tohex(query.value(8)).rjust(16) + " " + query.value(9) + offstr(query.value(10)) + + " (" + dsoname(query.value(11)) + ")" + " -> " + + tohex(query.value(12)) + " " + query.value(13) + offstr(query.value(14)) + + " (" + dsoname(query.value(15)) + ")") + return data + # Branch data model class BranchModel(TreeModel): @@ -1553,7 +1567,11 @@ class BranchModel(TreeModel): " AND evsel_id = " + str(self.event_id) + " ORDER BY samples.id" " LIMIT " + str(glb_chunk_sz)) - self.fetcher = SQLFetcher(glb, sql, BranchDataPrep, self.AddSample) + if pyside_version_1 and sys.version_info[0] == 3: + prep = BranchDataPrepWA + else: + prep = BranchDataPrep + self.fetcher = SQLFetcher(glb, sql, prep, self.AddSample) self.fetcher.done.connect(self.Update) self.fetcher.Fetch(glb_chunk_sz) @@ -2079,14 +2097,6 @@ def IsSelectable(db, table, sql = ""): return False return True -# SQL data preparation - -def SQLTableDataPrep(query, count): - data = [] - for i in xrange(count): - data.append(query.value(i)) - return data - # SQL table data model item class SQLTableItem(): @@ -2110,7 +2120,7 @@ class SQLTableModel(TableModel): self.more = True self.populated = 0 self.column_headers = column_headers - self.fetcher = SQLFetcher(glb, sql, lambda x, y=len(column_headers): SQLTableDataPrep(x, y), self.AddSample) + self.fetcher = SQLFetcher(glb, sql, lambda x, y=len(column_headers): self.SQLTableDataPrep(x, y), self.AddSample) self.fetcher.done.connect(self.Update) self.fetcher.Fetch(glb_chunk_sz) @@ -2154,6 +2164,12 @@ class SQLTableModel(TableModel): def columnHeader(self, column): return self.column_headers[column] + def SQLTableDataPrep(self, query, count): + data = [] + for i in xrange(count): + data.append(query.value(i)) + return data + # SQL automatic table data model class SQLAutoTableModel(SQLTableModel): @@ -2182,8 +2198,32 @@ class SQLAutoTableModel(SQLTableModel): QueryExec(query, "SELECT column_name FROM information_schema.columns WHERE table_schema = '" + schema + "' and table_name = '" + select_table_name + "'") while query.next(): column_headers.append(query.value(0)) + if pyside_version_1 and sys.version_info[0] == 3: + if table_name == "samples_view": + self.SQLTableDataPrep = self.samples_view_DataPrep + if table_name == "samples": + self.SQLTableDataPrep = self.samples_DataPrep super(SQLAutoTableModel, self).__init__(glb, sql, column_headers, parent) + def samples_view_DataPrep(self, query, count): + data = [] + data.append(query.value(0)) + # Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string + data.append("{:>19}".format(query.value(1))) + for i in xrange(2, count): + data.append(query.value(i)) + return data + + def samples_DataPrep(self, query, count): + data = [] + for i in xrange(9): + data.append(query.value(i)) + # Workaround pyside failing to handle large integers (i.e. time) in python3 by converting to a string + data.append("{:>19}".format(query.value(9))) + for i in xrange(10, count): + data.append(query.value(i)) + return data + # Base class for custom ResizeColumnsToContents class ResizeColumnsToContentsBase(QObject): ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] perf scripts python: exported-sql-viewer.py: Fix python3 support 2019-03-27 7:28 [PATCH 0/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter 2019-03-27 7:28 ` [PATCH 1/2] perf scripts python: exported-sql-viewer.py: Fix never-ending loop Adrian Hunter @ 2019-03-27 7:28 ` Adrian Hunter 2019-03-29 20:42 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2019-03-27 13:47 ` [PATCH 0/2] " Arnaldo Carvalho de Melo 2 siblings, 1 reply; 6+ messages in thread From: Adrian Hunter @ 2019-03-27 7:28 UTC (permalink / raw) To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel Unlike python2, python3 strings are not compatible with byte strings. That results in disassembly not working for the branches reports. Fixup those places overlooked in the port to python3. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Fixes: beda0e725e5f ("perf script python: Add Python3 support to exported-sql-viewer.py") --- .../perf/scripts/python/exported-sql-viewer.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py index 0cf30956064a..74ef92f1d19a 100755 --- a/tools/perf/scripts/python/exported-sql-viewer.py +++ b/tools/perf/scripts/python/exported-sql-viewer.py @@ -2908,9 +2908,13 @@ class LibXED(): ok = self.xed_format_context(2, inst.xedp, inst.bufferp, sizeof(inst.buffer), ip, 0, 0) if not ok: return 0, "" + if sys.version_info[0] == 2: + result = inst.buffer.value + else: + result = inst.buffer.value.decode() # Return instruction length and the disassembled instruction text # For now, assume the length is in byte 166 - return inst.xedd[166], inst.buffer.value + return inst.xedd[166], result def TryOpen(file_name): try: @@ -2926,9 +2930,14 @@ def Is64Bit(f): header = f.read(7) f.seek(pos) magic = header[0:4] - eclass = ord(header[4]) - encoding = ord(header[5]) - version = ord(header[6]) + if sys.version_info[0] == 2: + eclass = ord(header[4]) + encoding = ord(header[5]) + version = ord(header[6]) + else: + eclass = header[4] + encoding = header[5] + version = header[6] if magic == chr(127) + "ELF" and eclass > 0 and eclass < 3 and encoding > 0 and encoding < 3 and version == 1: result = True if eclass == 2 else False return result -- 2.17.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [tip:perf/urgent] perf scripts python: exported-sql-viewer.py: Fix python3 support 2019-03-27 7:28 ` [PATCH 2/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter @ 2019-03-29 20:42 ` tip-bot for Adrian Hunter 0 siblings, 0 replies; 6+ messages in thread From: tip-bot for Adrian Hunter @ 2019-03-29 20:42 UTC (permalink / raw) To: linux-tip-commits Cc: mingo, tglx, adrian.hunter, hpa, linux-kernel, acme, jolsa Commit-ID: 606bd60ab6fbcb7f73deeef4fa37cfd5e447a200 Gitweb: https://git.kernel.org/tip/606bd60ab6fbcb7f73deeef4fa37cfd5e447a200 Author: Adrian Hunter <adrian.hunter@intel.com> AuthorDate: Wed, 27 Mar 2019 09:28:26 +0200 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Thu, 28 Mar 2019 15:53:16 -0300 perf scripts python: exported-sql-viewer.py: Fix python3 support Unlike python2, python3 strings are not compatible with byte strings. That results in disassembly not working for the branches reports. Fixup those places overlooked in the port to python3. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Fixes: beda0e725e5f ("perf script python: Add Python3 support to exported-sql-viewer.py") Link: http://lkml.kernel.org/r/20190327072826.19168-3-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/scripts/python/exported-sql-viewer.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py index 0cf30956064a..74ef92f1d19a 100755 --- a/tools/perf/scripts/python/exported-sql-viewer.py +++ b/tools/perf/scripts/python/exported-sql-viewer.py @@ -2908,9 +2908,13 @@ class LibXED(): ok = self.xed_format_context(2, inst.xedp, inst.bufferp, sizeof(inst.buffer), ip, 0, 0) if not ok: return 0, "" + if sys.version_info[0] == 2: + result = inst.buffer.value + else: + result = inst.buffer.value.decode() # Return instruction length and the disassembled instruction text # For now, assume the length is in byte 166 - return inst.xedd[166], inst.buffer.value + return inst.xedd[166], result def TryOpen(file_name): try: @@ -2926,9 +2930,14 @@ def Is64Bit(f): header = f.read(7) f.seek(pos) magic = header[0:4] - eclass = ord(header[4]) - encoding = ord(header[5]) - version = ord(header[6]) + if sys.version_info[0] == 2: + eclass = ord(header[4]) + encoding = ord(header[5]) + version = ord(header[6]) + else: + eclass = header[4] + encoding = header[5] + version = header[6] if magic == chr(127) + "ELF" and eclass > 0 and eclass < 3 and encoding > 0 and encoding < 3 and version == 1: result = True if eclass == 2 else False return result ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] perf scripts python: exported-sql-viewer.py: Fix python3 support 2019-03-27 7:28 [PATCH 0/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter 2019-03-27 7:28 ` [PATCH 1/2] perf scripts python: exported-sql-viewer.py: Fix never-ending loop Adrian Hunter 2019-03-27 7:28 ` [PATCH 2/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter @ 2019-03-27 13:47 ` Arnaldo Carvalho de Melo 2 siblings, 0 replies; 6+ messages in thread From: Arnaldo Carvalho de Melo @ 2019-03-27 13:47 UTC (permalink / raw) To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel Em Wed, Mar 27, 2019 at 09:28:24AM +0200, Adrian Hunter escreveu: > Hi > > Here are a couple for fixes. Thanks, applied to perf/urgent. - Arnaldo > > Adrian Hunter (2): > perf scripts python: exported-sql-viewer.py: Fix never-ending loop > perf scripts python: exported-sql-viewer.py: Fix python3 support > > tools/perf/scripts/python/exported-sql-viewer.py | 77 +++++++++++++++++++----- > 1 file changed, 63 insertions(+), 14 deletions(-) > > > Regards > Adrian -- - Arnaldo ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-03-29 20:42 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-03-27 7:28 [PATCH 0/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter 2019-03-27 7:28 ` [PATCH 1/2] perf scripts python: exported-sql-viewer.py: Fix never-ending loop Adrian Hunter 2019-03-29 20:41 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2019-03-27 7:28 ` [PATCH 2/2] perf scripts python: exported-sql-viewer.py: Fix python3 support Adrian Hunter 2019-03-29 20:42 ` [tip:perf/urgent] " tip-bot for Adrian Hunter 2019-03-27 13:47 ` [PATCH 0/2] " Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox