import type { SceneOptions } from '../../Config'; /** * Monitors process memory usage (heapUsed) and determines whether the memory limit has been exceeded. * * Uses heapUsed (V8 heap used) as the memory metric for cache management. The configured RSS limit * ({@link SceneOptions.memoryLimitMB}) is converted to a heapUsed limit via {@link RSS_TO_HEAPUSED_RATIO}. * * Sampling is throttled: if the last sample was taken less than {@link THROTTLE_MS} * milliseconds ago, the cached result is reused to avoid excessive * `process.memoryUsage()` calls during rapid module loading. * * Configuration is read from {@link SceneOptions}: * - `memoryLimitMB`: max process memory (RSS) in MB; 0 or undefined disables monitoring. * Internally converted to a heapUsed limit: `heapUsedLimit = memoryLimitMB * 1024 * 1024 * RSS_TO_HEAPUSED_RATIO`. * * @category frontend/common */ export declare class MemoryMonitor { private readonly heapUsedLimitBytes; private lastSampleTime; private cachedUsage; /** Minimum interval between consecutive memory samples, in milliseconds. */ private static readonly THROTTLE_MS; /** * Ratio for converting an RSS-based memory limit to a heapUsed-based limit. * Calibrated from scene_board_ext BODIES-level run (no eviction, no GC): * P50 of heapUsed/RSS = 0.911, rounded down to 0.85 for extra safety margin * to reduce OOM risk when node --max-old-space-size is close to memoryLimitMB. */ private static readonly RSS_TO_HEAPUSED_RATIO; constructor(options?: SceneOptions); /** Whether memory monitoring is enabled (memoryLimitMB > 0). */ isEnabled(): boolean; /** Returns the heapUsed limit in bytes (converted from the RSS-based memoryLimitMB). */ getHeapUsedLimitBytes(): number; /** * Check whether the current heapUsed exceeds the memory limit. * * Sampling is throttled: calls within {@link THROTTLE_MS} of the last sample * return the cached result. */ isHeapUsedOverLimit(): boolean; /** * Check whether the current heapUsed exceeds the given target value. * * Sampling is throttled: calls within {@link THROTTLE_MS} of the last sample * return the cached result. */ isHeapUsedOverTarget(targetBytes: number): boolean; /** * Get the current heapUsed in bytes, bypassing the throttle for one-shot measurements. * * Unlike {@link isHeapUsedOverTarget} / {@link isHeapUsedOverLimit} (which use throttled sampling), * this method always calls `process.memoryUsage()` directly. It is intended for * one-shot measurements such as heapUsed recording before/after module loading and * real-time heapUsed checks during eviction (each unload/downgrade calls this to * decide whether more eviction is needed). */ getCurrentHeapUsed(): number; private getUsage; } //# sourceMappingURL=MemoryMonitor.d.ts.map