Skip to content

Commit

Permalink
Print the thread name in the live TUI
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pablogsal committed Mar 7, 2024
1 parent b8dd3aa commit f3ed424
Show file tree
Hide file tree
Showing 4 changed files with 553 additions and 548 deletions.
1 change: 1 addition & 0 deletions news/562.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include the thread name in the live TUI
12 changes: 8 additions & 4 deletions src/memray/reporters/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def __init__(self, pid: Optional[int], cmd_line: Optional[str], native: bool):
self.pid = pid
self.cmd_line = cmd_line
self.native = native
self._seen_threads: Set[int] = set()
self._seen_threads: Dict[int, str] = {}
self._max_memory_seen = 0
super().__init__()

Expand Down Expand Up @@ -578,15 +578,15 @@ def watch_thread_idx(self, thread_idx: int) -> None:
"""Called when the thread_idx attribute changes."""
self.query_one("#tid", Label).update(f"[b]TID[/]: {hex(self.current_thread)}")
self.query_one("#thread", Label).update(
f"[b]Thread[/] {thread_idx + 1} of {len(self.threads)}"
f"[b]Thread[/] {thread_idx + 1} of {len(self.threads)} ({self.threads[thread_idx]})"
)
self.query_one(AllocationTable).current_thread = self.current_thread

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

def watch_disconnected(self) -> None:
Expand Down Expand Up @@ -644,7 +644,11 @@ def display_snapshot(self) -> None:
if self.paused:
return

new_tids = {record.tid for record in snapshot.records} - self._seen_threads
new_tids = {
record.tid: record.thread_name
for record in snapshot.records
if record.tid not in self._seen_threads
}
self._seen_threads.update(new_tids)

if new_tids:
Expand Down
Loading

0 comments on commit f3ed424

Please sign in to comment.