datapilot-cli
Version:
Enterprise-grade streaming multi-format data analysis with comprehensive statistical insights and intelligent relationship detection - supports CSV, JSON, Excel, TSV, Parquet - memory-efficient, cross-platform
159 lines • 4.14 kB
TypeScript
/**
* Memory management and cleanup utilities for DataPilot
*/
import { EventEmitter } from 'events';
import { DataPilotError } from '../core/types';
import type { LogContext } from './logger';
export interface MemoryStats {
heapUsed: number;
heapTotal: number;
external: number;
rss: number;
arrayBuffers: number;
}
export interface MemoryThresholds {
warningMB: number;
criticalMB: number;
maxMB: number;
}
export interface MemoryManagerConfig {
thresholds: MemoryThresholds;
monitoringInterval: number;
enableAutomaticCleanup: boolean;
enableGarbageCollection: boolean;
logMemoryUsage: boolean;
}
export declare class MemoryManager extends EventEmitter {
private config;
private monitoringTimer?;
private cleanupCallbacks;
private isMonitoring;
private lastMemoryStats?;
private memoryHistory;
private maxHistorySize;
constructor(config?: Partial<MemoryManagerConfig>);
/**
* Start memory monitoring
*/
startMonitoring(context?: LogContext): void;
/**
* Stop memory monitoring
*/
stopMonitoring(context?: LogContext): void;
/**
* Check current memory usage and emit events if thresholds are exceeded
*/
checkMemoryUsage(context?: LogContext): MemoryStats;
/**
* Register cleanup callback
*/
registerCleanupCallback(callback: () => void): void;
/**
* Force garbage collection if available
*/
forceGarbageCollection(context?: LogContext): void;
/**
* Run cleanup callbacks
*/
runCleanup(context?: LogContext): void;
/**
* Get memory statistics
*/
getMemoryStats(): {
current: MemoryStats | undefined;
peak: MemoryStats | undefined;
average: MemoryStats | undefined;
history: MemoryStats[];
};
/**
* Get memory growth rate
*/
getMemoryGrowthRate(): number | undefined;
/**
* Predict memory exhaustion time
*/
predictMemoryExhaustion(): Date | undefined;
/**
* Create memory error based on current usage
*/
createMemoryError(context?: LogContext): DataPilotError;
/**
* Cleanup and dispose
*/
dispose(): void;
private handleMemoryWarning;
private handleMemoryCritical;
private handleMemoryMax;
}
export declare const globalMemoryManager: MemoryManager;
/**
* Resource cleanup utilities
*/
export declare class ResourceManager {
private resources;
private disposed;
/**
* Register a resource for cleanup
*/
register(id: string, cleanup: () => void, type?: string): void;
/**
* Unregister a resource
*/
unregister(id: string): boolean;
/**
* Clean up a specific resource
*/
cleanup(id: string, context?: LogContext): boolean;
/**
* Clean up all resources of a specific type
*/
cleanupByType(type: string, context?: LogContext): number;
/**
* Clean up all resources
*/
cleanupAll(context?: LogContext): number;
/**
* Get resource count by type
*/
getResourceCount(type?: string): number;
/**
* List all resources
*/
listResources(): Array<{
id: string;
type: string;
}>;
/**
* Dispose of the resource manager
*/
dispose(context?: LogContext): void;
/**
* Check if disposed
*/
isDisposed(): boolean;
}
export declare const globalResourceManager: ResourceManager;
/**
* Process cleanup handler
*/
export declare class ProcessCleanupHandler {
private static instance?;
private handlers;
private isShuttingDown;
private constructor();
static getInstance(): ProcessCleanupHandler;
/**
* Register cleanup handler
*/
register(handler: () => void | Promise<void>): void;
/**
* Run all cleanup handlers
*/
runCleanup(): Promise<void>;
private handleExit;
private handleSignal;
private handleUncaughtException;
private handleUnhandledRejection;
}
export declare const globalCleanupHandler: ProcessCleanupHandler;
//# sourceMappingURL=memory-manager.d.ts.map