[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <66fd717b870b63ec703b4bf0bbcc50a6d0742c30.camel@intel.com>
Date: Wed, 23 Jul 2025 18:33:28 +0000
From: "Falcon, Thomas" <thomas.falcon@...el.com>
To: "alexander.shishkin@...ux.intel.com" <alexander.shishkin@...ux.intel.com>,
"mhiramat@...nel.org" <mhiramat@...nel.org>, "tmricht@...ux.ibm.com"
<tmricht@...ux.ibm.com>, "xu.yang_2@....com" <xu.yang_2@....com>,
"howardchu95@...il.com" <howardchu95@...il.com>, "Hunter, Adrian"
<adrian.hunter@...el.com>, "ak@...ux.intel.com" <ak@...ux.intel.com>,
"mingo@...hat.com" <mingo@...hat.com>, "irogers@...gle.com"
<irogers@...gle.com>, "gautam@...ux.ibm.com" <gautam@...ux.ibm.com>,
"ctshao@...gle.com" <ctshao@...gle.com>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, "james.clark@...aro.org"
<james.clark@...aro.org>, "collin.funk1@...il.com" <collin.funk1@...il.com>,
"mark.rutland@....com" <mark.rutland@....com>, "peterz@...radead.org"
<peterz@...radead.org>, "linux@...blig.org" <linux@...blig.org>, "Wang,
Weilin" <weilin.wang@...el.com>, "yangtiezhu@...ngson.cn"
<yangtiezhu@...ngson.cn>, "acme@...nel.org" <acme@...nel.org>,
"linux-perf-users@...r.kernel.org" <linux-perf-users@...r.kernel.org>,
"kan.liang@...ux.intel.com" <kan.liang@...ux.intel.com>, "jolsa@...nel.org"
<jolsa@...nel.org>, "namhyung@...nel.org" <namhyung@...nel.org>
Subject: Re: [PATCH v7 11/16] perf ilist: Add new python ilist command
On Mon, 2025-07-14 at 09:43 -0700, Ian Rogers wrote:
> The perf ilist command is a textual app [1] similar to perf list. In
> the top-left pane a tree of PMUs is displayed. Selecting a PMU expands
> the events within it. Selecting an event displays the `perf list`
> style event information in the top-right pane.
>
> When an event is selected it is opened and the counters on each CPU
> the event is for are periodically read. The bottom of the screen
> contains a scrollable set of sparklines showing the events in total
> and on each CPU. Scrolling below the sparklines shows the same data as
> raw counts. The sparklines are small graphs where the height of the
> bar is in relation to maximum of the other counts in the graph.
>
> By default the counts are read with an interval of 0.1 seconds (10
> times per second). A -I/--interval command line option allows the
> interval to be changed. The oldest read counts are dropped when the
> counts fill the line causing the sparkline to move from right to left.
>
> A search box can be pulled up with the 's' key. 'n' and 'p' iterate
> through the search results. As some PMUs have hundreds of events a 'c'
> key will collapse the events in the current PMU to make navigating the
> PMUs easier.
>
> [1] https://textual.textualize.io/
>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
Hi Ian, I hit a segfault playing around with the ilist search feature. I can recreate it pretty
reliably by searching for something then holding down 'n' to quickly cycle through the results.
After a few seconds, the program crashes.
I've attached a backtrace from gdb below.
Thanks,
Tom
#0 __memset_avx2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:210
#1 0x00007fffe88121a7 in perf_evsel__read (evsel=0x555557b16390, cpu_map_idx=8, thread=0,
count=0x0) at evsel.c:403
#2 0x00007fffe88cbf97 in evsel__read_one (evsel=0x555557b16390, cpu_map_idx=8, thread=0) at
util/evsel.c:1719
#3 0x00007fffe88cc794 in evsel__read_counter (evsel=0x555557b16390, cpu_map_idx=8, thread=0) at
util/evsel.c:1896
#4 0x00007fffe880c0a8 in prepare_metric (mexp=0x555555d25660, evsel=<optimized out>,
pctx=0x5555579b5d00, cpu_idx=8, thread_idx=0)
at /home/tfalcon/perf-tools-next/tools/perf/util/python.c:1353
#5 pyrf_evlist__compute_metric (pevlist=<optimized out>, args=<optimized out>, kwargs=<optimized
out>) at /home/tfalcon/perf-tools-next/tools/perf/util/python.c:1428
#6 0x00007ffff7978655 in method_vectorcall_VARARGS_KEYWORDS (func=<optimized out>,
args=0x7ffff7fb1680, nargsf=<optimized out>, kwnames=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/descrobject.c:358
#7 0x00007ffff793f337 in _PyObject_VectorcallTstate (tstate=0x7ffff7d599d0 <_PyRuntime+283024>,
callable=0x7fffe94f3dd0, args=<optimized out>, nargsf=<optimized out>,
kwnames=<optimized out>) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Include/internal/pycore_call.h:168
#8 PyObject_Vectorcall (callable=0x7fffe94f3dd0, args=<optimized out>, nargsf=<optimized out>,
kwnames=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/call.c:327
#9 0x00007ffff794f1c1 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>,
throwflag=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/generated_cases.c.h:1843
#10 0x00007ffff79ab59f in _PyEval_EvalFrame (tstate=0x7ffff7d599d0 <_PyRuntime+283024>,
frame=<optimized out>, throwflag=0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Include/internal/pycore_ceval.h:119
#11 _PyEval_Vector (tstate=0x7ffff7d599d0 <_PyRuntime+283024>, func=0x7fffdde34400, locals=0x0,
args=0x7fffffffc9a8, argcount=1, kwnames=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/ceval.c:1816
#12 _PyFunction_Vectorcall (func=0x7fffdde34400, stack=0x7fffffffc9a8, nargsf=1, kwnames=0x0) at
/usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/call.c:413
#13 _PyObject_VectorcallTstate (tstate=0x7ffff7d599d0 <_PyRuntime+283024>, callable=0x7fffdde34400,
args=0x7fffffffc9a8, nargsf=1, kwnames=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Include/internal/pycore_call.h:168
#14 method_vectorcall (method=<optimized out>, args=0x7ffff7d2a140 <_PyRuntime+88320>,
nargsf=<optimized out>, kwnames=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/classobject.c:70
#15 0x00007ffff795369d in PyObject_Call (callable=0x7fffcfc978c0, args=0x7ffff7d2a128
<_PyRuntime+88296>, kwargs=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/call.c:373
#16 PyCFunction_Call (callable=0x7fffcfc978c0, args=0x7ffff7d2a128 <_PyRuntime+88296>, kwargs=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/call.c:381
#17 _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized
out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/generated_cases.c.h:1355
#18 0x00007ffff7a3a861 in _PyEval_EvalFrame (tstate=0x7ffff7d599d0 <_PyRuntime+283024>,
frame=<optimized out>, throwflag=0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Include/internal/pycore_ceval.h:119
#19 gen_send_ex2 (gen=0x7fffdccfcba0, arg=0x7ffff7d0bd30 <_Py_NoneStruct>, presult=0x7fffffffcc68,
exc=0, closing=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/genobject.c:229
#20 0x00007fffde564149 in task_step_impl (state=state@...ry=0x7fffde89dfd0,
task=task@...ry=0x7fffdcd443c0, exc=exc@...ry=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Modules/_asynciomodule.c:2782
#21 0x00007fffde5657a5 in task_step (state=0x7fffde89dfd0, task=0x7fffdcd443c0, exc=0x0) at
/usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Modules/_asynciomodule.c:3101
#22 0x00007ffff79700a7 in cfunction_vectorcall_O (func=0x7fffcc0b1ad0, args=0x7fffcc37e860,
nargsf=<optimized out>, kwnames=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Include/cpython/methodobject.h:50
#23 0x00007ffff7ad6a3f in _PyObject_VectorcallTstate (tstate=0x7ffff7d599d0 <_PyRuntime+283024>,
callable=0x7fffcc0b1ad0, args=<optimized out>, nargsf=<optimized out>,
kwnames=<optimized out>) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Include/internal/pycore_call.h:168
#24 0x00007ffff78ef15b in context_run (self=0x7fffddf2a440, args=0x7fffcc37e858, nargs=2,
kwnames=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/context.c:664
#25 0x00007ffff7969b4b in cfunction_vectorcall_FASTCALL_KEYWORDS (func=<optimized out>,
args=0x7fffcc37e858, nargsf=<optimized out>, kwnames=<optimized out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/methodobject.c:441
#26 0x00007ffff795369d in PyObject_Call (callable=0x7fffcdff8950, args=0x7fffcc37e840, kwargs=0x0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/call.c:373
#27 PyCFunction_Call (callable=0x7fffcdff8950, args=0x7fffcc37e840, kwargs=0x0) at
/usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Objects/call.c:381
#28 _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized
out>)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/generated_cases.c.h:1355
#29 0x00007ffff7a25fcb in PyEval_EvalCode (co=0x5555555d9a90, globals=<optimized out>,
locals=0x7fffe9634c80)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/ceval.c:604
#30 0x00007ffff7a640c3 in run_eval_code_obj (tstate=tstate@...ry=0x7ffff7d599d0 <_PyRuntime+283024>,
co=co@...ry=0x5555555d9a90, globals=globals@...ry=0x7fffe9634c80,
locals=locals@...ry=0x7fffe9634c80) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Python/pythonrun.c:1381
#31 0x00007ffff7a615f3 in run_mod (mod=mod@...ry=0x555555710ec8,
filename=filename@...ry=0x7fffe96568e0, globals=globals@...ry=0x7fffe9634c80,
locals=locals@...ry=0x7fffe9634c80, flags=flags@...ry=0x7fffffffd298,
arena=arena@...ry=0x7fffe971bdb0, interactive_src=0x0, generate_new_source=0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/pythonrun.c:1466
#32 0x00007ffff7a5dfd6 in pyrun_file (fp=fp@...ry=0x5555555703a0,
filename=filename@...ry=0x7fffe96568e0, start=start@...ry=257, globals=globals@...ry=0x7fffe9634c80,
locals=locals@...ry=0x7fffe9634c80, closeit=closeit@...ry=1, flags=0x7fffffffd298) at
/usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Python/pythonrun.c:1295
#33 0x00007ffff7a5dc4f in _PyRun_SimpleFileObject (fp=fp@...ry=0x5555555703a0,
filename=filename@...ry=0x7fffe96568e0, closeit=closeit@...ry=1,
flags=flags@...ry=0x7fffffffd298) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Python/pythonrun.c:517
#34 0x00007ffff7a5d881 in _PyRun_AnyFileObject (fp=fp@...ry=0x5555555703a0,
filename=filename@...ry=0x7fffe96568e0, closeit=closeit@...ry=1,
flags=flags@...ry=0x7fffffffd298) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Python/pythonrun.c:77
#35 0x00007ffff7a5beda in pymain_run_file_obj (program_name=0x7fffe9634db0, filename=0x7fffe96568e0,
skip_source_first_line=0)
at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Modules/main.c:410
#36 pymain_run_file (config=0x7ffff7d2c0c8 <_PyRuntime+96392>) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Modules/main.c:429
#37 pymain_run_python (exitcode=0x7fffffffd28c) at /usr/src/debug/python3.13-3.13.5-
1.fc41.x86_64/Modules/main.c:696
#38 Py_RunMain () at /usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Modules/main.c:775
#39 0x00007ffff7a1396c in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at
/usr/src/debug/python3.13-3.13.5-1.fc41.x86_64/Modules/main.c:829
#40 0x00007ffff760f488 in __libc_start_call_main (main=main@...ry=0x555555555160 <main>,
argc=argc@...ry=2, argv=argv@...ry=0x7fffffffd4f8)
at ../sysdeps/nptl/libc_start_call_main.h:58
#41 0x00007ffff760f54b in __libc_start_main_impl (main=0x555555555160 <main>, argc=2,
argv=0x7fffffffd4f8, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffd4e8) at ../csu/libc-start.c:360
#42 0x0000555555555095 in _start ()
> ---
> tools/perf/python/ilist.py | 392 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 392 insertions(+)
> create mode 100755 tools/perf/python/ilist.py
>
> diff --git a/tools/perf/python/ilist.py b/tools/perf/python/ilist.py
> new file mode 100755
> index 000000000000..b21f4c93247e
> --- /dev/null
> +++ b/tools/perf/python/ilist.py
> @@ -0,0 +1,392 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
> +"""Interactive perf list."""
> +
> +import argparse
> +from typing import Any, Dict, Tuple
> +import perf
> +from textual import on
> +from textual.app import App, ComposeResult
> +from textual.binding import Binding
> +from textual.containers import Horizontal, HorizontalGroup, Vertical, VerticalScroll
> +from textual.command import SearchIcon
> +from textual.screen import ModalScreen
> +from textual.widgets import Button, Footer, Header, Input, Label, Sparkline, Static, Tree
> +from textual.widgets.tree import TreeNode
> +
> +class ErrorScreen(ModalScreen[bool]):
> + """Pop up dialog for errors."""
> +
> + CSS="""
> + ErrorScreen {
> + align: center middle;
> + }
> + """
> + def __init__(self, error: str):
> + self.error = error
> + super().__init__()
> +
> + def compose(self) -> ComposeResult:
> + yield Button(f"Error: {self.error}", variant="primary", id="error")
> +
> + def on_button_pressed(self, event: Button.Pressed) -> None:
> + self.dismiss(True)
> +
> +
> +class SearchScreen(ModalScreen[str]):
> + """Pop up dialog for search."""
> +
> + CSS="""
> + SearchScreen Horizontal {
> + align: center middle;
> + margin-top: 1;
> + }
> + SearchScreen Input {
> + width: 1fr;
> + }
> + """
> + def compose(self) -> ComposeResult:
> + yield Horizontal(SearchIcon(), Input(placeholder="Event name"))
> +
> + def on_input_submitted(self, event: Input.Submitted) -> None:
> + """Handle the user pressing Enter in the input field."""
> + self.dismiss(event.value)
> +
> +
> +class Counter(HorizontalGroup):
> + """Two labels for a CPU and its counter value."""
> +
> + CSS="""
> + Label {
> + gutter: 1;
> + }
> + """
> +
> + def __init__(self, cpu: int) -> None:
> + self.cpu = cpu
> + super().__init__()
> +
> + def compose(self) -> ComposeResult:
> + label = f"cpu{self.cpu}" if self.cpu >= 0 else "total"
> + yield Label(label + " ")
> + yield Label("0", id=f"counter_{label}")
> +
> +
> +class CounterSparkline(HorizontalGroup):
> + """A Sparkline for a performance counter."""
> +
> + def __init__(self, cpu: int) -> None:
> + self.cpu = cpu
> + super().__init__()
> +
> + def compose(self) -> ComposeResult:
> + label = f"cpu{self.cpu}" if self.cpu >= 0 else "total"
> + yield Label(label)
> + yield Sparkline([], summary_function=max, id=f"sparkline_{label}")
> +
> +
> +class IListApp(App):
> + TITLE = "Interactive Perf List"
> +
> + BINDINGS = [
> + Binding(key="s", action="search", description="Search",
> + tooltip="Search events and PMUs"),
> + Binding(key="n", action="next", description="Next",
> + tooltip="Next search result or item"),
> + Binding(key="p", action="prev", description="Previous",
> + tooltip="Previous search result or item"),
> + Binding(key="c", action="collapse", description="Collapse",
> + tooltip="Collapse the current PMU"),
> + Binding(key="^q", action="quit", description="Quit",
> + tooltip="Quit the app"),
> + ]
> +
> + CSS = """
> + /* Make the 'total' sparkline a different color. */
> + #sparkline_total > .sparkline--min-color {
> + color: $accent;
> + }
> + #sparkline_total > .sparkline--max-color {
> + color: $accent 30%;
> + }
> + /*
> + * Make the active_search initially not displayed with the text in
> + * the middle of the line.
> + */
> + #active_search {
> + display: none;
> + width: 100%;
> + text-align: center;
> + }
> + """
> +
> + def __init__(self, interval: float) -> None:
> + self.interval = interval
> + self.evlist = None
> + self.search_results: list[TreeNode[str]] = []
> + self.cur_search_result: TreeNode[str] | None = None
> + super().__init__()
> +
> +
> +
> + def expand_and_select(self, node: TreeNode[Any]) -> None:
> + """Expand select a node in the tree."""
> + if node.parent:
> + node.parent.expand()
> + if node.parent.parent:
> + node.parent.parent.expand()
> + node.expand()
> + node.tree.select_node(node)
> + node.tree.scroll_to_node(node)
> +
> +
> + def set_searched_tree_node(self, previous: bool) -> None:
> + """Set the cur_search_result node to either the next or previous."""
> + l = len(self.search_results)
> +
> + if l < 1:
> + tree: Tree[str] = self.query_one("#pmus", Tree)
> + if previous:
> + tree.action_cursor_up()
> + else:
> + tree.action_cursor_down()
> + return
> +
> + if self.cur_search_result:
> + idx = self.search_results.index(self.cur_search_result)
> + if previous:
> + idx = idx - 1 if idx > 0 else l - 1
> + else:
> + idx = idx + 1 if idx < l - 1 else 0
> + else:
> + idx = l - 1 if previous else 0
> +
> + node = self.search_results[idx]
> + if node == self.cur_search_result:
> + return
> +
> + self.cur_search_result = node
> + self.expand_and_select(node)
> +
> + def action_search(self) -> None:
> + """Search was chosen."""
> + def set_initial_focus(event: str | None) -> None:
> + """Sets the focus after the SearchScreen is dismissed."""
> +
> + search_label = self.query_one("#active_search", Label)
> + search_label.display = True if event else False
> + if not event:
> + return
> + event = event.lower()
> + search_label.update(f'Searching for events matching "{event}"')
> +
> + tree: Tree[str] = self.query_one("#pmus", Tree)
> + def find_search_results(event: str, node: TreeNode[str], \
> + cursor_seen: bool = False, \
> + match_after_cursor: TreeNode[str] | None = None) \
> + -> Tuple[bool, TreeNode[str] | None]:
> + """Find nodes that match the search remembering the one after the cursor."""
> + if not cursor_seen and node == tree.cursor_node:
> + cursor_seen = True
> + if node.data and event in node.data:
> + if cursor_seen and not match_after_cursor:
> + match_after_cursor = node
> + self.search_results.append(node)
> +
> + if node.children:
> + for child in node.children:
> + (cursor_seen, match_after_cursor) = \
> + find_search_results(event, child, cursor_seen, match_after_cursor)
> + return (cursor_seen, match_after_cursor)
> +
> + self.search_results.clear()
> + (_ , self.cur_search_result) = find_search_results(event, tree.root)
> + if len(self.search_results) < 1:
> + self.push_screen(ErrorScreen(f"Failed to find pmu/event {event}"))
> + search_label.display = False
> + elif self.cur_search_result:
> + self.expand_and_select(self.cur_search_result)
> + else:
> + self.set_searched_tree_node(previous=False)
> +
> + self.push_screen(SearchScreen(), set_initial_focus)
> +
> +
> + def action_next(self) -> None:
> + """Next was chosen."""
> + self.set_searched_tree_node(previous=False)
> +
> +
> + def action_prev(self) -> None:
> + """Previous was chosen."""
> + self.set_searched_tree_node(previous=True)
> +
> +
> + def action_collapse(self) -> None:
> + """Collapse the potentially large number of events under a PMU."""
> + tree: Tree[str] = self.query_one("#pmus", Tree)
> + node = tree.cursor_node
> + if node and node.parent and node.parent.parent:
> + node.parent.collapse_all()
> + node.tree.scroll_to_node(node.parent)
> +
> +
> + def update_counts(self) -> None:
> + """Called every interval to update counts."""
> + if not self.evlist:
> + return
> +
> + def update_count(cpu: int, count: int):
> + # Update the raw count display.
> + counter: Label = self.query(f"#counter_cpu{cpu}" if cpu >= 0 else "#counter_total")
> + if not counter:
> + return
> + counter = counter.first(Label)
> + counter.update(str(count))
> +
> + # Update the sparkline.
> + line: Sparkline = self.query(f"#sparkline_cpu{cpu}" if cpu >= 0 else "#sparkline_total")
> + if not line:
> + return
> + line = line.first(Sparkline)
> + # If there are more events than the width, remove the front event.
> + if len(line.data) > line.size.width:
> + line.data.pop(0)
> + line.data.append(count)
> + line.mutate_reactive(Sparkline.data)
> +
> + # Update the total and each CPU counts, assume there's just 1 evsel.
> + total = 0
> + self.evlist.disable()
> + for evsel in self.evlist:
> + for cpu in evsel.cpus():
> + aggr = 0
> + for thread in evsel.threads():
> + counts = evsel.read(cpu, thread)
> + aggr += counts.val
> + update_count(cpu, aggr)
> + total += aggr
> + update_count(-1, total)
> + self.evlist.enable()
> +
> +
> + def on_mount(self) -> None:
> + """When App starts set up periodic event updating."""
> + self.update_counts()
> + self.set_interval(self.interval, self.update_counts)
> +
> +
> + def set_pmu_and_event(self, pmu: str, event: str) -> None:
> + """Updates the event/description and starts the counters."""
> + # Remove previous event information.
> + if self.evlist:
> + self.evlist.disable()
> + self.evlist.close()
> + lines = self.query(CounterSparkline)
> + for line in lines:
> + line.remove()
> + lines = self.query(Counter)
> + for line in lines:
> + line.remove()
> +
> + def pmu_event_description(pmu: str, event: str) -> str:
> + """Find and format event description for {pmu}/{event}/."""
> + def get_info(info: Dict[str, str], key: str):
> + return (info[key] + "\n") if key in info else ""
> +
> + for p in perf.pmus():
> + if p.name() != pmu:
> + continue
> + for info in p.events():
> + if "name" not in info or info["name"] != event:
> + continue
> +
> + desc = get_info(info, "topic")
> + desc += get_info(info, "event_type_desc")
> + desc += get_info(info, "desc")
> + desc += get_info(info, "long_desc")
> + desc += get_info(info, "encoding_desc")
> + return desc
> + return "description"
> +
> + # Parse event, update event text and description.
> + full_name = event if event.startswith(pmu) or ':' in event else f"{pmu}/{event}/"
> + self.query_one("#event_name", Label).update(full_name)
> + self.query_one("#event_description", Static).update(pmu_event_description(pmu, event))
> +
> + # Open the event.
> + try:
> + self.evlist = perf.parse_events(full_name)
> + if self.evlist:
> + self.evlist.open()
> + self.evlist.enable()
> + except:
> + self.evlist = None
> +
> + if not self.evlist:
> + self.push_screen(ErrorScreen(f"Failed to open {full_name}"))
> + return
> +
> + # Add spark lines for all the CPUs. Note, must be done after
> + # open so that the evlist CPUs have been computed by propagate
> + # maps.
> + lines = self.query_one("#lines")
> + line = CounterSparkline(cpu=-1)
> + lines.mount(line)
> + for cpu in self.evlist.all_cpus():
> + line = CounterSparkline(cpu)
> + lines.mount(line)
> + line = Counter(cpu=-1)
> + lines.mount(line)
> + for cpu in self.evlist.all_cpus():
> + line = Counter(cpu)
> + lines.mount(line)
> +
> +
> + def compose(self) -> ComposeResult:
> + """Draws the app."""
> + def pmu_event_tree() -> Tree:
> + """Create tree of PMUs with events under."""
> + tree: Tree[str] = Tree("PMUs", id="pmus")
> + tree.root.expand()
> + for pmu in perf.pmus():
> + pmu_name = pmu.name().lower()
> + pmu_node = tree.root.add(pmu_name, data=pmu_name)
> + try:
> + for event in sorted(pmu.events(), key=lambda x: x["name"]):
> + if "name" in event:
> + e = event["name"].lower()
> + if "alias" in event:
> + pmu_node.add_leaf(f'{e} ({event["alias"]})', data=e)
> + else:
> + pmu_node.add_leaf(e, data=e)
> + except:
> + # Reading events may fail with EPERM, ignore.
> + pass
> + return tree
> +
> + yield Header(id="header")
> + yield Horizontal(Vertical(pmu_event_tree(), id="events"),
> + Vertical(Label("event name", id="event_name"),
> + Static("description", markup=False, id="event_description"),
> + ))
> + yield Label(id="active_search")
> + yield VerticalScroll(id="lines")
> + yield Footer(id="footer")
> +
> +
> + @on(Tree.NodeSelected)
> + def on_tree_node_selected(self, event: Tree.NodeSelected[str]) -> None:
> + """Called when a tree node is selected, selecting the event."""
> + if event.node.parent and event.node.parent.parent:
> + assert event.node.parent.data is not None
> + assert event.node.data is not None
> + self.set_pmu_and_event(event.node.parent.data, event.node.data)
> +
> +
> +if __name__ == "__main__":
> + ap = argparse.ArgumentParser()
> + ap.add_argument('-I', '--interval', help="Counter update interval in seconds", default=0.1)
> + args = ap.parse_args()
> + app = IListApp(float(args.interval))
> + app.run()
Powered by blists - more mailing lists