From df5de03fade99374c2cab86ca4325cf3f1d61cba Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Sun, 10 Nov 2024 19:44:25 -0300 Subject: [PATCH] wip --- src/stores/omniscientLogger.ts | 174 ++++++++++++++++----------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/src/stores/omniscientLogger.ts b/src/stores/omniscientLogger.ts index 399b5ea84..a123c9d44 100644 --- a/src/stores/omniscientLogger.ts +++ b/src/stores/omniscientLogger.ts @@ -12,93 +12,93 @@ export const webrtcStats = new WebRTCStats({ getStatsInterval: 250 }) export const useOmniscientLoggerStore = defineStore('omniscient-logger', () => { const videoStore = useVideoStore() - // Routine to log the framerate of the video streams - const streamsFrameRateHistory = ref<{ [key in string]: number[] }>({}) - let lastStreamAverageFramerateLog = new Date() - const streamAverageFramerateLogDelay = 10000 - setInterval(() => { - Object.keys(videoStore.activeStreams).forEach((streamName) => { - if (videoStore.activeStreams[streamName] === undefined) return - videoStore.activeStreams[streamName]!.mediaStream?.getVideoTracks().forEach((track) => { - if (streamsFrameRateHistory.value[streamName] === undefined) streamsFrameRateHistory.value[streamName] = [] - if (track.getSettings().frameRate === undefined) return - - const streamHistory = streamsFrameRateHistory.value[streamName] - streamHistory.push(track.getSettings().frameRate as number) - streamHistory.splice(0, streamHistory.length - 10) - streamsFrameRateHistory.value[streamName] = streamHistory - - const average = streamHistory.reduce((a, b) => a + b, 0) / streamHistory.length - const minThreshold = 0.9 * average - const newFrameRate = track.getSettings().frameRate as number - - // Warn about drops in the framerate of the video stream - if (newFrameRate < minThreshold) { - console.warn(`Drop in the framerate detected for stream '${streamName}': ${newFrameRate.toFixed(2)} fps.`) - } - - // Log the average framerate of the video stream recursively - if (new Date().getTime() - lastStreamAverageFramerateLog.getTime() > streamAverageFramerateLogDelay) { - console.debug(`Average frame rate for stream '${streamName}': ${average.toFixed(2)} fps.`) - lastStreamAverageFramerateLog = new Date() - } - }) - }) - }, 250) - - // Routine to log the framerate of the application rendering - const appFrameRateHistory = ref([]) - const appAverageFrameRateSampleDelay = 100 - const appAverageFrameRateLogDelay = 10000 - let lastAppAverageFpsLog = new Date() - - // Log tab visibility changes so we don't warn about framerate drops when the tab was not visible in the last seconds - const windowVisibility = useDocumentVisibility() - let timeLastTabOpening = new Date() - watch(windowVisibility, (newVisibility, oldVisibility) => { - if (newVisibility === 'visible' && oldVisibility === 'hidden') { - timeLastTabOpening = new Date() - } - }) - - const fpsMeter = (): void => { - let prevTime = performance.now() - let frames = 0 - - requestAnimationFrame(function loop() { - const time = performance.now() - frames++ - if (time > prevTime + appAverageFrameRateSampleDelay) { - const currentFPS = Math.round((frames * 1000) / (time - prevTime)) - prevTime = time - frames = 0 - - appFrameRateHistory.value.push(currentFPS) - appFrameRateHistory.value.splice(0, appFrameRateHistory.value.length - 10) - - const average = appFrameRateHistory.value.reduce((a, b) => a + b, 0) / appFrameRateHistory.value.length - - // Warn about drops in the framerate of the application rendering - // The threshold is set to 80% of the average framerate by default - // We don't warn if the framerate is above 60 because it's an already very high value, and we don't want to spam the console on high-end monitors - // We also don't warn if the tab was not visible in the last second, since the application was not being rendered - const minThreshold = Math.min(60, 0.8 * average) - const msSinceLastTabOpening = new Date().getTime() - timeLastTabOpening.getTime() - if (currentFPS < minThreshold && msSinceLastTabOpening > 1000) { - console.warn(`Drop in the framerate detected for the application rendering: ${currentFPS.toFixed(2)} fps.`) - } - - // Log the average framerate of the application rendering recursively - if (new Date().getTime() - lastAppAverageFpsLog.getTime() > appAverageFrameRateLogDelay) { - console.debug(`Average framerate for the application rendering: ${average.toFixed(2)} fps.`) - lastAppAverageFpsLog = new Date() - } - } - - requestAnimationFrame(loop) - }) - } - fpsMeter() + // // Routine to log the framerate of the video streams + // const streamsFrameRateHistory = ref<{ [key in string]: number[] }>({}) + // let lastStreamAverageFramerateLog = new Date() + // const streamAverageFramerateLogDelay = 10000 + // setInterval(() => { + // Object.keys(videoStore.activeStreams).forEach((streamName) => { + // if (videoStore.activeStreams[streamName] === undefined) return + // videoStore.activeStreams[streamName]!.mediaStream?.getVideoTracks().forEach((track) => { + // if (streamsFrameRateHistory.value[streamName] === undefined) streamsFrameRateHistory.value[streamName] = [] + // if (track.getSettings().frameRate === undefined) return + + // const streamHistory = streamsFrameRateHistory.value[streamName] + // streamHistory.push(track.getSettings().frameRate as number) + // streamHistory.splice(0, streamHistory.length - 10) + // streamsFrameRateHistory.value[streamName] = streamHistory + + // const average = streamHistory.reduce((a, b) => a + b, 0) / streamHistory.length + // const minThreshold = 0.9 * average + // const newFrameRate = track.getSettings().frameRate as number + + // // Warn about drops in the framerate of the video stream + // if (newFrameRate < minThreshold) { + // console.warn(`Drop in the framerate detected for stream '${streamName}': ${newFrameRate.toFixed(2)} fps.`) + // } + + // // Log the average framerate of the video stream recursively + // if (new Date().getTime() - lastStreamAverageFramerateLog.getTime() > streamAverageFramerateLogDelay) { + // console.debug(`Average frame rate for stream '${streamName}': ${average.toFixed(2)} fps.`) + // lastStreamAverageFramerateLog = new Date() + // } + // }) + // }) + // }, 250) + + // // Routine to log the framerate of the application rendering + // const appFrameRateHistory = ref([]) + // const appAverageFrameRateSampleDelay = 100 + // const appAverageFrameRateLogDelay = 10000 + // let lastAppAverageFpsLog = new Date() + + // // Log tab visibility changes so we don't warn about framerate drops when the tab was not visible in the last seconds + // const windowVisibility = useDocumentVisibility() + // let timeLastTabOpening = new Date() + // watch(windowVisibility, (newVisibility, oldVisibility) => { + // if (newVisibility === 'visible' && oldVisibility === 'hidden') { + // timeLastTabOpening = new Date() + // } + // }) + + // const fpsMeter = (): void => { + // let prevTime = performance.now() + // let frames = 0 + + // requestAnimationFrame(function loop() { + // const time = performance.now() + // frames++ + // if (time > prevTime + appAverageFrameRateSampleDelay) { + // const currentFPS = Math.round((frames * 1000) / (time - prevTime)) + // prevTime = time + // frames = 0 + + // appFrameRateHistory.value.push(currentFPS) + // appFrameRateHistory.value.splice(0, appFrameRateHistory.value.length - 10) + + // const average = appFrameRateHistory.value.reduce((a, b) => a + b, 0) / appFrameRateHistory.value.length + + // // Warn about drops in the framerate of the application rendering + // // The threshold is set to 80% of the average framerate by default + // // We don't warn if the framerate is above 60 because it's an already very high value, and we don't want to spam the console on high-end monitors + // // We also don't warn if the tab was not visible in the last second, since the application was not being rendered + // const minThreshold = Math.min(60, 0.8 * average) + // const msSinceLastTabOpening = new Date().getTime() - timeLastTabOpening.getTime() + // if (currentFPS < minThreshold && msSinceLastTabOpening > 1000) { + // console.warn(`Drop in the framerate detected for the application rendering: ${currentFPS.toFixed(2)} fps.`) + // } + + // // Log the average framerate of the application rendering recursively + // if (new Date().getTime() - lastAppAverageFpsLog.getTime() > appAverageFrameRateLogDelay) { + // console.debug(`Average framerate for the application rendering: ${average.toFixed(2)} fps.`) + // lastAppAverageFpsLog = new Date() + // } + // } + + // requestAnimationFrame(loop) + // }) + // } + // fpsMeter() // Routine to log the WebRTC statistics