diff options
author | Nick Terrell <terrelln@fb.com> | 2022-12-13 16:21:55 -0800 |
---|---|---|
committer | Nick Terrell <terrelln@fb.com> | 2022-12-13 16:21:55 -0800 |
commit | 4f2c0a4acffbec01079c28f839422e64ddeff004 (patch) | |
tree | 06ada4a8a6d94a94c93944806041b8c994cebfc5 /tools/perf/scripts/python/intel-pt-events.py | |
parent | 88a309465b3f05a100c3b81966982c0f9f5d23a6 (diff) | |
parent | 830b3c68c1fb1e9176028d02ef86f3cf76aa2476 (diff) |
Merge branch 'main' into zstd-linus
Diffstat (limited to 'tools/perf/scripts/python/intel-pt-events.py')
-rw-r--r-- | tools/perf/scripts/python/intel-pt-events.py | 95 |
1 files changed, 84 insertions, 11 deletions
diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py index 66452a8ec358..6be7fd8fd615 100644 --- a/tools/perf/scripts/python/intel-pt-events.py +++ b/tools/perf/scripts/python/intel-pt-events.py @@ -76,16 +76,16 @@ def trace_begin(): glb_args = ap.parse_args() if glb_args.insn_trace: print("Intel PT Instruction Trace") - itrace = "i0nsepwx" + itrace = "i0nsepwxI" glb_insn = True elif glb_args.src_trace: print("Intel PT Source Trace") - itrace = "i0nsepwx" + itrace = "i0nsepwxI" glb_insn = True glb_src = True else: - print("Intel PT Branch Trace, Power Events and PTWRITE") - itrace = "bepwx" + print("Intel PT Branch Trace, Power Events, Event Trace and PTWRITE") + itrace = "bepwxI" global glb_disassembler try: glb_disassembler = LibXED() @@ -104,7 +104,13 @@ def print_ptwrite(raw_buf): flags = data[0] payload = data[1] exact_ip = flags & 1 - print("IP: %u payload: %#x" % (exact_ip, payload), end=' ') + try: + s = payload.to_bytes(8, "little").decode("ascii").rstrip("\x00") + if not s.isprintable(): + s = "" + except: + s = "" + print("IP: %u payload: %#x" % (exact_ip, payload), s, end=' ') def print_cbr(raw_buf): data = struct.unpack_from("<BBBBII", raw_buf) @@ -149,12 +155,54 @@ def print_psb(raw_buf): offset = data[1] print("offset: %#x" % (offset), end=' ') +glb_cfe = ["", "INTR", "IRET", "SMI", "RSM", "SIPI", "INIT", "VMENTRY", "VMEXIT", + "VMEXIT_INTR", "SHUTDOWN", "", "UINT", "UIRET"] + [""] * 18 +glb_evd = ["", "PFA", "VMXQ", "VMXR"] + [""] * 60 + +def print_evt(raw_buf): + data = struct.unpack_from("<BBH", raw_buf) + typ = data[0] & 0x1f + ip_flag = (data[0] & 0x80) >> 7 + vector = data[1] + evd_cnt = data[2] + s = glb_cfe[typ] + if s: + print(" cfe: %s IP: %u vector: %u" % (s, ip_flag, vector), end=' ') + else: + print(" cfe: %u IP: %u vector: %u" % (typ, ip_flag, vector), end=' ') + pos = 4 + for i in range(evd_cnt): + data = struct.unpack_from("<QQ", raw_buf) + et = data[0] & 0x3f + s = glb_evd[et] + if s: + print("%s: %#x" % (s, data[1]), end=' ') + else: + print("EVD_%u: %#x" % (et, data[1]), end=' ') + +def print_iflag(raw_buf): + data = struct.unpack_from("<IQ", raw_buf) + iflag = data[0] & 1 + old_iflag = iflag ^ 1 + via_branch = data[0] & 2 + branch_ip = data[1] + if via_branch: + s = "via" + else: + s = "non" + print("IFLAG: %u->%u %s branch" % (old_iflag, iflag, s), end=' ') + def common_start_str(comm, sample): ts = sample["time"] cpu = sample["cpu"] pid = sample["pid"] tid = sample["tid"] - return "%16s %5u/%-5u [%03u] %9u.%09u " % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000) + if "machine_pid" in sample: + machine_pid = sample["machine_pid"] + vcpu = sample["vcpu"] + return "VM:%5d VCPU:%03d %16s %5u/%-5u [%03u] %9u.%09u " % (machine_pid, vcpu, comm, pid, tid, cpu, ts / 1000000000, ts %1000000000) + else: + return "%16s %5u/%-5u [%03u] %9u.%09u " % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000) def print_common_start(comm, sample, name): flags_disp = get_optional_null(sample, "flags_disp") @@ -164,7 +212,7 @@ def print_common_start(comm, sample, name): # weight = sample["weight"] # transaction = sample["transaction"] # cpumode = get_optional_zero(sample, "cpumode") - print(common_start_str(comm, sample) + "%7s %19s" % (name, flags_disp), end=' ') + print(common_start_str(comm, sample) + "%8s %21s" % (name, flags_disp), end=' ') def print_instructions_start(comm, sample): if "x" in get_optional_null(sample, "flags"): @@ -315,6 +363,14 @@ def do_process_event(param_dict): print_common_start(comm, sample, name) print_psb(raw_buf) print_common_ip(param_dict, sample, symbol, dso) + elif name == "evt": + print_common_start(comm, sample, name) + print_evt(raw_buf) + print_common_ip(param_dict, sample, symbol, dso) + elif name == "iflag": + print_common_start(comm, sample, name) + print_iflag(raw_buf) + print_common_ip(param_dict, sample, symbol, dso) else: print_common_start(comm, sample, name) print_common_ip(param_dict, sample, symbol, dso) @@ -328,9 +384,19 @@ def process_event(param_dict): sys.exit(1) def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x): + if len(x) >= 2 and x[0]: + machine_pid = x[0] + vcpu = x[1] + else: + machine_pid = 0 + vcpu = -1 try: - print("%16s %5u/%-5u [%03u] %9u.%09u error type %u code %u: %s ip 0x%16x" % - ("Trace error", pid, tid, cpu, ts / 1000000000, ts %1000000000, typ, code, msg, ip)) + if machine_pid: + print("VM:%5d VCPU:%03d %16s %5u/%-5u [%03u] %9u.%09u error type %u code %u: %s ip 0x%16x" % + (machine_pid, vcpu, "Trace error", pid, tid, cpu, ts / 1000000000, ts %1000000000, typ, code, msg, ip)) + else: + print("%16s %5u/%-5u [%03u] %9u.%09u error type %u code %u: %s ip 0x%16x" % + ("Trace error", pid, tid, cpu, ts / 1000000000, ts %1000000000, typ, code, msg, ip)) except broken_pipe_exception: # Stop python printing broken pipe errors and traceback sys.stdout = open(os.devnull, 'w') @@ -345,14 +411,21 @@ def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_pree preempt_str = "preempt" else: preempt_str = "" + if len(x) >= 2 and x[0]: + machine_pid = x[0] + vcpu = x[1] + else: + vcpu = None; if machine_pid == -1: machine_str = "" - else: + elif vcpu is None: machine_str = "machine PID %d" % machine_pid + else: + machine_str = "machine PID %d VCPU %d" % (machine_pid, vcpu) switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \ (out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str) if glb_args.all_switch_events: - print(switch_str); + print(switch_str) else: global glb_switch_str glb_switch_str[cpu] = switch_str |