From 5306056d93f180cc85e72d0e769004ee9a5886a5 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Tue, 10 Sep 2024 11:29:16 -0300 Subject: [PATCH] webrtc: Warn about changes in stats that should not change --- src/stores/omniscientLogger.ts | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/stores/omniscientLogger.ts b/src/stores/omniscientLogger.ts index 25747e0ac..1304c7d43 100644 --- a/src/stores/omniscientLogger.ts +++ b/src/stores/omniscientLogger.ts @@ -151,6 +151,18 @@ export const useOmniscientLoggerStore = defineStore('omniscient-logger', () => { 'totalFreezesDuration', 'totalPausesDuration', ] // Keys that should not increase + const averageKeysThatShouldNotDecrease: WebRTCVideoStat[] = [ + 'clockRate', + 'framesAssembledFromMultiplePackets', + 'framesPerSecond', + 'packetRate', + ] // Keys that should not decrease + const averageKeysThatShouldNotIncrease: WebRTCVideoStat[] = [ + 'jitter', + 'jitterBufferDelay', + 'jitterBufferMinimumDelay', + 'jitterBufferTargetDelay', + ] // Keys that should not increase const webrtcStatsAverageLogDelay = 10000 let lastWebrtcStatsAverageLog = new Date() @@ -191,6 +203,29 @@ export const useOmniscientLoggerStore = defineStore('omniscient-logger', () => { } }) + // Warn about changes in average values that should not change + averageKeys.forEach((key) => { + const keyArray = webRtcStatsHistory.value[ev.peerId][key] + if (keyArray.length < historyLength) return + + const average = (keyArray as number[]).reduce((a, b) => a + b, 0) / keyArray.length + const currentValue = keyArray[keyArray.length - 1] as number + + if (averageKeysThatShouldNotDecrease.includes(key)) { + const minThreshold = 0.9 * average + if (currentValue < minThreshold) { + console.debug(`Drop in the value of key '${key}' for peer '${ev.peerId}': ${currentValue.toFixed(2)}.`) + } + } + + if (averageKeysThatShouldNotIncrease.includes(key)) { + const minThreshold = 1.1 * average + if (currentValue > minThreshold) { + console.debug(`Increase in the value of key '${key}' for peer '${ev.peerId}': ${currentValue.toFixed(2)}.`) + } + } + }) + // Log the average values recursively if (new Date().getTime() - lastWebrtcStatsAverageLog.getTime() > webrtcStatsAverageLogDelay) { averageKeys.forEach((key) => {