UNPKG

taskflow-ai

Version:

TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具

101 lines (100 loc) 2.53 kB
/** * 性能监控系统 * 提供方法执行时间监控、内存使用监控和性能报告 */ import { PerformanceMetrics, PerformanceThresholds } from '../../types/strict-types'; /** * 性能监控管理器 */ export declare class PerformanceMonitor { private static instance; private metrics; private thresholds; private logger; private constructor(); static getInstance(): PerformanceMonitor; /** * 设置性能阈值 */ setThresholds(operation: string, thresholds: PerformanceThresholds): void; /** * 记录性能指标 */ recordMetrics(operation: string, metrics: PerformanceMetrics): void; /** * 检查性能阈值 */ private checkThresholds; /** * 获取操作的性能统计 */ getStats(operation: string): { avgExecutionTime: number; maxExecutionTime: number; minExecutionTime: number; avgMemoryUsage: number; avgCacheHitRate: number; avgErrorRate: number; totalCalls: number; } | null; /** * 生成性能报告 */ generateReport(): string; /** * 清除指定操作的性能数据 */ clearMetrics(operation?: string): void; } /** * 性能监控装饰器 */ export declare function performanceMonitor(operationName?: string): (target: Record<string, unknown>, propertyKey: string, descriptor?: PropertyDescriptor) => PropertyDescriptor; /** * 简单的内存缓存实现 */ export declare class MemoryCache<T> { private cache; private maxSize; private defaultTTL; private stats; constructor(maxSize?: number, defaultTTL?: number); /** * 设置缓存值 */ set(key: string, value: T, ttl?: number): void; /** * 获取缓存值 */ get(key: string): T | undefined; /** * 删除缓存值 */ delete(key: string): boolean; /** * 清空缓存 */ clear(): void; /** * 获取缓存统计 */ getStats(): { size: number; hitRate: number; missRate: number; evictionCount: number; totalRequests: number; }; /** * 删除最少使用的项 */ private evictLeastUsed; /** * 清理过期项 */ cleanup(): void; } /** * 缓存装饰器 */ export declare function cached(ttl?: number, keyGenerator?: (...args: unknown[]) => string): (target: Record<string, unknown>, propertyKey: string, descriptor?: PropertyDescriptor) => PropertyDescriptor;