UNPKG

@vtex/api

Version:
27 lines (26 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventLoopLagMeasurer = void 0; const perf_hooks_1 = require("perf_hooks"); const utils_1 = require("../../../../utils"); const instruments_1 = require("../instruments"); class EventLoopLagMeasurer { constructor() { this.eventLoopDelayMonitor = (0, perf_hooks_1.monitorEventLoopDelay)({ resolution: 10 }); this.percentilesInstrument = (0, instruments_1.createEventLoopLagPercentilesInstrument)(); this.maxInstrument = (0, instruments_1.createEventLoopLagMaxInstrument)(); } start() { this.eventLoopDelayMonitor.enable(); } async updateInstrumentsAndReset() { this.maxInstrument.set((0, utils_1.nanosecondsToSeconds)(this.eventLoopDelayMonitor.max)); this.setPercentileObservation(95); this.setPercentileObservation(99); this.eventLoopDelayMonitor.reset(); } setPercentileObservation(percentile) { this.percentilesInstrument.set({ ["percentile" /* EventLoopMetricLabels.PERCENTILE */]: percentile }, (0, utils_1.nanosecondsToSeconds)(this.eventLoopDelayMonitor.percentile(percentile))); } } exports.EventLoopLagMeasurer = EventLoopLagMeasurer;