Skip to content

Commit 3036a9e

Browse files
committed
Print the thread name in the live TUI
To allow users to determine thread in a multithreaded application corresponds to the "Thread X of Y" number displayed in the live view, include the thread name that we collect in the TUI. Signed-off-by: Pablo Galindo <[email protected]>
1 parent b8dd3aa commit 3036a9e

File tree

4 files changed

+555
-548
lines changed

4 files changed

+555
-548
lines changed

news/562.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include the thread name in the live TUI

src/memray/reporters/tui.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def __init__(self, pid: Optional[int], cmd_line: Optional[str], native: bool):
540540
self.pid = pid
541541
self.cmd_line = cmd_line
542542
self.native = native
543-
self._seen_threads: Set[int] = set()
543+
self._seen_threads: Dict[int, str] = {}
544544
self._max_memory_seen = 0
545545
super().__init__()
546546

@@ -578,15 +578,17 @@ def watch_thread_idx(self, thread_idx: int) -> None:
578578
"""Called when the thread_idx attribute changes."""
579579
self.query_one("#tid", Label).update(f"[b]TID[/]: {hex(self.current_thread)}")
580580
self.query_one("#thread", Label).update(
581-
f"[b]Thread[/] {thread_idx + 1} of {len(self.threads)}"
581+
f"[b]Thread[/] {thread_idx + 1} of {len(self.threads)} "
582+
f"({self.threads[thread_idx]})"
582583
)
583584
self.query_one(AllocationTable).current_thread = self.current_thread
584585

585586
def watch_threads(self, threads: List[int]) -> None:
586587
"""Called when the threads attribute changes."""
587588
self.query_one("#tid", Label).update(f"[b]TID[/]: {hex(self.current_thread)}")
588589
self.query_one("#thread", Label).update(
589-
f"[b]Thread[/] {self.thread_idx + 1} of {len(threads)}"
590+
f"[b]Thread[/] {self.thread_idx + 1} of {len(self.threads)} "
591+
f"({self.threads[self.thread_idx]})"
590592
)
591593

592594
def watch_disconnected(self) -> None:
@@ -644,7 +646,11 @@ def display_snapshot(self) -> None:
644646
if self.paused:
645647
return
646648

647-
new_tids = {record.tid for record in snapshot.records} - self._seen_threads
649+
new_tids = {
650+
record.tid: record.thread_name
651+
for record in snapshot.records
652+
if record.tid not in self._seen_threads
653+
}
648654
self._seen_threads.update(new_tids)
649655

650656
if new_tids:

0 commit comments

Comments
 (0)