Skip to content

Commit

Permalink
feat(Stats): count non fatal errors (#6781)
Browse files Browse the repository at this point in the history
Add `nonFatalErrorCount` to shaka stats.
  • Loading branch information
tykus160 authored Jun 10, 2024
1 parent 59304b8 commit 081afde
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ shaka.extern.StateChange;
*
* bytesDownloaded: number,
*
* nonFatalErrorCount: number,
*
* switchHistory: !Array.<shaka.extern.TrackChoice>,
* stateHistory: !Array.<shaka.extern.StateChange>
* }}
Expand Down Expand Up @@ -166,6 +168,9 @@ shaka.extern.StateChange;
* @property {number} bytesDownloaded
* The bytes downloaded during the playback. If nothing is loaded, NaN.
*
* @property {number} nonFatalErrorCount
* The amount of non fatal errors that occurred. If nothing is loaded, NaN.
*
* @property {!Array.<shaka.extern.TrackChoice>} switchHistory
* A history of the stream changes.
* @property {!Array.<shaka.extern.StateChange>} stateHistory
Expand Down
4 changes: 4 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7006,6 +7006,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return;
}

if (error.severity === shaka.util.Error.Severity.RECOVERABLE) {
this.stats_.addNonFatalError();
}

let fireError = true;
if (this.fullyLoaded_ && this.manifest_ && this.streamingEngine_ &&
(error.code == shaka.util.Error.Code.VIDEO_ERROR ||
Expand Down
10 changes: 10 additions & 0 deletions lib/util/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ shaka.util.Stats = class {
/** @private {number} */
this.bytesDownloaded_ = NaN;

/** @private {number} */
this.nonFatalErrorCount_ = 0;

/** @private {!shaka.util.StateHistory} */
this.stateHistory_ = new shaka.util.StateHistory();

Expand Down Expand Up @@ -217,6 +220,11 @@ shaka.util.Stats = class {
}
}

/** */
addNonFatalError() {
this.nonFatalErrorCount_++;
}

/**
* @return {!shaka.util.StateHistory}
*/
Expand Down Expand Up @@ -259,6 +267,7 @@ shaka.util.Stats = class {
liveLatency: this.liveLatencySeconds_,
maxSegmentDuration: this.maxSegmentDurationSeconds_,
bytesDownloaded: this.bytesDownloaded_,
nonFatalErrorCount: this.nonFatalErrorCount_,
stateHistory: this.stateHistory_.getCopy(),
switchHistory: this.switchHistory_.getCopy(),
};
Expand Down Expand Up @@ -292,6 +301,7 @@ shaka.util.Stats = class {
liveLatency: NaN,
maxSegmentDuration: NaN,
bytesDownloaded: NaN,
nonFatalErrorCount: NaN,
switchHistory: [],
stateHistory: [],
};
Expand Down
2 changes: 2 additions & 0 deletions test/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ describe('Player', () => {

bytesDownloaded: jasmine.any(Number),

nonFatalErrorCount: jasmine.any(Number),

// We should have loaded the first Period by now, so we should have a
// history.
switchHistory: jasmine.arrayContaining([{
Expand Down
5 changes: 5 additions & 0 deletions ui/statistics_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
return this.currentStats_[name] + ' (stalls)';
};

const parseErrors = (name) => {
return this.currentStats_[name] + ' (errors)';
};

const parseBytesDownloaded = (name) => {
const bytes = parseInt(this.currentStats_[name], 10);
if (bytes > 1e6) {
Expand Down Expand Up @@ -150,6 +154,7 @@ shaka.ui.StatisticsButton = class extends shaka.ui.Element {
'stallsDetected': parseStalls,
'gapsJumped': parseGaps,
'bytesDownloaded': parseBytesDownloaded,
'nonFatalErrorCount': parseErrors,
};

/** @private {shaka.util.Timer} */
Expand Down

0 comments on commit 081afde

Please sign in to comment.