UNPKG

traceperf

Version:

High-performance function execution tracking and monitoring for Node.js

69 lines (68 loc) 2.07 kB
import { IPerformanceMonitor } from '../types'; /** * Performance monitor for tracking execution times and memory usage */ export declare class PerformanceMonitor implements IPerformanceMonitor { private _timers; private _defaultThreshold; /** * Create a new PerformanceMonitor instance * * @param options - Monitor options */ constructor(options?: { defaultThreshold?: number; }); /** * Start timing an operation * * @param label - Label for the operation * @returns A unique identifier for the timing operation */ startTimer(label: string): string; /** * End timing an operation * * @param id - The identifier returned by startTimer * @returns The duration in milliseconds * @throws Error if the timer doesn't exist */ endTimer(id: string): number; /** * Check if an operation exceeds the performance threshold * * @param duration - The duration in milliseconds * @param threshold - The threshold to check against * @returns Whether the operation is considered slow */ isBottleneck(duration: number, threshold?: number): boolean; /** * Get memory usage information * * @returns Memory usage object */ getMemoryUsage(): { heapUsed: number; heapTotal: number; external: number; rss: number; } | undefined; /** * Calculate memory difference between current and start memory * * @param start - Starting memory usage snapshot * @returns Memory difference or undefined */ getMemoryDiff(start: { heapUsed: number; }): number; /** * Generate a suggestion for a bottleneck * * @param functionName - The name of the function * @param duration - The duration in milliseconds * @param memoryUsage - Memory usage in bytes * @returns A suggestion for improving performance */ generateSuggestion(functionName: string, duration: number, memoryUsage?: number): string; }