Add Event Trace to the intel-pt-events.py script. This shows how to unpack the raw data from the new sample events in a Python script.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -76,16 +76,16 @@ def trace_begin(): · 75 unmodified lines | ||
| 76 | 76 | glb_args = ap.parse_args() |
| 77 | 77 | if glb_args.insn_trace: |
| 78 | 78 | print("Intel PT Instruction Trace") |
| 79 | − itrace = "i0nsepwx" | |
| 79 | + itrace = "i0nsepwxI" | |
| 80 | 80 | glb_insn = True |
| 81 | 81 | elif glb_args.src_trace: |
| 82 | 82 | print("Intel PT Source Trace") |
| 83 | − itrace = "i0nsepwx" | |
| 83 | + itrace = "i0nsepwxI" | |
| 84 | 84 | glb_insn = True |
| 85 | 85 | glb_src = True |
| 86 | 86 | else: |
| 87 | − print("Intel PT Branch Trace, Power Events and PTWRITE") | |
| 88 | − itrace = "bepwx" | |
| 87 | + print("Intel PT Branch Trace, Power Events, Event Trace and PTWRITE") | |
| 88 | + itrace = "bepwxI" | |
| 89 | 89 | global glb_disassembler |
| 90 | 90 | try: |
| 91 | 91 | glb_disassembler = LibXED() |
| @@ -149,6 +149,43 @@ def print_psb(raw_buf): · 57 unmodified lines | ||
| 149 | 149 | offset = data[1] |
| 150 | 150 | print("offset: %#x" % (offset), end=' ') |
| 151 | 151 | |
| 152 | +glb_cfe = ["", "INTR", "IRET", "SMI", "RSM", "SIPI", "INIT", "VMENTRY", "VMEXIT", | |
| 153 | + "VMEXIT_INTR", "SHUTDOWN", "", "UINT", "UIRET"] + [""] * 18 | |
| 154 | +glb_evd = ["", "PFA", "VMXQ", "VMXR"] + [""] * 60 | |
| 155 | + | |
| 156 | +def print_evt(raw_buf): | |
| 157 | + data = struct.unpack_from("<BBH", raw_buf) | |
| 158 | + typ = data[0] & 0x1f | |
| 159 | + ip_flag = (data[0] & 0x80) >> 7 | |
| 160 | + vector = data[1] | |
| 161 | + evd_cnt = data[2] | |
| 162 | + s = glb_cfe[typ] | |
| 163 | + if s: | |
| 164 | + print(" cfe: %s IP: %u vector: %u" % (s, ip_flag, vector), end=' ') | |
| 165 | + else: | |
| 166 | + print(" cfe: %u IP: %u vector: %u" % (typ, ip_flag, vector), end=' ') | |
| 167 | + pos = 4 | |
| 168 | + for i in range(evd_cnt): | |
| 169 | + data = struct.unpack_from("<QQ", raw_buf) | |
| 170 | + et = data[0] & 0x3f | |
| 171 | + s = glb_evd[et] | |
| 172 | + if s: | |
| 173 | + print("%s: %#x" % (s, data[1]), end=' ') | |
| 174 | + else: | |
| 175 | + print("EVD_%u: %#x" % (et, data[1]), end=' ') | |
| 176 | + | |
| 177 | +def print_iflag(raw_buf): | |
| 178 | + data = struct.unpack_from("<IQ", raw_buf) | |
| 179 | + iflag = data[0] & 1 | |
| 180 | + old_iflag = iflag ^ 1 | |
| 181 | + via_branch = data[0] & 2 | |
| 182 | + branch_ip = data[1] | |
| 183 | + if via_branch: | |
| 184 | + s = "via" | |
| 185 | + else: | |
| 186 | + s = "non" | |
| 187 | + print("IFLAG: %u->%u %s branch" % (old_iflag, iflag, s), end=' ') | |
| 188 | + | |
| 152 | 189 | def common_start_str(comm, sample): |
| 153 | 190 | ts = sample["time"] |
| 154 | 191 | cpu = sample["cpu"] |
| @@ -164,7 +201,7 @@ def print_common_start(comm, sample, name): · 9 unmodified lines | ||
| 164 | 201 | # weight = sample["weight"] |
| 165 | 202 | # transaction = sample["transaction"] |
| 166 | 203 | # cpumode = get_optional_zero(sample, "cpumode") |
| 167 | − print(common_start_str(comm, sample) + "%7s %19s" % (name, flags_disp), end=' ') | |
| 204 | + print(common_start_str(comm, sample) + "%8s %21s" % (name, flags_disp), end=' ') | |
| 168 | 205 | |
| 169 | 206 | def print_instructions_start(comm, sample): |
| 170 | 207 | if "x" in get_optional_null(sample, "flags"): |
| @@ -315,6 +352,14 @@ def do_process_event(param_dict): · 144 unmodified lines | ||
| 315 | 352 | print_common_start(comm, sample, name) |
| 316 | 353 | print_psb(raw_buf) |
| 317 | 354 | print_common_ip(param_dict, sample, symbol, dso) |
| 355 | + elif name == "evt": | |
| 356 | + print_common_start(comm, sample, name) | |
| 357 | + print_evt(raw_buf) | |
| 358 | + print_common_ip(param_dict, sample, symbol, dso) | |
| 359 | + elif name == "iflag": | |
| 360 | + print_common_start(comm, sample, name) | |
| 361 | + print_iflag(raw_buf) | |
| 362 | + print_common_ip(param_dict, sample, symbol, dso) | |
| 318 | 363 | else: |
| 319 | 364 | print_common_start(comm, sample, name) |
| 320 | 365 | print_common_ip(param_dict, sample, symbol, dso) |