Commit 102a446f authored by joi@chromium.org's avatar joi@chromium.org

Add the WebRTC.webkitApiCountPerSession metric.

BUG=348616

Review URL: https://codereview.chromium.org/214983003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260211 0039d316-1c4b-4281-b951-d872f2087c98
parent 1a1b39e2
...@@ -735,6 +735,8 @@ ...@@ -735,6 +735,8 @@
'renderer/media/webrtc_local_audio_track.h', 'renderer/media/webrtc_local_audio_track.h',
'renderer/media/webrtc_logging.cc', 'renderer/media/webrtc_logging.cc',
'renderer/media/webrtc_logging.h', 'renderer/media/webrtc_logging.h',
'renderer/media/webrtc_uma_histograms.cc',
'renderer/media/webrtc_uma_histograms.h',
'renderer/p2p/host_address_request.cc', 'renderer/p2p/host_address_request.cc',
'renderer/p2p/host_address_request.h', 'renderer/p2p/host_address_request.h',
'renderer/p2p/ipc_network_manager.cc', 'renderer/p2p/ipc_network_manager.cc',
......
...@@ -731,6 +731,7 @@ ...@@ -731,6 +731,7 @@
'renderer/media/webrtc_identity_service_unittest.cc', 'renderer/media/webrtc_identity_service_unittest.cc',
'renderer/media/webrtc_local_audio_source_provider_unittest.cc', 'renderer/media/webrtc_local_audio_source_provider_unittest.cc',
'renderer/media/webrtc_local_audio_track_unittest.cc', 'renderer/media/webrtc_local_audio_track_unittest.cc',
'renderer/media/webrtc_uma_histograms_unittest.cc',
], ],
'dependencies': [ 'dependencies': [
'../third_party/libjingle/libjingle.gyp:libjingle_webrtc', '../third_party/libjingle/libjingle.gyp:libjingle_webrtc',
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "content/renderer/media/rtc_media_constraints.h" #include "content/renderer/media/rtc_media_constraints.h"
#include "content/renderer/media/webrtc_audio_capturer.h" #include "content/renderer/media/webrtc_audio_capturer.h"
#include "content/renderer/media/webrtc_audio_device_impl.h" #include "content/renderer/media/webrtc_audio_device_impl.h"
#include "content/renderer/media/webrtc_uma_histograms.h"
#include "content/renderer/render_thread_impl.h" #include "content/renderer/render_thread_impl.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h" #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h" #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
...@@ -553,6 +554,8 @@ bool RTCPeerConnectionHandler::addStream( ...@@ -553,6 +554,8 @@ bool RTCPeerConnectionHandler::addStream(
peer_connection_tracker_->TrackAddStream( peer_connection_tracker_->TrackAddStream(
this, stream, PeerConnectionTracker::SOURCE_LOCAL); this, stream, PeerConnectionTracker::SOURCE_LOCAL);
PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter();
track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM,
MediaStream::GetAdapter(stream)); MediaStream::GetAdapter(stream));
...@@ -591,6 +594,7 @@ void RTCPeerConnectionHandler::removeStream( ...@@ -591,6 +594,7 @@ void RTCPeerConnectionHandler::removeStream(
if (peer_connection_tracker_) if (peer_connection_tracker_)
peer_connection_tracker_->TrackRemoveStream( peer_connection_tracker_->TrackRemoveStream(
this, stream, PeerConnectionTracker::SOURCE_LOCAL); this, stream, PeerConnectionTracker::SOURCE_LOCAL);
PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter();
track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM,
MediaStream::GetAdapter(stream)); MediaStream::GetAdapter(stream));
} }
...@@ -767,6 +771,8 @@ void RTCPeerConnectionHandler::OnAddStream( ...@@ -767,6 +771,8 @@ void RTCPeerConnectionHandler::OnAddStream(
this, remote_stream->webkit_stream(), this, remote_stream->webkit_stream(),
PeerConnectionTracker::SOURCE_REMOTE); PeerConnectionTracker::SOURCE_REMOTE);
PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter();
track_metrics_.AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM, track_metrics_.AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM,
stream_interface); stream_interface);
...@@ -784,6 +790,7 @@ void RTCPeerConnectionHandler::OnRemoveStream( ...@@ -784,6 +790,7 @@ void RTCPeerConnectionHandler::OnRemoveStream(
track_metrics_.RemoveStream(MediaStreamTrackMetrics::RECEIVED_STREAM, track_metrics_.RemoveStream(MediaStreamTrackMetrics::RECEIVED_STREAM,
stream_interface); stream_interface);
PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter();
scoped_ptr<RemoteMediaStreamImpl> remote_stream(it->second); scoped_ptr<RemoteMediaStreamImpl> remote_stream(it->second);
const blink::WebMediaStream& webkit_stream = remote_stream->webkit_stream(); const blink::WebMediaStream& webkit_stream = remote_stream->webkit_stream();
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/media/webrtc_uma_histograms.h"
#include "base/metrics/histogram.h"
namespace content {
void UpdateWebRTCMethodCount(JavaScriptAPIName api_name) {
DVLOG(3) << "Incrementing WebRTC.webkitApiCount for " << api_name;
UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCount", api_name, INVALID_NAME);
PerSessionWebRTCAPIMetrics::GetInstance()->LogUsageOnlyOnce(api_name);
}
PerSessionWebRTCAPIMetrics::~PerSessionWebRTCAPIMetrics() {
}
// static
PerSessionWebRTCAPIMetrics* PerSessionWebRTCAPIMetrics::GetInstance() {
return Singleton<PerSessionWebRTCAPIMetrics>::get();
}
void PerSessionWebRTCAPIMetrics::IncrementStreamCounter() {
DCHECK(CalledOnValidThread());
++num_streams_;
}
void PerSessionWebRTCAPIMetrics::DecrementStreamCounter() {
DCHECK(CalledOnValidThread());
if (--num_streams_ == 0) {
ResetUsage();
}
}
PerSessionWebRTCAPIMetrics::PerSessionWebRTCAPIMetrics() : num_streams_(0) {
ResetUsage();
}
void PerSessionWebRTCAPIMetrics::LogUsage(JavaScriptAPIName api_name) {
DVLOG(3) << "Incrementing WebRTC.webkitApiCountPerSession for " << api_name;
UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCountPerSession",
api_name, INVALID_NAME);
}
void PerSessionWebRTCAPIMetrics::LogUsageOnlyOnce(JavaScriptAPIName api_name) {
DCHECK(CalledOnValidThread());
if (!has_used_api_[api_name]) {
has_used_api_[api_name] = true;
LogUsage(api_name);
}
}
void PerSessionWebRTCAPIMetrics::ResetUsage() {
for (size_t i = 0; i < arraysize(has_used_api_); ++i)
has_used_api_[i] = false;
}
} // namespace content
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_
#define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ #define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_
#include "base/metrics/histogram.h" #include "base/memory/singleton.h"
#include "base/threading/non_thread_safe.h"
#include "content/common/content_export.h"
namespace content { namespace content {
...@@ -19,11 +21,61 @@ enum JavaScriptAPIName { ...@@ -19,11 +21,61 @@ enum JavaScriptAPIName {
}; };
// Helper method used to collect information about the number of times // Helper method used to collect information about the number of times
// different WebRTC API:s are called from JavaScript. // different WebRTC APIs are called from JavaScript.
// The histogram can be viewed at chrome://histograms/WebRTC.webkitApiCount. //
inline void UpdateWebRTCMethodCount(JavaScriptAPIName api_name) { // This contributes to two histograms; the former is a raw count of
UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCount", api_name, INVALID_NAME); // the number of times the APIs are called, and be viewed at
} // chrome://histograms/WebRTC.webkitApiCount.
//
// The latter is a count of the number of times the APIs are called
// that gets incremented only once per "session" as established by the
// PerSessionWebRTCAPIMetrics singleton below. It can be viewed at
// chrome://histograms/WebRTC.webkitApiCountPerSession.
void UpdateWebRTCMethodCount(JavaScriptAPIName api_name);
// A singleton that keeps track of the number of MediaStreams being
// sent over PeerConnections. It uses the transition to zero such
// streams to demarcate the start of a new "session". Note that this
// is a rough approximation of sessions, as you could conceivably have
// multiple tabs using this renderer process, and each of them using
// PeerConnections.
//
// The UpdateWebRTCMethodCount function above uses this class to log a
// metric at most once per session.
class CONTENT_EXPORT PerSessionWebRTCAPIMetrics : public base::NonThreadSafe {
public:
virtual ~PerSessionWebRTCAPIMetrics();
static PerSessionWebRTCAPIMetrics* GetInstance();
// Increment/decrement the number of streams being sent or received
// over any current PeerConnection.
void IncrementStreamCounter();
void DecrementStreamCounter();
protected:
friend struct DefaultSingletonTraits<PerSessionWebRTCAPIMetrics>;
friend void UpdateWebRTCMethodCount(JavaScriptAPIName);
// Protected so that unit tests can test without this being a
// singleton.
PerSessionWebRTCAPIMetrics();
// Overridable by unit tests.
virtual void LogUsage(JavaScriptAPIName api_name);
// Called by UpdateWebRTCMethodCount above. Protected rather than
// private so that unit tests can call it.
void LogUsageOnlyOnce(JavaScriptAPIName api_name);
private:
void ResetUsage();
int num_streams_;
bool has_used_api_[INVALID_NAME];
DISALLOW_COPY_AND_ASSIGN(PerSessionWebRTCAPIMetrics);
};
} // namespace content } // namespace content
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/media/webrtc_uma_histograms.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
namespace content {
class MockPerSessionWebRTCAPIMetrics : public PerSessionWebRTCAPIMetrics {
public:
MockPerSessionWebRTCAPIMetrics() {}
using PerSessionWebRTCAPIMetrics::LogUsageOnlyOnce;
MOCK_METHOD1(LogUsage, void(JavaScriptAPIName));
};
TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingGetUserMedia) {
MockPerSessionWebRTCAPIMetrics metrics;
EXPECT_CALL(metrics, LogUsage(_)).Times(1);
metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA);
}
TEST(PerSessionWebRTCAPIMetrics, CallOngoingGetUserMedia) {
MockPerSessionWebRTCAPIMetrics metrics;
metrics.IncrementStreamCounter();
EXPECT_CALL(metrics, LogUsage(WEBKIT_GET_USER_MEDIA)).Times(1);
metrics.LogUsageOnlyOnce(WEBKIT_GET_USER_MEDIA);
}
TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingRTCPeerConnection) {
MockPerSessionWebRTCAPIMetrics metrics;
EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION));
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
}
TEST(PerSessionWebRTCAPIMetrics, NoCallOngoingMultiplePC) {
MockPerSessionWebRTCAPIMetrics metrics;
EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
}
TEST(PerSessionWebRTCAPIMetrics, BeforeAfterCallMultiplePC) {
MockPerSessionWebRTCAPIMetrics metrics;
EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.IncrementStreamCounter();
metrics.IncrementStreamCounter();
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.DecrementStreamCounter();
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.DecrementStreamCounter();
EXPECT_CALL(metrics, LogUsage(WEBKIT_RTC_PEER_CONNECTION)).Times(1);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
metrics.LogUsageOnlyOnce(WEBKIT_RTC_PEER_CONNECTION);
}
} // namespace content
...@@ -29148,6 +29148,27 @@ other types of suffix sets. ...@@ -29148,6 +29148,27 @@ other types of suffix sets.
<summary>Counts number of calls to WebRTC APIs from JavaScript.</summary> <summary>Counts number of calls to WebRTC APIs from JavaScript.</summary>
</histogram> </histogram>
<histogram name="WebRTC.webkitApiCountPerSession" enum="JavaScriptAPIName">
<owner>tommi@chromium.org</owner>
<summary>
Counts number of calls to WebRTC APIs from JavaScript, once per
&quot;session&quot; which is demarcated by the total number of MediaStreams
within a renderer process that are being sent over a PeerConnection
transitioning from or to 0.
</summary>
</histogram>
<histogram name="WebRTC.webkitApiCountUniqueByOrigin" enum="JavaScriptAPIName">
<obsolete>
Deprecated as of r253828 (27 Feb 2014).
</obsolete>
<owner>tommi@chromium.org</owner>
<summary>
Counts number of calls to WebRTC APIs from JavaScript, once per origin per
renderer process.
</summary>
</histogram>
<histogram name="Webstore.ExtensionInstallResult" enum="BooleanSuccess"> <histogram name="Webstore.ExtensionInstallResult" enum="BooleanSuccess">
<owner>jackhou@chromium.org</owner> <owner>jackhou@chromium.org</owner>
<summary> <summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment