39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { PerformanceTracker as StaticPerformanceTracker } from './performance.tracker.js';
|
|
|
|
/**
|
|
* Instance-based wrapper for PerformanceTracker to provide the API expected by tests
|
|
*/
|
|
export class PerformanceTracker {
|
|
constructor(private name: string) {}
|
|
|
|
/**
|
|
* Measure an async operation
|
|
*/
|
|
async measureAsync<T>(operation: string, fn: () => Promise<T>): Promise<T> {
|
|
const fullOperation = `${this.name} - ${operation}`;
|
|
const { result } = await StaticPerformanceTracker.track(fullOperation, fn);
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Measure a sync operation (convert to async)
|
|
*/
|
|
measure<T>(operation: string, fn: () => T): T {
|
|
const fullOperation = `${this.name} - ${operation}`;
|
|
const result = fn();
|
|
// Track sync operations as completed instantly
|
|
const startTime = performance.now();
|
|
const endTime = performance.now();
|
|
// We can't use the static tracker for sync operations directly,
|
|
// so we'll just return the result
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Get summary statistics for operations under this tracker
|
|
*/
|
|
async getSummary(operation?: string): Promise<any> {
|
|
const fullOperation = operation ? `${this.name} - ${operation}` : this.name;
|
|
return StaticPerformanceTracker.getSummary(fullOperation);
|
|
}
|
|
} |