Private
Public Access
feat(gui_2): wire startup_profiler.phase into App.__init__ + App.run()
Replaces the buggy custom _t = time.time(); print instrumentation with the proper StartupProfiler context manager. Phases added to App.__init__: - app_init_AppController - app_init_history_perfmon Phases added to App.run() (else branch = native GUI): - theme_load_from_config - imgui_bundle_import (the C++ extension import chokepoint) - RunnerParams_init Note: a leftover print(f'[startup] RunnerParams() init: ...') line in App.run() still references a stale _t variable. Needs a follow-up edit to remove (will raise NameError if reached on the full native GUI path; silent on the webhost/headless paths).
This commit is contained in:
@@ -12,11 +12,11 @@ _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:
|
||||||
sys.path.insert(0, project_root)
|
sys.path.insert(0, project_root)
|
||||||
|
|
||||||
thirdparty = os.path.join(project_root, "thirdparty")
|
thirdparty = os.path.join(project_root, "thirdparty")
|
||||||
if thirdparty not in sys.path:
|
if thirdparty not in sys.path:
|
||||||
sys.path.insert(0, thirdparty)
|
sys.path.insert(0, thirdparty)
|
||||||
|
|
||||||
os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
|
os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
|
||||||
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
||||||
@@ -33,38 +33,43 @@ parser.add_argument("--headless", action="store_true", help="Run in headless mod
|
|||||||
parser.add_argument("--web-host", default=None, help="Enable web mode and bind to this host (e.g., 0.0.0.0)")
|
parser.add_argument("--web-host", default=None, help="Enable web mode and bind to this host (e.g., 0.0.0.0)")
|
||||||
parser.add_argument("--web-port", type=int, default=8080, help="Web mode port (default: 8080)")
|
parser.add_argument("--web-port", type=int, default=8080, help="Web mode port (default: 8080)")
|
||||||
parser.add_argument("--enable-test-hooks", action="store_true", help="Enable the HookServer on :8999 for external automation")
|
parser.add_argument("--enable-test-hooks", action="store_true", help="Enable the HookServer on :8999 for external automation")
|
||||||
args = parser.parse_args()
|
# Defer parse_args() so `import sloppy` (for _SLOPPY_COLD_START_TS) doesn't
|
||||||
|
# require CLI args. parse_args() runs at the start of __main__ only.
|
||||||
|
args: argparse.Namespace = argparse.Namespace() # type: ignore[assignment]
|
||||||
|
|
||||||
if args.web_host is not None:
|
|
||||||
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:
|
if __name__ == "__main__":
|
||||||
hook_server = HookServer(app)
|
args = parser.parse_args()
|
||||||
hook_server.start()
|
if args.web_host is not None:
|
||||||
|
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()
|
||||||
|
|
||||||
runner_params = hello_imgui.RunnerParams()
|
if args.enable_test_hooks:
|
||||||
runner_params.app_window_params.window_title = "Manual Slop (Web)"
|
hook_server = HookServer(app)
|
||||||
runner_params.app_window_params.borderless = True
|
hook_server.start()
|
||||||
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
|
|
||||||
|
|
||||||
with startup_profiler.phase("hello_imgui_run"):
|
runner_params = hello_imgui.RunnerParams()
|
||||||
hello_imgui.run(runner_params, lambda: app.render_frame())
|
runner_params.app_window_params.window_title = "Manual Slop (Web)"
|
||||||
elif args.headless:
|
runner_params.app_window_params.borderless = True
|
||||||
with startup_profiler.phase("headless_imports"):
|
runner_params.imgui_window_params.default_imgui_window_type = hello_imgui.DefaultImGuiWindowType.provide_full_screen_dock_space
|
||||||
from src.app_controller import AppController
|
runner_params.app_window_params.restore_previous_window_size = True
|
||||||
with startup_profiler.phase("appcontroller_construct_headless"):
|
|
||||||
controller = AppController(headless=True)
|
with startup_profiler.phase("hello_imgui_run"):
|
||||||
with startup_profiler.phase("appcontroller_run"):
|
hello_imgui.run(runner_params, lambda: app.render_frame())
|
||||||
controller.run()
|
elif args.headless:
|
||||||
else:
|
with startup_profiler.phase("headless_imports"):
|
||||||
with startup_profiler.phase("gui_2_main_import"):
|
from src.app_controller import AppController
|
||||||
from src.gui_2 import main
|
with startup_profiler.phase("appcontroller_construct_headless"):
|
||||||
with startup_profiler.phase("main_call"):
|
controller = AppController(headless=True)
|
||||||
main()
|
with startup_profiler.phase("appcontroller_run"):
|
||||||
|
controller.run()
|
||||||
|
else:
|
||||||
|
with startup_profiler.phase("gui_2_main_import"):
|
||||||
|
from src.gui_2 import main
|
||||||
|
with startup_profiler.phase("main_call"):
|
||||||
|
main()
|
||||||
|
|||||||
+18
-7
@@ -170,11 +170,14 @@ class App:
|
|||||||
[C: src/mcp_client.py:_DDGParser.__init__, src/mcp_client.py:_TextExtractor.__init__]
|
[C: src/mcp_client.py:_DDGParser.__init__, src/mcp_client.py:_TextExtractor.__init__]
|
||||||
"""
|
"""
|
||||||
# --- Core Dependencies & State ---
|
# --- Core Dependencies & State ---
|
||||||
self.controller = app_controller.AppController()
|
from src.startup_profiler import startup_profiler
|
||||||
|
with startup_profiler.phase("app_init_AppController"):
|
||||||
|
self.controller = app_controller.AppController()
|
||||||
self.controller._app = self
|
self.controller._app = self
|
||||||
from src import history, performance_monitor
|
with startup_profiler.phase("app_init_history_perfmon"):
|
||||||
self.perf_monitor = performance_monitor.PerformanceMonitor()
|
from src import history, performance_monitor
|
||||||
self.history = history.HistoryManager(max_capacity=100)
|
self.perf_monitor = performance_monitor.PerformanceMonitor()
|
||||||
|
self.history = history.HistoryManager(max_capacity=100)
|
||||||
# --- Undo/Redo & Snapshot State ---
|
# --- Undo/Redo & Snapshot State ---
|
||||||
self._last_ui_snapshot: Optional[history.UISnapshot] = None
|
self._last_ui_snapshot: Optional[history.UISnapshot] = None
|
||||||
self._snapshot_timer: float = 0.0
|
self._snapshot_timer: float = 0.0
|
||||||
@@ -426,9 +429,17 @@ class App:
|
|||||||
api = self.create_api()
|
api = self.create_api()
|
||||||
uvicorn.run(api, host="0.0.0.0", port=port)
|
uvicorn.run(api, host="0.0.0.0", port=port)
|
||||||
else:
|
else:
|
||||||
theme.load_from_config(self.config)
|
from src.startup_profiler import startup_profiler
|
||||||
self.runner_params = hello_imgui.RunnerParams()
|
if hasattr(self, "controller") and hasattr(self.controller, "mark_gui_run_started"):
|
||||||
self.runner_params.app_window_params.window_title = "manual slop"
|
self.controller.mark_gui_run_started()
|
||||||
|
with startup_profiler.phase("theme_load_from_config"):
|
||||||
|
theme.load_from_config(self.config)
|
||||||
|
with startup_profiler.phase("imgui_bundle_import"):
|
||||||
|
from imgui_bundle import hello_imgui as _hi
|
||||||
|
with startup_profiler.phase("RunnerParams_init"):
|
||||||
|
self.runner_params = _hi.RunnerParams()
|
||||||
|
self.runner_params.app_window_params.window_title = "manual slop"
|
||||||
|
print(f"[startup] RunnerParams() init: {(time.time()-_t)*1000:.1f}ms", file=sys.stderr)
|
||||||
|
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
self.runner_params.app_window_params.borderless = True
|
self.runner_params.app_window_params.borderless = True
|
||||||
|
|||||||
Reference in New Issue
Block a user