History

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.

Adrian Hunter committed 7 years ago

Commit 606bd601 parent 8453c931 file · +13 −4Browse files

Showing the changes to tools/perf/scripts/python/exported-sql-viewer.py (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/exported-sql-viewer.py+13−4
@@ -2908,9 +2908,13 @@ class LibXED(): · 2907 unmodified lines
29082908 ok = self.xed_format_context(2, inst.xedp, inst.bufferp, sizeof(inst.buffer), ip, 0, 0)
29092909 if not ok:
29102910 return 0, ""
2911+ if sys.version_info[0] == 2:
2912+ result = inst.buffer.value
2913+ else:
2914+ result = inst.buffer.value.decode()
29112915 # Return instruction length and the disassembled instruction text
29122916 # For now, assume the length is in byte 166
2913− return inst.xedd[166], inst.buffer.value
2917+ return inst.xedd[166], result
29142918
29152919 def TryOpen(file_name):
29162920 try:
@@ -2926,9 +2930,14 @@ def Is64Bit(f): · 9 unmodified lines
29262930 header = f.read(7)
29272931 f.seek(pos)
29282932 magic = header[0:4]
2929− eclass = ord(header[4])
2930− encoding = ord(header[5])
2931− version = ord(header[6])
2933+ if sys.version_info[0] == 2:
2934+ eclass = ord(header[4])
2935+ encoding = ord(header[5])
2936+ version = ord(header[6])
2937+ else:
2938+ eclass = header[4]
2939+ encoding = header[5]
2940+ version = header[6]
29322941 if magic == chr(127) + "ELF" and eclass > 0 and eclass < 3 and encoding > 0 and encoding < 3 and version == 1:
29332942 result = True if eclass == 2 else False
29342943 return result