perf scripts python: exported-sql-viewer.py: Fix python3 support
authorAdrian Hunter <adrian.hunter@intel.com>
Wed, 27 Mar 2019 07:28:26 +0000 (09:28 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 28 Mar 2019 18:53:16 +0000 (15:53 -0300)
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

index 0cf3095..74ef92f 100755 (executable)
@@ -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