Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf scripts python: intel-pt-events.py: Add Event Trace

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.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20220124084201.2699795-22-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
95f9bfcf 26738598

+50 -5
+50 -5
tools/perf/scripts/python/intel-pt-events.py
··· 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 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"] ··· 201 164 # weight = sample["weight"] 202 165 # transaction = sample["transaction"] 203 166 # cpumode = get_optional_zero(sample, "cpumode") 204 - print(common_start_str(comm, sample) + "%7s %19s" % (name, flags_disp), end=' ') 167 + print(common_start_str(comm, sample) + "%8s %21s" % (name, flags_disp), end=' ') 205 168 206 169 def print_instructions_start(comm, sample): 207 170 if "x" in get_optional_null(sample, "flags"): ··· 351 314 elif name == "psb": 352 315 print_common_start(comm, sample, name) 353 316 print_psb(raw_buf) 317 + print_common_ip(param_dict, sample, symbol, dso) 318 + elif name == "evt": 319 + print_common_start(comm, sample, name) 320 + print_evt(raw_buf) 321 + print_common_ip(param_dict, sample, symbol, dso) 322 + elif name == "iflag": 323 + print_common_start(comm, sample, name) 324 + print_iflag(raw_buf) 354 325 print_common_ip(param_dict, sample, symbol, dso) 355 326 else: 356 327 print_common_start(comm, sample, name)