scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
182 lines (181 loc) • 6.41 kB
TypeScript
/**
* WasmMemoryDebugHelper - TypeScript interface for WASM memory tracking
*
* This helper provides access to memory tracking data stored in window.__sciChartMemoryTracking
* by the C++ memory override system. It allows toggling tracking flags and retrieving/logging
* memory statistics.
*/
/**
* Memory tracking record structure
*/
interface MemoryRecord {
guid: number;
ptr: number;
size: number;
timestamp: number;
stackTraceJS: string | null;
deallocated: boolean;
deallocationTimestamp: number | null;
}
/**
* Memory statistics structure
*/
interface MemoryStats {
totalAllocations: number;
totalDeallocations: number;
currentAllocatedBytes: number;
peakAllocatedBytes: number;
}
/**
* Memory tracking data structure stored on window object
*/
interface SciChartMemoryTracking {
records: Map<number, MemoryRecord>;
allRecords: Map<number, MemoryRecord>;
mallocTimestamp: number;
mallocNextGuid: number;
newRecords: Map<number, MemoryRecord>;
allNewRecords: Map<number, MemoryRecord>;
newDeleteTimestamp: number;
newDeleteNextGuid: number;
stackTraceEnabled: boolean;
mallocTrackingEnabled: boolean;
newDeleteTrackingEnabled: boolean;
}
/**
* WasmMemoryDebugHelper class - provides TypeScript interface to memory tracking
* @ignore This is supposed to be available only during development in Debug Wasm build mode
*/
export declare class WasmMemoryDebugHelper {
/**
* Get the memory tracking object from window, or undefined if not initialized
* @returns The memory tracking object with proper typing, or undefined
*/
private static getTracking;
/**
* Get the window object with memory tracking property
* @returns The window object (use getTracking() for typed access to memory tracking data)
*/
static getWindow(): Window & {
__sciChartMemoryTracking?: SciChartMemoryTracking;
};
/**
* Check if memory tracking is initialized
*/
static isInitialized(): boolean;
/**
* Initialize memory tracking storage on the JavaScript side
* This mirrors the C++ init_memory_tracking_storage function
* Note: The C++ code automatically initializes this, but this method
* can be called explicitly if needed for testing or manual initialization
*/
static initializeTracking(): void;
/**
* Enable or disable stack trace capture for allocations
*/
static setStackTraceEnabled(enabled: boolean): void;
/**
* Get current stack trace enabled state
*/
static getStackTraceEnabled(): boolean;
/**
* Enable or disable malloc/free tracking
*/
static setMallocTrackingEnabled(enabled: boolean): void;
/**
* Get current malloc tracking enabled state
*/
static getMallocTrackingEnabled(): boolean;
/**
* Enable or disable new/delete tracking
*/
static setNewDeleteTrackingEnabled(enabled: boolean): void;
/**
* Get current new/delete tracking enabled state
*/
static getNewDeleteTrackingEnabled(): boolean;
/**
* Calculate statistics from a Map of memory records
* @param map The Map to calculate stats from
* @returns Statistics object with counts and byte totals
*/
private static calculateStatsFromMap;
/**
* Reset malloc/free batch tracking - clears current batch records only
* Preserves: allRecords Map (historical data)
*/
static resetMallocBatch(): void;
/**
* Reset new/delete batch tracking - clears current batch records only
* Preserves: allNewRecords Map (historical data)
*/
static resetNewDeleteBatch(): void;
/**
* Reset malloc/free historical data - clears historical records only
* Clears: allRecords Map (historical)
* Preserves: records Map (batch), timeline counters
*/
static resetMallocHistorical(): void;
/**
* Reset new/delete historical data - clears historical records only
* Clears: allNewRecords Map (historical)
* Preserves: newRecords Map (batch), timeline counters
*/
static resetNewDeleteHistorical(): void;
/**
* Reset all historical data - clears both malloc/free and new/delete historical records
* Calls resetMallocHistorical() and resetNewDeleteHistorical()
*/
static resetAllHistorical(): void;
/**
* Reset everything - clears all batch and historical data for both malloc/free and new/delete
* Clears all Maps (batch and historical) while preserving timeline counters
* Calls all batch and historical reset methods
*/
static resetAll(): void;
/**
* Get malloc/free memory statistics (calculated from allRecords - historical)
*/
static getMallocStats(): MemoryStats;
/**
* Get current batch malloc/free records
*/
static getMallocRecords(): Map<number, MemoryRecord>;
/**
* Get all historical malloc/free records
*/
static getAllMallocRecords(): Map<number, MemoryRecord>;
/**
* Get new/delete memory statistics (calculated from allNewRecords - historical)
*/
static getNewDeleteStats(): MemoryStats;
/**
* Get current batch new/delete records
*/
static getNewDeleteRecords(): Map<number, MemoryRecord>;
/**
* Get all historical new/delete records
*/
static getAllNewDeleteRecords(): Map<number, MemoryRecord>;
/**
* Log current batch malloc/free allocations with detailed statistics
* Stats are calculated from the records Map (current batch)
*/
static logMallocBatch(): void;
/**
* Log all historical malloc/free allocations (does not reset)
* Stats are calculated from the allRecords Map (historical)
*/
static logAllMallocAllocations(): void;
/**
* Log current batch new/delete allocations with detailed statistics
* Stats are calculated from the newRecords Map (current batch)
*/
static logNewDeleteBatch(): void;
/**
* Log all historical new/delete allocations (does not reset)
* Stats are calculated from the allNewRecords Map (historical)
*/
static logAllNewDeleteAllocations(): void;
}
export {};