| Index: tools/perf/page_sets/webrtc_track_peerconnections.js
|
| diff --git a/tools/perf/page_sets/webrtc_track_peerconnections.js b/tools/perf/page_sets/webrtc_track_peerconnections.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..68ee11fbee5718be09c99551274c0899cfc6c1b5
|
| --- /dev/null
|
| +++ b/tools/perf/page_sets/webrtc_track_peerconnections.js
|
| @@ -0,0 +1,52 @@
|
| +// 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.
|
| +
|
| +// This file overwrites the webkitRTCPeerConnection constructor with a
|
| +// new constructor which tracks all created connections. It does this by
|
| +// periodically gathering statistics on all connections, using the WebRTC
|
| +// statistics API. All reports are gathered into window.peerConnectionReports,
|
| +// which contains one list per connection. In each list there is a number of
|
| +// report batches, which in turn contains metric names mapped to values.
|
| +
|
| +window.peerConnectionReports = [];
|
| +
|
| +webkitRTCPeerConnection = (function() {
|
| + function getReportsAsDicts(getStatsResult) {
|
| + var result = [];
|
| + getStatsResult.forEach(function(report) {
|
| + var values = {};
|
| + report.names().forEach(function(name) {
|
| + values[name] = report.stat(name);
|
| + });
|
| + result.push(values);
|
| + });
|
| + return result;
|
| + }
|
| +
|
| + function gatherStatsFromOneConnection(peerConnection) {
|
| + var connectionId = window.peerConnectionReports.length;
|
| + window.peerConnectionReports.push([]);
|
| + var pollIntervalMs = 1000;
|
| +
|
| + setInterval(function() {
|
| + peerConnection.getStats(function(response) {
|
| + var reports = getReportsAsDicts(response.result());
|
| + window.peerConnectionReports[connectionId].push(reports);
|
| + });
|
| + }, pollIntervalMs);
|
| + }
|
| +
|
| + var originalConstructor = webkitRTCPeerConnection;
|
| + return function() {
|
| + // Bind the incoming arguments to the original constructor.
|
| + var args = [null].concat(Array.prototype.slice.call(arguments));
|
| + var factoryFunction = originalConstructor.bind.apply(
|
| + originalConstructor, args);
|
| +
|
| + // Create the object and track it.
|
| + var peerConnection = new factoryFunction();
|
| + gatherStatsFromOneConnection(peerConnection);
|
| + return peerConnection;
|
| + }
|
| +})();
|
|
|