Bug 1400757 - Add telemetry to MediaRecorder and TrackEncoder to track basic usage. r?pehrsons,francois
Add telemetry to collect the following:
- Number of times a MediaRecorder is started during a session
- Duration of media recordings
- How often we're timing out init of audio and video track encoders
MozReview-Commit-ID: 9Pc2oKNCH1M
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -1194,16 +1194,18 @@ MediaRecorder::Start(const Optional<int3
timeSlice = aTimeSlice.Value();
}
MediaRecorderReporter::AddMediaRecorder(this);
mState = RecordingState::Recording;
// Start a session.
mSessions.AppendElement();
mSessions.LastElement() = new Session(this, timeSlice);
mSessions.LastElement()->Start();
+ mStartTime = TimeStamp::Now();
+ Telemetry::ScalarAdd(Telemetry::ScalarID::MEDIARECORDER_RECORDING_COUNT, 1);
}
void
MediaRecorder::Stop(ErrorResult& aResult)
{
LOG(LogLevel::Debug, ("MediaRecorder.Stop %p", this));
MediaRecorderReporter::RemoveMediaRecorder(this);
if (mState == RecordingState::Inactive) {
@@ -1569,16 +1571,22 @@ MediaRecorder::StopForSessionDestruction
{
LOG(LogLevel::Debug, ("MediaRecorder.StopForSessionDestruction %p", this));
MediaRecorderReporter::RemoveMediaRecorder(this);
// We do not perform a mState != RecordingState::Recording) check here as
// we may already be inactive due to ForceInactive().
mState = RecordingState::Inactive;
MOZ_ASSERT(mSessions.Length() > 0);
mSessions.LastElement()->Stop();
+ // This is a coarse calculation and does not reflect the duration of the
+ // final recording for reasons such as pauses. However it allows us an idea
+ // of how long people are running their recorders for.
+ TimeDuration timeDelta = TimeStamp::Now() - mStartTime;
+ Telemetry::Accumulate(Telemetry::MEDIA_RECORDER_RECORDING_DURATION,
+ timeDelta.ToSeconds());
}
void
MediaRecorder::InitializeDomExceptions()
{
mSecurityDomException = DOMException::Create(NS_ERROR_DOM_SECURITY_ERR);
mUnknownDomException = DOMException::Create(NS_ERROR_DOM_UNKNOWN_ERR);
}
--- a/dom/media/MediaRecorder.h
+++ b/dom/media/MediaRecorder.h
@@ -162,16 +162,18 @@ protected:
// It specifies the container format as well as the audio and video capture formats.
nsString mMimeType;
uint32_t mAudioBitsPerSecond;
uint32_t mVideoBitsPerSecond;
uint32_t mBitsPerSecond;
+ TimeStamp mStartTime;
+
// DOMExceptions that are created early and possibly thrown in NotifyError.
// Creating them early allows us to capture the JS stack for which cannot be
// done at the time the error event is fired.
RefPtr<DOMException> mSecurityDomException;
RefPtr<DOMException> mUnknownDomException;
private:
// Register MediaRecorder into Document to listen the activity changes.
--- a/dom/media/encoder/TrackEncoder.cpp
+++ b/dom/media/encoder/TrackEncoder.cpp
@@ -224,16 +224,18 @@ AudioTrackEncoder::TryInit(const AudioSe
// data yet. Motivated by issues like Bug 1336367
TRACK_LOG(LogLevel::Warning,
("[AudioTrackEncoder]: Initialize failed "
"for %ds. Attempting to init with %d "
"(default) channels!",
AUDIO_INIT_FAILED_DURATION,
DEFAULT_CHANNELS));
nsresult rv = Init(DEFAULT_CHANNELS, mTrackRate);
+ Telemetry::Accumulate(
+ Telemetry::MEDIA_RECORDER_TRACK_ENCODER_INIT_TIMEOUT_TYPE, 0);
if (NS_FAILED(rv)) {
TRACK_LOG(LogLevel::Error,
("[AudioTrackEncoder %p]: Default-channel-init failed.", this));
OnError();
return;
}
}
}
@@ -517,16 +519,18 @@ VideoTrackEncoder::Init(const VideoSegme
}
mNotInitDuration += aDuration;
if ((mNotInitDuration / mTrackRate > VIDEO_INIT_FAILED_DURATION) &&
mInitCounter > 1) {
TRACK_LOG(LogLevel::Warning,
("[VideoTrackEncoder %p]: No successful init for %ds.",
this, VIDEO_INIT_FAILED_DURATION));
+ Telemetry::Accumulate(
+ Telemetry::MEDIA_RECORDER_TRACK_ENCODER_INIT_TIMEOUT_TYPE, 1);
OnError();
return;
}
}
void
VideoTrackEncoder::Cancel()
{
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -9231,16 +9231,35 @@
"WEBRTC_CALL_TYPE": {
"record_in_processes": ["main", "content"],
"alert_emails": ["webrtc-telemetry-alerts@mozilla.com"],
"expires_in_version": "never",
"kind": "enumerated",
"n_values": 8,
"description": "Type of call: (Bitmask) Audio = 1, Video = 2, DataChannels = 4"
},
+ "MEDIA_RECORDER_RECORDING_DURATION": {
+ "record_in_processes": ["main", "content"],
+ "alert_emails": ["bvandyk@mozilla.com"],
+ "expires_in_version": "60",
+ "kind": "exponential",
+ "high": 3600,
+ "n_buckets": 100,
+ "bug_numbers": [1400757],
+ "description": "The length of time (in seconds) that a recording lasted. Recorded when a recorder stops"
+ },
+ "MEDIA_RECORDER_TRACK_ENCODER_INIT_TIMEOUT_TYPE": {
+ "record_in_processes": ["main", "content"],
+ "alert_emails": ["bvandyk@mozilla.com"],
+ "expires_in_version": "60",
+ "kind": "enumerated",
+ "n_values": 4,
+ "bug_numbers": [1400757],
+ "description": "Records the type of timeout that happened while attempting to init the encoder. Audio = 0, Video = 1. Recorded immediately following a timeout"
+ },
"DEVTOOLS_ENTRY_POINT": {
"record_in_processes": ["main"],
"bug_numbers": [1378863],
"alert_emails": ["dev-developer-tools@lists.mozilla.org", "apoirot@mozilla.com"],
"expires_in_version": "60",
"kind": "categorical",
"labels": ["KeyShortcut", "SystemMenu", "HamburgerMenu", "ContextMenu", "CommandLine"],
"releaseChannelCollection": "opt-out",
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -628,16 +628,31 @@ webrtc.nicer:
kind: uint
notification_emails:
- webrtc-ice-telemetry-alerts@mozilla.com
release_channel_collection: opt-in
record_in_processes:
- 'main'
- 'content'
+mediarecorder:
+ recording_count:
+ bug_numbers:
+ - 1400757
+ description: >
+ The number of times a MediaRecorder has been started. Recorded when a MediaRecorder starts
+ expires: "60"
+ kind: uint
+ notification_emails:
+ - bvandyk@mozilla.com
+ release_channel_collection: opt-in
+ record_in_processes:
+ - main
+ - content
+
# The following section contains content process base counters.
dom.contentprocess:
troubled_due_to_memory:
bug_numbers:
- 1305091
description: >
The number of content processes that were marked as troubled because
it was running low on virtual memory.