Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(editor): expose the profiler on EditorControlSurface

esengine92c84b9b7c80
diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.ts
index f18a8eb5a..4e30a38ca 100644
--- a/desktop/src/engine/EditorControlSurface.ts
+++ b/desktop/src/engine/EditorControlSurface.ts
@@ -26,6 +26,7 @@ import type {
import type { SceneData, SubsystemStatus } from 'esengine';
import { Material, Sprite } from 'esengine';
import { EngineHost } from './EngineHost';
+import { PerfMonitor, type PerfSnapshot, type FrameSample } from './PerfMonitor';
import type { SceneCommandsImpl, EditorTransaction } from './SceneCommands';
import type { SceneQueryImpl } from './SceneQuery';
import type { SceneModelImpl } from './SceneModel';
@@ -311,6 +312,21 @@ export class EditorControlSurfaceImpl {
};
}
+ /** The current profiler snapshot: frame timing, stat-unit segments, per-system
+ * timings, counters, memory, and GPU — the full per-frame telemetry. */
+ getFrameStats(): PerfSnapshot {
+ return PerfMonitor.getSnapshot();
+ }
+ /** Subscribe to profiler snapshot changes. Returns an unsubscribe. */
+ subscribeFrameStats(fn: () => void): () => void {
+ return PerfMonitor.subscribe(fn);
+ }
+ /** A captured frame's full breakdown by id (phases, cpp/gpu scopes, long tasks),
+ * or null if it scrolled out of the ring. */
+ getFrameSample(id: number): FrameSample | null {
+ return PerfMonitor.getSample(id);
+ }
+
/**
* The lifecycle + liveness of every engine subsystem (physics, audio, …) in
* this realm's engine — the "what's loaded and actually running" surface.