]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
perf scripts python: intel-pt-events.py: Fix printing of switch events
authorAdrian Hunter <adrian.hunter@intel.com>
Wed, 15 Dec 2021 08:06:36 +0000 (10:06 +0200)
committerAndrea Righi <andrea.righi@canonical.com>
Fri, 21 Jan 2022 14:49:21 +0000 (15:49 +0100)
BugLink: https://bugs.launchpad.net/bugs/1956926
commit 0f80bfbf4919e32f52fe1312c3900ff4fbb7eeb9 upstream.

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: a92bf335fd82eeee ("perf scripts python: intel-pt-events.py: Add branches to script")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20211215080636.149562-4-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
tools/perf/scripts/python/intel-pt-events.py

index 1d3a189a9a5477895a60d475a91eb95a212a56d8..66452a8ec358679eaa99aa29c865115e6b90921a 100644 (file)
@@ -32,8 +32,7 @@ try:
 except:
        broken_pipe_exception = IOError
 
-glb_switch_str         = None
-glb_switch_printed     = True
+glb_switch_str         = {}
 glb_insn               = False
 glb_disassembler       = None
 glb_src                        = False
@@ -70,6 +69,7 @@ def trace_begin():
        ap = argparse.ArgumentParser(usage = "", add_help = False)
        ap.add_argument("--insn-trace", action='store_true')
        ap.add_argument("--src-trace", action='store_true')
+       ap.add_argument("--all-switch-events", action='store_true')
        global glb_args
        global glb_insn
        global glb_src
@@ -256,10 +256,6 @@ def print_srccode(comm, param_dict, sample, symbol, dso, with_insn):
        print(start_str, src_str)
 
 def do_process_event(param_dict):
-       global glb_switch_printed
-       if not glb_switch_printed:
-               print(glb_switch_str)
-               glb_switch_printed = True
        event_attr = param_dict["attr"]
        sample     = param_dict["sample"]
        raw_buf    = param_dict["raw_buf"]
@@ -274,6 +270,11 @@ def do_process_event(param_dict):
        dso    = get_optional(param_dict, "dso")
        symbol = get_optional(param_dict, "symbol")
 
+       cpu = sample["cpu"]
+       if cpu in glb_switch_str:
+               print(glb_switch_str[cpu])
+               del glb_switch_str[cpu]
+
        if name[0:12] == "instructions":
                if glb_src:
                        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):
                sys.exit(1)
 
 def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
-       global glb_switch_printed
-       global glb_switch_str
        if out:
                out_str = "Switch out "
        else:
@@ -350,6 +349,10 @@ def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_pree
                machine_str = ""
        else:
                machine_str = "machine PID %d" % machine_pid
-       glb_switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \
+       switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \
                (out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str)
-       glb_switch_printed = False
+       if glb_args.all_switch_events:
+               print(switch_str);
+       else:
+               global glb_switch_str
+               glb_switch_str[cpu] = switch_str