def print_common_ip(param_dict, sample, symbol, dso): ip = sample["ip"] offs = get_offset(param_dict, "symoff") if "cyc_cnt" in sample: cyc_cnt = sample["cyc_cnt"] insn_cnt = get_optional_zero(sample, "insn_cnt") ipc_str = " IPC: %#.2f (%u/%u)" % (insn_cnt / cyc_cnt, insn_cnt, cyc_cnt) else: ipc_str = "" if glb_insn and glb_disassembler is not None: insn = perf_sample_insn(perf_script_context) if insn and len(insn): cnt, text = disassem(insn, ip) byte_str = ("%x" % ip).rjust(16) if sys.version_info.major >= 3: for k in range(cnt): byte_str += " %02x" % insn[k] else: for k in xrange(cnt): byte_str += " %02x" % ord(insn[k]) print("%-40s %-30s" % (byte_str, text), end=' ') print("%s%s (%s)" % (symbol, offs, dso), end=' ') else: print("%16x %s%s (%s)" % (ip, symbol, offs, dso), end=' ') if "addr_correlates_sym" in sample: addr = sample["addr"] dso = get_optional(sample, "addr_dso") symbol = get_optional(sample, "addr_symbol") offs = get_offset(sample, "addr_symoff") print("=> %x %s%s (%s)%s" % (addr, symbol, offs, dso, ipc_str)) else: print(ipc_str)
def print_srccode(comm, param_dict, sample, symbol, dso, with_insn): ip = sample["ip"] if symbol == "[unknown]": start_str = common_start_str(comm, sample) + ("%x" % ip).rjust(16).ljust(40) else: offs = get_offset(param_dict, "symoff") start_str = common_start_str(comm, sample) + (symbol + offs).ljust(40) if with_insn and glb_insn and glb_disassembler is not None: insn = perf_sample_insn(perf_script_context) if insn and len(insn): cnt, text = disassem(insn, ip) start_str += text.ljust(30) global glb_source_file_name global glb_line_number global glb_dso source_file_name, line_number, source_line = perf_sample_srccode( perf_script_context) if source_file_name: if glb_line_number == line_number and glb_source_file_name == source_file_name: src_str = "" else: if len(source_file_name) > 40: src_file = ("..." + source_file_name[-37:]) + " " else: src_file = source_file_name.ljust(41) if source_line is None: src_str = src_file + str(line_number).rjust( 4) + " <source not found>" else: src_str = src_file + str(line_number).rjust( 4) + " " + source_line glb_dso = None elif dso == glb_dso: src_str = "" else: src_str = dso glb_dso = dso glb_line_number = line_number glb_source_file_name = source_file_name print(start_str, src_str)