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>

authored by Adrian Hunter and committed by Arnaldo Carvalho de Melo 606bd60a 8453c936

+13 -4
+13 -4
tools/perf/scripts/python/exported-sql-viewer.py
··· 2908 2908 ok = self.xed_format_context(2, inst.xedp, inst.bufferp, sizeof(inst.buffer), ip, 0, 0) 2909 2909 if not ok: 2910 2910 return 0, "" 2911 + if sys.version_info[0] == 2: 2912 + result = inst.buffer.value 2913 + else: 2914 + result = inst.buffer.value.decode() 2911 2915 # Return instruction length and the disassembled instruction text 2912 2916 # For now, assume the length is in byte 166 2913 - return inst.xedd[166], inst.buffer.value 2917 + return inst.xedd[166], result 2914 2918 2915 2919 def TryOpen(file_name): 2916 2920 try: ··· 2930 2926 header = f.read(7) 2931 2927 f.seek(pos) 2932 2928 magic = header[0:4] 2933 - eclass = ord(header[4]) 2934 - encoding = ord(header[5]) 2935 - version = ord(header[6]) 2929 + if sys.version_info[0] == 2: 2930 + eclass = ord(header[4]) 2931 + encoding = ord(header[5]) 2932 + version = ord(header[6]) 2933 + else: 2934 + eclass = header[4] 2935 + encoding = header[5] 2936 + version = header[6] 2936 2937 if magic == chr(127) + "ELF" and eclass > 0 and eclass < 3 and encoding > 0 and encoding < 3 and version == 1: 2937 2938 result = True if eclass == 2 else False 2938 2939 return result