From dc19e5909d0f926e396d7f3c669a03a4d6c3230c Mon Sep 17 00:00:00 2001 From: Logan Mann Date: Wed, 1 Nov 2023 22:58:05 +0000 Subject: [PATCH] Create MicCreationSuccessful UMA histogram Adds a boolean enum histogram to track the frequency at which mic usage is successful. When mic input is requested in mediaDevices.getUserMedia(), either a success or failure callback is run depending on whether a mic was able to be opened. This histogram logs a success or failure item in each callback. See http://go/cobalt-mic-uma-histogram for additional details. b/306441161 --- cobalt/media_capture/media_devices.cc | 12 ++++++++++++ .../histograms/metadata/cobalt/histograms.xml | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cobalt/media_capture/media_devices.cc b/cobalt/media_capture/media_devices.cc index 7a75b18e63d3..3c671f3609f2 100644 --- a/cobalt/media_capture/media_devices.cc +++ b/cobalt/media_capture/media_devices.cc @@ -18,6 +18,7 @@ #include #include +#include "base/metrics/histogram_functions.h" #include "base/threading/thread_task_runner_handle.h" #include "cobalt/base/polymorphic_downcast.h" #include "cobalt/media_capture/media_device_info.h" @@ -66,6 +67,11 @@ std::unique_ptr CreateMicrophone( return mic; } +void LogMicCreationSucceededHistogramItem(bool mic_creation_succeeded) { + base::UmaHistogramBoolean("Cobalt.MediaDevices.MicCreationSucceeded", + mic_creation_succeeded); +} + } // namespace. MediaDevices::MediaDevices(script::EnvironmentSettings* settings, @@ -169,6 +175,9 @@ void MediaDevices::OnMicrophoneError( speech::MicrophoneManager::MicrophoneError error, std::string message) { DLOG(INFO) << "MediaDevices::OnMicrophoneError " << message; + // Log failed mic creation in UMA histogram + LogMicCreationSucceededHistogramItem(false); + // No special error handling logic besides logging the message above, so just // delegate to the OnMicrophoneStopped() functionality. OnMicrophoneStopped(); @@ -195,6 +204,9 @@ void MediaDevices::OnMicrophoneStopped() { } void MediaDevices::OnMicrophoneSuccess() { + // Log successful mic creation in UMA histogram + LogMicCreationSucceededHistogramItem(true); + if (javascript_message_loop_->task_runner() != base::ThreadTaskRunnerHandle::Get()) { javascript_message_loop_->task_runner()->PostTask( diff --git a/tools/metrics/histograms/metadata/cobalt/histograms.xml b/tools/metrics/histograms/metadata/cobalt/histograms.xml index 6c4fd71d4597..171ee7d5f2b4 100644 --- a/tools/metrics/histograms/metadata/cobalt/histograms.xml +++ b/tools/metrics/histograms/metadata/cobalt/histograms.xml @@ -151,6 +151,19 @@ Always run the pretty print utility on this file after editing: + + + + loganmann@google.com + yt-magma-eng@google.com + cobalt-team@google.com + + A boolean representing the success or failure of an attempted mic creation + event via mediaDevices.getUserMedia(). + + +