History

perf scripts python: intel-pt-events.py: Fix printing of switch events

The intel-pt-events.py script displays only the last of consecutive switch statements but that may not be the last switch event for the CPU. Fix by keeping a dictionary of last context switch keyed by CPU, and make it possible to see all switch events by adding option --all-switch-events.

Adrian Hunter committed 4 years ago

Commit 0f80bfb1 parent 5e0c3251 file · +13 −10Browse 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+13−10
@@ -32,8 +32,7 @@ try: · 31 unmodified lines
32except:32except:
33 broken_pipe_exception = IOError33 broken_pipe_exception = IOError
34 34
35glb_switch_str = None35glb_switch_str = {}
36glb_switch_printed = True
37glb_insn = False36glb_insn = False
38glb_disassembler = None37glb_disassembler = None
39glb_src = False38glb_src = False
@@ -70,6 +69,7 @@ def trace_begin(): · 30 unmodified lines
70 ap = argparse.ArgumentParser(usage = "", add_help = False)69 ap = argparse.ArgumentParser(usage = "", add_help = False)
71 ap.add_argument("--insn-trace", action='store_true')70 ap.add_argument("--insn-trace", action='store_true')
72 ap.add_argument("--src-trace", action='store_true')71 ap.add_argument("--src-trace", action='store_true')
72 ap.add_argument("--all-switch-events", action='store_true')
73 global glb_args73 global glb_args
74 global glb_insn74 global glb_insn
75 global glb_src75 global glb_src
@@ -256,10 +256,6 @@ def print_srccode(comm, param_dict, sample, symbol, dso, with_insn): · 180 unmodified lines
256 print(start_str, src_str)256 print(start_str, src_str)
257 257
258def do_process_event(param_dict):258def do_process_event(param_dict):
259 global glb_switch_printed
260 if not glb_switch_printed:
261 print(glb_switch_str)
262 glb_switch_printed = True
263 event_attr = param_dict["attr"]259 event_attr = param_dict["attr"]
264 sample = param_dict["sample"]260 sample = param_dict["sample"]
265 raw_buf = param_dict["raw_buf"]261 raw_buf = param_dict["raw_buf"]
@@ -274,6 +270,11 @@ def do_process_event(param_dict): · 8 unmodified lines
274 dso = get_optional(param_dict, "dso")270 dso = get_optional(param_dict, "dso")
275 symbol = get_optional(param_dict, "symbol")271 symbol = get_optional(param_dict, "symbol")
276 272
273 cpu = sample["cpu"]
274 if cpu in glb_switch_str:
275 print(glb_switch_str[cpu])
276 del glb_switch_str[cpu]
277
277 if name[0:12] == "instructions":278 if name[0:12] == "instructions":
278 if glb_src:279 if glb_src:
279 print_srccode(comm, param_dict, sample, symbol, dso, True)280 print_srccode(comm, param_dict, sample, symbol, dso, True)
@@ -336,8 +337,6 @@ def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x): · 56 unmodified lines
336 sys.exit(1)337 sys.exit(1)
337 338
338def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):339def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
339 global glb_switch_printed
340 global glb_switch_str
341 if out:340 if out:
342 out_str = "Switch out "341 out_str = "Switch out "
343 else:342 else:
@@ -350,6 +349,10 @@ def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_pree · 6 unmodified lines
350 machine_str = ""349 machine_str = ""
351 else:350 else:
352 machine_str = "machine PID %d" % machine_pid351 machine_str = "machine PID %d" % machine_pid
353 glb_switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \352 switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \
354 (out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str)353 (out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str)
355 glb_switch_printed = False354 if glb_args.all_switch_events:
355 print(switch_str);
356 else:
357 global glb_switch_str
358 glb_switch_str[cpu] = switch_str