From cde72f37108b84e9c56fc6ec220c917970da3e8b Mon Sep 17 00:00:00 2001 From: Qubasa Date: Mon, 4 Mar 2024 16:00:04 +0700 Subject: [PATCH] clan_vm_manager: Add CUMTIME to profiler output --- pkgs/clan-vm-manager/clan_vm_manager/__init__.py | 2 ++ .../clan_vm_manager/components/profiler.py | 8 +++++--- .../clan-vm-manager/clan_vm_manager/singletons/use_vms.py | 2 -- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-vm-manager/clan_vm_manager/__init__.py b/pkgs/clan-vm-manager/clan_vm_manager/__init__.py index 17fcd5d4..2fce92cc 100644 --- a/pkgs/clan-vm-manager/clan_vm_manager/__init__.py +++ b/pkgs/clan-vm-manager/clan_vm_manager/__init__.py @@ -2,10 +2,12 @@ import logging import sys from clan_vm_manager.app import MainApplication +from clan_vm_manager.components.profiler import profile log = logging.getLogger(__name__) +@profile def main() -> int: app = MainApplication() return app.run(sys.argv) diff --git a/pkgs/clan-vm-manager/clan_vm_manager/components/profiler.py b/pkgs/clan-vm-manager/clan_vm_manager/components/profiler.py index 05c022d5..597a6993 100644 --- a/pkgs/clan-vm-manager/clan_vm_manager/components/profiler.py +++ b/pkgs/clan-vm-manager/clan_vm_manager/components/profiler.py @@ -30,10 +30,10 @@ cProfile Output Columns Explanation: """ -def print_profile(profiler: cProfile.Profile) -> None: +def print_profile(profiler: cProfile.Profile, sortkey: pstats.SortKey) -> None: s = io.StringIO() ps = pstats.Stats(profiler, stream=s) - ps.sort_stats(pstats.SortKey.CUMULATIVE) + ps.sort_stats(sortkey) ps.print_stats(12) # Process the output to trim file paths @@ -60,6 +60,7 @@ def print_profile(profiler: cProfile.Profile) -> None: print(new_line) +# TODO: Add an RLock for every profiler, currently not thread safe class ProfilerStore: profilers: dict[str, cProfile.Profile] @@ -76,7 +77,8 @@ class ProfilerStore: def on_exit(self) -> None: for key, profiler in self.profilers.items(): print("=" * 7 + key + "=" * 7) - print_profile(profiler) + print_profile(profiler, pstats.SortKey.TIME) + print_profile(profiler, pstats.SortKey.CUMULATIVE) print(explanation) diff --git a/pkgs/clan-vm-manager/clan_vm_manager/singletons/use_vms.py b/pkgs/clan-vm-manager/clan_vm_manager/singletons/use_vms.py index 1ffcd73c..c76ebdf7 100644 --- a/pkgs/clan-vm-manager/clan_vm_manager/singletons/use_vms.py +++ b/pkgs/clan-vm-manager/clan_vm_manager/singletons/use_vms.py @@ -7,7 +7,6 @@ from clan_cli.history.add import HistoryEntry from clan_vm_manager import assets from clan_vm_manager.components.gkvstore import GKVStore -from clan_vm_manager.components.profiler import profile from clan_vm_manager.components.vmobj import VMObject gi.require_version("GObject", "2.0") @@ -48,7 +47,6 @@ class ClanStore: self.push_history_entry(vm) return GLib.SOURCE_REMOVE - @profile def push_history_entry(self, entry: HistoryEntry) -> None: # TODO: We shouldn't do this here but in the list view if entry.flake.icon is None: