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 | except: | 32 | except: |
| 33 | broken_pipe_exception = IOError | 33 | broken_pipe_exception = IOError |
| 34 | 34 | ||
| 35 | glb_switch_str = None | 35 | glb_switch_str = {} |
| 36 | glb_switch_printed = True | ||
| 37 | glb_insn = False | 36 | glb_insn = False |
| 38 | glb_disassembler = None | 37 | glb_disassembler = None |
| 39 | glb_src = False | 38 | glb_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_args | 73 | global glb_args |
| 74 | global glb_insn | 74 | global glb_insn |
| 75 | global glb_src | 75 | 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 | ||
| 258 | def do_process_event(param_dict): | 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 | 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 | ||
| 338 | def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x): | 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 | 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_pid | 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 | (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 = 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 | ||