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.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -32,8 +32,7 @@ try: · 31 unmodified lines | ||
| 32 | 32 | except: |
| 33 | 33 | broken_pipe_exception = IOError |
| 34 | 34 | |
| 35 | −glb_switch_str = None | |
| 36 | −glb_switch_printed = True | |
| 35 | +glb_switch_str = {} | |
| 37 | 36 | glb_insn = False |
| 38 | 37 | glb_disassembler = None |
| 39 | 38 | glb_src = False |
| @@ -70,6 +69,7 @@ def trace_begin(): · 30 unmodified lines | ||
| 70 | 69 | ap = argparse.ArgumentParser(usage = "", add_help = False) |
| 71 | 70 | ap.add_argument("--insn-trace", action='store_true') |
| 72 | 71 | ap.add_argument("--src-trace", action='store_true') |
| 72 | + ap.add_argument("--all-switch-events", action='store_true') | |
| 73 | 73 | global glb_args |
| 74 | 74 | global glb_insn |
| 75 | 75 | global glb_src |
| @@ -256,10 +256,6 @@ def print_srccode(comm, param_dict, sample, symbol, dso, with_insn): · 180 unmodified lines | ||
| 256 | 256 | print(start_str, src_str) |
| 257 | 257 | |
| 258 | 258 | def 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 | 259 | event_attr = param_dict["attr"] |
| 264 | 260 | sample = param_dict["sample"] |
| 265 | 261 | raw_buf = param_dict["raw_buf"] |
| @@ -274,6 +270,11 @@ def do_process_event(param_dict): · 8 unmodified lines | ||
| 274 | 270 | dso = get_optional(param_dict, "dso") |
| 275 | 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 | 278 | if name[0:12] == "instructions": |
| 278 | 279 | if glb_src: |
| 279 | 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 | 337 | sys.exit(1) |
| 337 | 338 | |
| 338 | 339 | def 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 | 340 | if out: |
| 342 | 341 | out_str = "Switch out " |
| 343 | 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 | 349 | machine_str = "" |
| 351 | 350 | else: |
| 352 | 351 | 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 | 353 | (out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str) |
| 355 | − glb_switch_printed = False | |
| 354 | + if glb_args.all_switch_events: | |
| 355 | + print(switch_str); | |
| 356 | + else: | |
| 357 | + global glb_switch_str | |
| 358 | + glb_switch_str[cpu] = switch_str | |