diff options
author | jiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-08 21:26:34 +0000 |
---|---|---|
committer | jiayl@chromium.org <jiayl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-08 21:26:34 +0000 |
commit | dab95c4c528c5509c7f426d55ba913b9ad038159 (patch) | |
tree | b02019723dbd17f31b112f748ba6ab8895a14803 | |
parent | c9f4983e513643d940f1cf0dfc7efa2e9e2c3495 (diff) | |
download | chromium_src-dab95c4c528c5509c7f426d55ba913b9ad038159.zip chromium_src-dab95c4c528c5509c7f426d55ba913b9ad038159.tar.gz chromium_src-dab95c4c528c5509c7f426d55ba913b9ad038159.tar.bz2 |
Fixes a memory leak when running webrtc-internals for a long time, by using a circular buffer of size 1k for stats data points. Also explicitly draws the graph time labels 1min apart in a 5min range.
BUG=230250
Review URL: https://chromiumcodereview.appspot.com/14880002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199008 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 15 insertions, 36 deletions
diff --git a/content/browser/resources/media/data_series.js b/content/browser/resources/media/data_series.js index f32c822..3dfad4e 100644 --- a/content/browser/resources/media/data_series.js +++ b/content/browser/resources/media/data_series.js @@ -6,6 +6,8 @@ * A TimelineDataSeries collects an ordered series of (time, value) pairs, * and converts them to graph points. It also keeps track of its color and * current visibility state. + * It keeps MAX_STATS_DATA_POINT_BUFFER_SIZE data points at most. Old data + * points will be dropped when it reaches this size. */ var TimelineDataSeries = (function() { 'use strict'; @@ -35,6 +37,9 @@ var TimelineDataSeries = (function() { addPoint: function(timeTicks, value) { var time = new Date(timeTicks); this.dataPoints_.push(new DataPoint(time, value)); + + if (this.dataPoints_.length > MAX_STATS_DATA_POINT_BUFFER_SIZE) + this.dataPoints_.shift(); }, isVisible: function() { diff --git a/content/browser/resources/media/stats_graph_helper.js b/content/browser/resources/media/stats_graph_helper.js index 33146f9..ddeb5d3 100644 --- a/content/browser/resources/media/stats_graph_helper.js +++ b/content/browser/resources/media/stats_graph_helper.js @@ -140,7 +140,10 @@ function drawSingleReport(peerConnectionElement, report) { // both the simple and compound graph cases. if (!graphViews[graphViewId].hasDataSeries(dataSeries[finalDataSeriesId])) graphViews[graphViewId].addDataSeries(dataSeries[finalDataSeriesId]); - graphViews[graphViewId].updateEndDate(); + // Draw the stats of the last 5 minutes. + graphViews[graphViewId].setDateRange( + new Date(singleReport.timestamp - 1000 * 60 * 5), + new Date(singleReport.timestamp)); } } diff --git a/content/browser/resources/media/timeline_graph_view.js b/content/browser/resources/media/timeline_graph_view.js index bb3557d..89b557e 100644 --- a/content/browser/resources/media/timeline_graph_view.js +++ b/content/browser/resources/media/timeline_graph_view.js @@ -214,41 +214,8 @@ var TimelineGraphView = (function() { * time range. */ drawTimeLabels: function(context, width, height, textHeight, startTime) { - // Text for a time string to use in determining how far apart - // to place text labels. - var sampleText = (new Date(startTime)).toLocaleTimeString(); - - // The desired spacing for text labels. - var targetSpacing = context.measureText(sampleText).width + - LABEL_LABEL_HORIZONTAL_SPACING; - - // The allowed time step values between adjacent labels. Anything much - // over a couple minutes isn't terribly realistic, given how much memory - // we use, and how slow a lot of the net-internals code is. - var timeStepValues = [ - 1000, // 1 second - 1000 * 5, - 1000 * 30, - 1000 * 60, // 1 minute - 1000 * 60 * 5, - 1000 * 60 * 30, - 1000 * 60 * 60, // 1 hour - 1000 * 60 * 60 * 5 - ]; - - // Find smallest time step value that gives us at least |targetSpacing|, - // if any. - var timeStep = null; - for (var i = 0; i < timeStepValues.length; ++i) { - if (timeStepValues[i] / DEFAULT_SCALE >= targetSpacing) { - timeStep = timeStepValues[i]; - break; - } - } - - // If no such value, give up. - if (!timeStep) - return; + // Draw the labels 1 minute apart. + var timeStep = 1000 * 60; // Find the time for the first label. This time is a perfect multiple of // timeStep because of how UTC times work. diff --git a/content/browser/resources/media/webrtc_internals.js b/content/browser/resources/media/webrtc_internals.js index 4cef1a4..6dd1bb1 100644 --- a/content/browser/resources/media/webrtc_internals.js +++ b/content/browser/resources/media/webrtc_internals.js @@ -9,6 +9,10 @@ var peerConnectionUpdateTable = null; var statsTable = null; var dumpCreator = null; +// The maximum number of data points bufferred for each stats. Old data points +// will be shifted out when the buffer is full. +var MAX_STATS_DATA_POINT_BUFFER_SIZE = 1000; + <include src="ssrc_info_manager.js"/> <include src="stats_graph_helper.js"/> <include src="stats_table.js"/> |