History

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.

Adrian Hunter committed 4 years ago

Commit 95f9bfc1 parent 26738591 file · +50 −5Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/intel-pt-events.py+50−5
@@ -76,16 +76,16 @@ def trace_begin(): · 75 unmodified lines
76 glb_args = ap.parse_args()76 glb_args = ap.parse_args()
77 if glb_args.insn_trace:77 if glb_args.insn_trace:
78 print("Intel PT Instruction Trace")78 print("Intel PT Instruction Trace")
79 itrace = "i0nsepwx"79 itrace = "i0nsepwxI"
80 glb_insn = True80 glb_insn = True
81 elif glb_args.src_trace:81 elif glb_args.src_trace:
82 print("Intel PT Source Trace")82 print("Intel PT Source Trace")
83 itrace = "i0nsepwx"83 itrace = "i0nsepwxI"
84 glb_insn = True84 glb_insn = True
85 glb_src = True85 glb_src = True
86 else:86 else:
87 print("Intel PT Branch Trace, Power Events and PTWRITE")87 print("Intel PT Branch Trace, Power Events, Event Trace and PTWRITE")
88 itrace = "bepwx"88 itrace = "bepwxI"
89 global glb_disassembler89 global glb_disassembler
90 try:90 try:
91 glb_disassembler = LibXED()91 glb_disassembler = LibXED()
@@ -149,6 +149,43 @@ def print_psb(raw_buf): · 57 unmodified lines
149 offset = data[1]149 offset = data[1]
150 print("offset: %#x" % (offset), end=' ')150 print("offset: %#x" % (offset), end=' ')
151 151
152glb_cfe = ["", "INTR", "IRET", "SMI", "RSM", "SIPI", "INIT", "VMENTRY", "VMEXIT",
153 "VMEXIT_INTR", "SHUTDOWN", "", "UINT", "UIRET"] + [""] * 18
154glb_evd = ["", "PFA", "VMXQ", "VMXR"] + [""] * 60
155
156def 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
177def 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
152def common_start_str(comm, sample):189def common_start_str(comm, sample):
153 ts = sample["time"]190 ts = sample["time"]
154 cpu = sample["cpu"]191 cpu = sample["cpu"]
@@ -164,7 +201,7 @@ def print_common_start(comm, sample, name): · 9 unmodified lines
164 # weight = sample["weight"]201 # weight = sample["weight"]
165 # transaction = sample["transaction"]202 # transaction = sample["transaction"]
166 # cpumode = get_optional_zero(sample, "cpumode")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
169def print_instructions_start(comm, sample):206def print_instructions_start(comm, sample):
170 if "x" in get_optional_null(sample, "flags"):207 if "x" in get_optional_null(sample, "flags"):
@@ -315,6 +352,14 @@ def do_process_event(param_dict): · 144 unmodified lines
315 print_common_start(comm, sample, name)352 print_common_start(comm, sample, name)
316 print_psb(raw_buf)353 print_psb(raw_buf)
317 print_common_ip(param_dict, sample, symbol, dso)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 else:363 else:
319 print_common_start(comm, sample, name)364 print_common_start(comm, sample, name)
320 print_common_ip(param_dict, sample, symbol, dso)365 print_common_ip(param_dict, sample, symbol, dso)