UNPKG

memoru

Version:

A hash-based LRU cache that evicts entries based on memory usage rather than time or item count.

142 lines 3.69 kB
import { EventEmitter } from 'events'; /** * Enum of garbage collection kinds for monitoring. * @public */ export declare enum GCKind { Minor = "minor", Major = "major", Incremental = "incremental", WeakCallback = "weak_callback" } /** * Enum of V8 heap space names for memory monitoring. * @public */ export declare enum HeapSpace { ReadOnly = "read_only_space", New = "new_space", Old = "old_space", Code = "code_space", Shared = "shared_space", Trusted = "trusted_space", NewLargeObject = "new_large_object_space", LargeObject = "large_object_space", CodeLargeObject = "code_large_object_space", SharedLargeObject = "shared_large_object_space", TrustedLargeObject = "trusted_large_object_space" } /** * Enum of process memory stats for monitoring. * @public */ export declare enum ProcessMemoryStat { RSS = "rss", HeapUsed = "heapUsed" } /** * Union of all supported memory stat types. * @public */ export type MemoryStat = HeapSpace | ProcessMemoryStat; /** * Configuration for a single monitored memory stat and its threshold. * @public */ export interface MonitoredStat { /** * The memory stat to monitor. */ stat: MemoryStat; /** * The threshold value in bytes to trigger an event. */ threshold: number; } /** * Options for configuring the memory stats monitor. * @public */ export interface MemoryStatsMonitorOptions { /** * Monitoring interval in milliseconds. * @defaultValue 1000 */ interval?: number; /** * List of memory stats and thresholds to monitor. */ monitored: MonitoredStat[]; /** * Enable garbage collection monitoring to prevent rotations during GC. * @defaultValue false */ monitorGC?: boolean; /** * Types of garbage collection events to monitor. * @defaultValue All GC kinds if monitorGC is true */ gcKinds?: GCKind[]; /** * Time in milliseconds to wait after a GC event before allowing rotations. * @defaultValue 500 */ gcCooldown?: number; } /** * Periodically monitors V8 and process memory stats, emitting events when thresholds are reached. * @public */ export declare class MemoryStatsMonitor extends EventEmitter { private intervalId?; private options; private gcObserver?; private isGCInProgress; private lastGCTime; /** * Create a new MemoryStatsMonitor. * @param options - Configuration for what to monitor and thresholds * @public */ constructor(options: MemoryStatsMonitorOptions); /** * Set up garbage collection event monitoring. * @internal */ private setupGCMonitoring; /** * Map Node.js GC kinds to our enum values. * @param kind - The GC kind number as reported by PerformanceObserver * @internal */ private mapGCKind; /** * Check if garbage collection is currently in progress. * @returns true if GC is in progress, false otherwise * @public */ isGCActive(): boolean; /** * Get the time elapsed since the last GC event in milliseconds. * @returns Number of milliseconds since last GC, or Infinity if no GC has occurred * @public */ timeSinceLastGC(): number; /** * Start the periodic monitoring loop. * @internal */ private start; /** * Stop the monitoring loop. * @public */ stop(): void; /** * Check if the monitor is currently active. * @returns true if monitoring is active, false otherwise * @public */ isMonitoring(): boolean; } //# sourceMappingURL=memory-stats.d.ts.map