diff --git a/sloppy.py b/sloppy.py index 33497a06..ee725162 100644 --- a/sloppy.py +++ b/sloppy.py @@ -1,6 +1,14 @@ import argparse import sys import os +import time + +# Cold-start anchor: capture wall-clock as the very first executable +# statement in the entry point. The AppController's startup_timeline() +# reads this from a module-global so the gap between "Python started" +# and "AppController init began" is visible (this is typically the +# largest startup phase: module imports). +_SLOPPY_COLD_START_TS: float = time.time() project_root = os.path.dirname(os.path.abspath(__file__)) if project_root not in sys.path: @@ -14,8 +22,11 @@ os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1" os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1" os.environ["TOKENIZERS_PARALLELISM"] = "false" -from defer.sugar import install as _install_defer -_install_defer() +from src.startup_profiler import startup_profiler + +with startup_profiler.phase("defer_sugar"): + from defer.sugar import install as _install_defer + _install_defer() parser = argparse.ArgumentParser(description="Manual Slop entry point") parser.add_argument("--headless", action="store_true", help="Run in headless mode without GUI") @@ -25,11 +36,13 @@ parser.add_argument("--enable-test-hooks", action="store_true", help="Enable the args = parser.parse_args() if args.web_host is not None: - from imgui_bundle import hello_imgui - from src.api_hooks import HookServer - - from src.gui_2 import App - app = App() + with startup_profiler.phase("web_host_imports"): + from imgui_bundle import hello_imgui + from src.api_hooks import HookServer + with startup_profiler.phase("gui_2_import_webhost"): + from src.gui_2 import App + with startup_profiler.phase("app_construct"): + app = App() if args.enable_test_hooks: hook_server = HookServer(app) @@ -41,11 +54,17 @@ if args.web_host is not None: runner_params.imgui_window_params.default_imgui_window_type = hello_imgui.DefaultImGuiWindowType.provide_full_screen_docker_space runner_params.app_window_params.restore_previous_window_size = True - hello_imgui.run(runner_params, lambda: app.render_frame()) + with startup_profiler.phase("hello_imgui_run"): + hello_imgui.run(runner_params, lambda: app.render_frame()) elif args.headless: - from src.app_controller import AppController - controller = AppController(headless=True) - controller.run() + with startup_profiler.phase("headless_imports"): + from src.app_controller import AppController + with startup_profiler.phase("appcontroller_construct_headless"): + controller = AppController(headless=True) + with startup_profiler.phase("appcontroller_run"): + controller.run() else: - from src.gui_2 import main - main() \ No newline at end of file + with startup_profiler.phase("gui_2_main_import"): + from src.gui_2 import main + with startup_profiler.phase("main_call"): + main() \ No newline at end of file