tab_title_template: Add a field that evaluated to the total memory used by all child processes in the tab

Fixes #10293
This commit is contained in:
Kovid Goyal 2026-07-29 13:36:24 +05:30
parent 503e1d1b5c
commit 9524c76fab
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 2 deletions

View file

@ -195,6 +195,8 @@ Detailed list of changes
- Add support for `terminal visibility reports <https://rockorager.dev/misc/visibility-reports/>`__
- :opt:`tab_title_template`: Add a field that evaluated to the total memory used by all child processes in the tab (:iss:`10293`)
0.48.1 [2026-07-24]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -703,7 +703,7 @@ class Child:
except OSError:
pass
def get_memory_used_by_child(self, check_if_cgroup_root: bool = False) -> int:
def get_memory_used_by_child(self) -> int:
if self.pid is None:
return -1
return memory_used_by_process_tree_rooted_at(self.pid, check_if_cgroup_root)
return memory_used_by_process_tree_rooted_at(self.pid, check_if_cgroup_root=False)

View file

@ -2258,6 +2258,8 @@ use :code:`{sup.index}`. All data available is:
:code:`tab.progress_percent`
If a command running in a window reports the progress for a task, show this progress as a percentage
from all windows in the tab, averaged. Empty string is no progress is reported.
:code:`tab.children_mem_usage`
The current memory usage of all child process of the tab and their descendants
:code:`custom`
This will call a function named :code:`draw_title(data)` from the file :file:`tab_bar.py` placed in
the kitty config directory. The function will be passed a dictionary of data, the same data that

View file

@ -285,6 +285,20 @@ class TabAccessor:
p = int(tab.total_progress / tab.num_of_windows_with_progress)
return f'{p}% '
@property
def children_mem_usage(self) -> str:
from kittens.tui.utils import human_size
tab = get_boss().tab_for_id(self.tab_id)
if not tab:
return ''
ans = 0
for w in tab:
if (m := w.child.get_memory_used_by_child()) > 0:
ans += m
return human_size(ans, max_num_of_decimals=0)
safe_builtins = {
'max': max,