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
7676 glb_args = ap.parse_args()
7777 if glb_args.insn_trace:
7878 print("Intel PT Instruction Trace")
79− itrace = "i0nsepwx"
79+ itrace = "i0nsepwxI"
8080 glb_insn = True
8181 elif glb_args.src_trace:
8282 print("Intel PT Source Trace")
83− itrace = "i0nsepwx"
83+ itrace = "i0nsepwxI"
8484 glb_insn = True
8585 glb_src = True
8686 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"
8989 global glb_disassembler
9090 try:
9191 glb_disassembler = LibXED()
@@ -149,6 +149,43 @@ def print_psb(raw_buf): · 57 unmodified lines
149149 offset = data[1]
150150 print("offset: %#x" % (offset), end=' ')
151151
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+
152189 def common_start_str(comm, sample):
153190 ts = sample["time"]
154191 cpu = sample["cpu"]
@@ -164,7 +201,7 @@ def print_common_start(comm, sample, name): · 9 unmodified lines
164201 # weight = sample["weight"]
165202 # transaction = sample["transaction"]
166203 # 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=' ')
168205
169206 def print_instructions_start(comm, sample):
170207 if "x" in get_optional_null(sample, "flags"):
@@ -315,6 +352,14 @@ def do_process_event(param_dict): · 144 unmodified lines
315352 print_common_start(comm, sample, name)
316353 print_psb(raw_buf)
317354 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)
318363 else:
319364 print_common_start(comm, sample, name)
320365 print_common_ip(param_dict, sample, symbol, dso)