-
Notifications
You must be signed in to change notification settings - Fork 551
fix(webrtc): reduce PeerConnectionAnalyzer log verbosity during bad quality #18418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,21 @@ function PeerConnectionAnalyzer() { | |
| video: true, | ||
| } | ||
|
|
||
| // Total number of entries ever pushed to _rtcStats[kind] since last reset. | ||
| // Used together with _loggedUpToRtcStatsTotal to determine which entries | ||
| // are new and have not been logged yet. | ||
| this._totalRtcStatsAdded = { | ||
| audio: 0, | ||
| video: 0, | ||
| } | ||
| // Value of _totalRtcStatsAdded[kind] after the last _logStats call. | ||
| // -1 is a sentinel meaning "not currently in a bad quality period"; on the | ||
| // next bad check all current _rtcStats entries will be logged. | ||
| this._loggedUpToRtcStatsTotal = { | ||
| audio: -1, | ||
| video: -1, | ||
| } | ||
|
|
||
| this._peerConnection = null | ||
| this._peerDirection = null | ||
| this._peerType = null | ||
|
|
@@ -221,6 +236,9 @@ PeerConnectionAnalyzer.prototype = { | |
| this._packetsPerSecond[kind].reset() | ||
| this._timestamps[kind].reset() | ||
| this._timestampsForLogs[kind].reset() | ||
|
|
||
| this._totalRtcStatsAdded[kind] = 0 | ||
| this._loggedUpToRtcStatsTotal[kind] = -1 | ||
| }, | ||
|
|
||
| _handleIceConnectionStateChanged() { | ||
|
|
@@ -303,6 +321,7 @@ PeerConnectionAnalyzer.prototype = { | |
| this._rtcStats[kind].shift() | ||
| } | ||
| this._rtcStats[kind].push([]) | ||
| this._totalRtcStatsAdded[kind]++ | ||
| } | ||
|
|
||
| if (this._peerDirection === PEER_DIRECTION.SENDER) { | ||
|
|
@@ -317,6 +336,10 @@ PeerConnectionAnalyzer.prototype = { | |
| if (this._analysisEnabled.video) { | ||
| this._setConnectionQualityVideo(this._calculateConnectionQualityVideo()) | ||
| } | ||
|
|
||
| for (const kind of ['audio', 'video']) { | ||
| this._logRemainingStatsIfQualityRecovered(kind) | ||
| } | ||
| }, | ||
|
|
||
| _processSenderStats(stats) { | ||
|
|
@@ -767,6 +790,15 @@ PeerConnectionAnalyzer.prototype = { | |
| }, | ||
|
|
||
| _logStats(kind, message) { | ||
| const logAll = this._loggedUpToRtcStatsTotal[kind] === -1 | ||
| const newCount = logAll | ||
| ? this._rtcStats[kind].length | ||
| : this._totalRtcStatsAdded[kind] - this._loggedUpToRtcStatsTotal[kind] | ||
|
|
||
| if (!logAll && newCount === 0) { | ||
| return | ||
| } | ||
|
|
||
| const tag = this._getLogTag(kind) | ||
|
|
||
| if (message) { | ||
|
|
@@ -780,20 +812,53 @@ PeerConnectionAnalyzer.prototype = { | |
| console.debug('%s: Round trip time: %s', tag, this._roundTripTime[kind].toString()) | ||
| console.debug('%s: Timestamps: %s', tag, this._timestampsForLogs[kind].toString()) | ||
|
|
||
| this._logRtcStats(tag, kind) | ||
| const startTotal = logAll ? 0 : this._loggedUpToRtcStatsTotal[kind] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the full RTC stats are logged they will always be indexed at 0. However, subsequent logs will take into account the total count of RTC stats, so the value will jump to something higher. Therefore the initial log should also respect the total count of RTC stats (probably something like |
||
| const startIdx = Math.max(0, this._rtcStats[kind].length - newCount) | ||
| this._logRtcStats(tag, kind, startTotal, startIdx) | ||
|
|
||
| this._loggedUpToRtcStatsTotal[kind] = this._totalRtcStatsAdded[kind] | ||
| }, | ||
|
|
||
| _logRtcStats(tag, kind) { | ||
| this._rtcStats[kind].forEach((rtcStats, i) => { | ||
| // Logs entries in _rtcStats[kind] from startIdx onwards, using startTotal | ||
| // as the base for the printed entry indices so they are consistent across | ||
| // calls even as old entries are shifted out of the sliding window. | ||
| _logRtcStats(tag, kind, startTotal = 0, startIdx = 0) { | ||
| for (let i = startIdx; i < this._rtcStats[kind].length; i++) { | ||
| const rtcStats = this._rtcStats[kind][i] | ||
| const logIdx = startTotal + (i - startIdx) | ||
|
|
||
| if (!rtcStats.length) { | ||
| console.debug('%s: %i: no matching type', tag, i) | ||
| return | ||
| console.debug('%s: %i: no matching type', tag, logIdx) | ||
| continue | ||
| } | ||
|
|
||
| rtcStats.forEach((rtcStat, j) => { | ||
| console.debug('%s: %i-%i: %s', tag, i, j, JSON.stringify(rtcStat)) | ||
| console.debug('%s: %i-%i: %s', tag, logIdx, j, JSON.stringify(rtcStat)) | ||
| }) | ||
| }) | ||
| } | ||
| }, | ||
|
|
||
| // Called after each quality update. If quality has recovered from a bad | ||
| // period, flushes any rtcStats entries collected since the last _logStats | ||
| // call so that no data is missing in the logs. | ||
| _logRemainingStatsIfQualityRecovered(kind) { | ||
| if (this._loggedUpToRtcStatsTotal[kind] === -1) { | ||
| return | ||
| } | ||
|
|
||
| const quality = this._connectionQuality[kind] | ||
| if (quality === CONNECTION_QUALITY.VERY_BAD || quality === CONNECTION_QUALITY.NO_TRANSMITTED_DATA) { | ||
| return | ||
| } | ||
|
|
||
| const newCount = this._totalRtcStatsAdded[kind] - this._loggedUpToRtcStatsTotal[kind] | ||
| if (newCount > 0) { | ||
| const tag = this._getLogTag(kind) | ||
| const startIdx = Math.max(0, this._rtcStats[kind].length - newCount) | ||
| this._logRtcStats(tag, kind, this._loggedUpToRtcStatsTotal[kind], startIdx) | ||
| } | ||
|
|
||
| this._loggedUpToRtcStatsTotal[kind] = -1 | ||
| }, | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary (but I am not fully sure 🤔). Although the data to calculate the quality is reset, the RTC stats array is never reset, so the total count of RTC stats and the last logged RTC stat would still be valid and independent of the data to calculate the quality.