feat(sloppy): instrument startup paths with startup_profiler.phase
Replaces ad-hoc print() timing with the proper StartupProfiler.phase() context manager. The phases cover the actual chokepoints the user wanted to measure (NOT src/* imports — those are benchmark_imports.py's job): - argv_parse: argparse setup - defer_sugar: defer.sugar install - web_host_imports: imgui_bundle + api_hooks - gui_2_import_webhost: from src.gui_2 import App - app_construct: App() instance creation - hello_imgui_run: the C++ imgui bundle init (the actual bottleneck) - headless_imports: from src.app_controller import AppController - appcontroller_construct_headless: AppController() + warmup submit - appcontroller_run: asyncio loop - gui_2_main_import: from src.gui_2 import main - main_call: the legacy main() entry Combined with the existing StartupProfiler singleton, every phase now emits [startup] <name>: <ms>ms to stderr in real time, so the user can grep for chokepoints in a real uv run.
This commit is contained in:
@@ -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()
|
||||
with startup_profiler.phase("gui_2_main_import"):
|
||||
from src.gui_2 import main
|
||||
with startup_profiler.phase("main_call"):
|
||||
main()
|
||||
Reference in New Issue
Block a user