Private
Public Access
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 argparse
|
||||||
import sys
|
import sys
|
||||||
import os
|
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__))
|
project_root = os.path.dirname(os.path.abspath(__file__))
|
||||||
if project_root not in sys.path:
|
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["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
||||||
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
||||||
|
|
||||||
from defer.sugar import install as _install_defer
|
from src.startup_profiler import startup_profiler
|
||||||
_install_defer()
|
|
||||||
|
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 = argparse.ArgumentParser(description="Manual Slop entry point")
|
||||||
parser.add_argument("--headless", action="store_true", help="Run in headless mode without GUI")
|
parser.add_argument("--headless", action="store_true", help="Run in headless mode without GUI")
|
||||||
@@ -25,10 +36,12 @@ parser.add_argument("--enable-test-hooks", action="store_true", help="Enable the
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.web_host is not None:
|
if args.web_host is not None:
|
||||||
|
with startup_profiler.phase("web_host_imports"):
|
||||||
from imgui_bundle import hello_imgui
|
from imgui_bundle import hello_imgui
|
||||||
from src.api_hooks import HookServer
|
from src.api_hooks import HookServer
|
||||||
|
with startup_profiler.phase("gui_2_import_webhost"):
|
||||||
from src.gui_2 import App
|
from src.gui_2 import App
|
||||||
|
with startup_profiler.phase("app_construct"):
|
||||||
app = App()
|
app = App()
|
||||||
|
|
||||||
if args.enable_test_hooks:
|
if args.enable_test_hooks:
|
||||||
@@ -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.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
|
runner_params.app_window_params.restore_previous_window_size = True
|
||||||
|
|
||||||
|
with startup_profiler.phase("hello_imgui_run"):
|
||||||
hello_imgui.run(runner_params, lambda: app.render_frame())
|
hello_imgui.run(runner_params, lambda: app.render_frame())
|
||||||
elif args.headless:
|
elif args.headless:
|
||||||
|
with startup_profiler.phase("headless_imports"):
|
||||||
from src.app_controller import AppController
|
from src.app_controller import AppController
|
||||||
|
with startup_profiler.phase("appcontroller_construct_headless"):
|
||||||
controller = AppController(headless=True)
|
controller = AppController(headless=True)
|
||||||
|
with startup_profiler.phase("appcontroller_run"):
|
||||||
controller.run()
|
controller.run()
|
||||||
else:
|
else:
|
||||||
|
with startup_profiler.phase("gui_2_main_import"):
|
||||||
from src.gui_2 import main
|
from src.gui_2 import main
|
||||||
|
with startup_profiler.phase("main_call"):
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user