Skip to content

Commit 0f80bfb

Browse files
ahunter6acmel
authored andcommitted
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. Fixes: a92bf33 ("perf scripts python: intel-pt-events.py: Add branches to script") Signed-off-by: Adrian Hunter <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Riccardo Mancini <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5e0c325 commit 0f80bfb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tools/perf/scripts/python/intel-pt-events.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
except:
3333
broken_pipe_exception = IOError
3434

35-
glb_switch_str = None
36-
glb_switch_printed = True
35+
glb_switch_str = {}
3736
glb_insn = False
3837
glb_disassembler = None
3938
glb_src = False
@@ -70,6 +69,7 @@ def trace_begin():
7069
ap = argparse.ArgumentParser(usage = "", add_help = False)
7170
ap.add_argument("--insn-trace", action='store_true')
7271
ap.add_argument("--src-trace", action='store_true')
72+
ap.add_argument("--all-switch-events", action='store_true')
7373
global glb_args
7474
global glb_insn
7575
global glb_src
@@ -256,10 +256,6 @@ def print_srccode(comm, param_dict, sample, symbol, dso, with_insn):
256256
print(start_str, src_str)
257257

258258
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
263259
event_attr = param_dict["attr"]
264260
sample = param_dict["sample"]
265261
raw_buf = param_dict["raw_buf"]
@@ -274,6 +270,11 @@ def do_process_event(param_dict):
274270
dso = get_optional(param_dict, "dso")
275271
symbol = get_optional(param_dict, "symbol")
276272

273+
cpu = sample["cpu"]
274+
if cpu in glb_switch_str:
275+
print(glb_switch_str[cpu])
276+
del glb_switch_str[cpu]
277+
277278
if name[0:12] == "instructions":
278279
if glb_src:
279280
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):
336337
sys.exit(1)
337338

338339
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
341340
if out:
342341
out_str = "Switch out "
343342
else:
@@ -350,6 +349,10 @@ def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_pree
350349
machine_str = ""
351350
else:
352351
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" % \
354353
(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

0 commit comments

Comments
 (0)