Skip to content

Commit

Permalink
Create MicCreationSuccessful UMA histogram (youtube#1890)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
loganmann-google authored Nov 2, 2023
2 parents 72a37d5 + dc19e59 commit 1653946
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cobalt/media_capture/media_devices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>
#include <utility>

#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"
Expand Down Expand Up @@ -66,6 +67,11 @@ std::unique_ptr<Microphone> CreateMicrophone(
return mic;
}

void LogMicCreationSucceededHistogramItem(bool mic_creation_succeeded) {
base::UmaHistogramBoolean("Cobalt.MediaDevices.MicCreationSucceeded",
mic_creation_succeeded);
}

} // namespace.

MediaDevices::MediaDevices(script::EnvironmentSettings* settings,
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions tools/metrics/histograms/metadata/cobalt/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ Always run the pretty print utility on this file after editing:
</summary>
</histogram>

<histogram name="Cobalt.MediaDevices.MicCreationSucceeded" enum="Boolean"
expires_after="never">
<!-- expires-never: Needed for long-term tracking of device mic support. -->

<owner>[email protected]</owner>
<owner>[email protected]</owner>
<owner>[email protected]</owner>
<summary>
A boolean representing the success or failure of an attempted mic creation
event via mediaDevices.getUserMedia().
</summary>
</histogram>

</histograms>

</histogram-configuration>

0 comments on commit 1653946

Please sign in to comment.