From 06435b3208bca93abdcf52a4205d2df8c49afb6c Mon Sep 17 00:00:00 2001 From: Bryce Van Dyk Date: Tue, 19 Sep 2017 07:34:02 +1200 Subject: [PATCH] Bug 1400757 - Add telemetry to MediaRecorder and TrackEncoder to track basic usage. r=francois,pehrsons 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 --HG-- extra : rebase_source : 16414a5ffa95413458d36295e5508df4c16e6fa9 --- dom/media/MediaRecorder.cpp | 8 ++++++++ dom/media/MediaRecorder.h | 2 ++ dom/media/encoder/TrackEncoder.cpp | 4 ++++ toolkit/components/telemetry/Histograms.json | 19 +++++++++++++++++++ toolkit/components/telemetry/Scalars.yaml | 15 +++++++++++++++ 5 files changed, 48 insertions(+) diff --git a/dom/media/MediaRecorder.cpp b/dom/media/MediaRecorder.cpp index 2f4be3cb3777..a0647c93f278 100644 --- a/dom/media/MediaRecorder.cpp +++ b/dom/media/MediaRecorder.cpp @@ -1199,6 +1199,8 @@ MediaRecorder::Start(const Optional& aTimeSlice, ErrorResult& aResult) mSessions.AppendElement(); mSessions.LastElement() = new Session(this, timeSlice); mSessions.LastElement()->Start(); + mStartTime = TimeStamp::Now(); + Telemetry::ScalarAdd(Telemetry::ScalarID::MEDIARECORDER_RECORDING_COUNT, 1); } void @@ -1574,6 +1576,12 @@ MediaRecorder::StopForSessionDestruction() 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 diff --git a/dom/media/MediaRecorder.h b/dom/media/MediaRecorder.h index 1eeed0c42a69..afa786523ebc 100644 --- a/dom/media/MediaRecorder.h +++ b/dom/media/MediaRecorder.h @@ -168,6 +168,8 @@ protected: 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. diff --git a/dom/media/encoder/TrackEncoder.cpp b/dom/media/encoder/TrackEncoder.cpp index 3f62db7e65bb..e281901696c2 100644 --- a/dom/media/encoder/TrackEncoder.cpp +++ b/dom/media/encoder/TrackEncoder.cpp @@ -229,6 +229,8 @@ AudioTrackEncoder::TryInit(const AudioSegment& aSegment, StreamTime aDuration) 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)); @@ -522,6 +524,8 @@ VideoTrackEncoder::Init(const VideoSegment& aSegment, StreamTime aDuration) 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; } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 77437edf496b..d6f34a760039 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -9268,6 +9268,25 @@ "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], diff --git a/toolkit/components/telemetry/Scalars.yaml b/toolkit/components/telemetry/Scalars.yaml index 2dc2a9f2771b..6ca1c1adcfed 100644 --- a/toolkit/components/telemetry/Scalars.yaml +++ b/toolkit/components/telemetry/Scalars.yaml @@ -633,6 +633,21 @@ webrtc.nicer: - '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: