diff --git a/docs/changelog.rst b/docs/changelog.rst index a9904c124..8904028c4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -195,6 +195,8 @@ Detailed list of changes - Add support for `terminal 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] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/child.py b/kitty/child.py index 16a0599b1..560a60040 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -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) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 8dd811768..3ef839681 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -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 diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 8b3c1cd36..6e71166a3 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -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,