UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

38 lines (37 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PerformanceMonitor = void 0; class PerformanceMonitor { log; thresholdMs; constructor(log, thresholdMs) { this.log = log; this.thresholdMs = thresholdMs; } check(elapsedMs, meta) { if (elapsedMs >= this.thresholdMs) { this.log.warn(`[SLOW WARNING] ${this.inferMethodName()} took ${this.getElapsedStr(elapsedMs)}`, meta); } } inferMethodName() { try { return (new Error().stack ?.split('\n') .at(3) ?.trimStart() .replace('at ', '') ?.match(/(.+)\s/) ?.at(0) ?.trimEnd() ?? '<unknown>'); // eslint-disable-next-line @typescript-eslint/no-unused-vars } catch (e) { // Fallback if stack parsing fails } return '<unknown>'; } getElapsedStr(elapsedMs) { return elapsedMs > 1 ? `${Math.round(elapsedMs)}ms` : `${elapsedMs.toFixed(3)}ms`; } } exports.PerformanceMonitor = PerformanceMonitor;