traceperf
Version:
High-performance function execution tracking and monitoring for Node.js
102 lines (101 loc) • 2.85 kB
TypeScript
import { IExecutionTracker, ITrackOptions } from '../types';
/**
* A record of a function execution
*/
export interface ExecutionRecord {
name: string;
duration: number;
startTime: [number, number];
endTime?: [number, number];
isSlow: boolean;
level: number;
memoryUsage?: number;
memoryReleased?: number;
children: ExecutionRecord[];
parent?: ExecutionRecord;
}
/**
* Execution tracker for performance monitoring
*/
export declare class ExecutionTracker implements IExecutionTracker {
private _executions;
private _currentExecution;
private _defaultThreshold;
private _callStack;
private _globalScope;
private _trackedFunctions;
/**
* Constructor
*
* @param options - Options for execution tracking
*/
constructor(options?: {
defaultThreshold?: number;
});
/**
* Track the execution of a function
*
* @param fn - The function to track
* @param options - Options for tracking
* @returns The return value of the tracked function
*/
track<T>(fn: () => T, options?: ITrackOptions): T;
/**
* Create a trackable version of a function
*
* This is a helper method to create a tracked version of a function
* that can be used for nested function tracking.
*
* @param fn - The function to make trackable
* @param options - Options for tracking
* @returns A tracked version of the function
*/
createTrackable<T extends (...args: any[]) => any>(fn: T, options?: Omit<ITrackOptions, 'label'> & {
label?: string;
}): (...args: Parameters<T>) => ReturnType<T>;
/**
* Get all execution records
*
* @returns A list of execution records
*/
getExecutions(): ExecutionRecord[];
/**
* Generate a human-friendly memory size string
*
* @param bytes - The size in bytes
* @returns A formatted string
*/
formatMemorySize(bytes: number): string;
/**
* Get the current call stack
*
* @returns The current call stack
*/
getCallStack(): string[];
/**
* Generate a visual representation of the execution flow
*
* @returns ASCII flow chart of the execution
*/
generateFlowChart(): string;
/**
* Recursively print an execution tree
*
* @param execution - The root execution
* @param result - The output string
* @returns The updated result string
*/
private printExecutionTree;
/**
* Print a single execution with appropriate formatting
*
* @param execution - The execution to print
* @param result - The result string to append to
* @returns The updated result string
*/
private printSingleExecution;
/**
* Clear all execution records
*/
clear(): void;
}