зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1034651 - The framerate front's `plotFPS` should be a static method, r=pbrosset
This commit is contained in:
Родитель
4eed9cf8c9
Коммит
1d81b115df
|
@ -121,58 +121,57 @@ let FramerateFront = exports.FramerateFront = protocol.FrontClass(FramerateActor
|
|||
initialize: function(client, { framerateActor }) {
|
||||
protocol.Front.prototype.initialize.call(this, client, { actor: framerateActor });
|
||||
this.manage(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Plots the frames per second on a timeline.
|
||||
*
|
||||
* @param array ticks
|
||||
* The raw data received from the framerate actor, which represents
|
||||
* the elapsed time on each refresh driver tick.
|
||||
* @param number interval
|
||||
* The maximum amount of time to wait between calculations.
|
||||
* @param number clamp
|
||||
* The maximum allowed framerate value.
|
||||
* @return array
|
||||
* A collection of { delta, value } objects representing the
|
||||
* framerate value at every delta time.
|
||||
*/
|
||||
plotFPS: function(ticks, interval = 100, clamp = 60) {
|
||||
let timeline = [];
|
||||
let totalTicks = ticks.length;
|
||||
|
||||
// If the refresh driver didn't get a chance to tick before the
|
||||
// recording was stopped, assume framerate was 0.
|
||||
if (totalTicks == 0) {
|
||||
timeline.push({ delta: 0, value: 0 });
|
||||
timeline.push({ delta: interval, value: 0 });
|
||||
return timeline;
|
||||
}
|
||||
|
||||
let frameCount = 0;
|
||||
let prevTime = ticks[0];
|
||||
|
||||
for (let i = 1; i < totalTicks; i++) {
|
||||
let currTime = ticks[i];
|
||||
frameCount++;
|
||||
|
||||
let elapsedTime = currTime - prevTime;
|
||||
if (elapsedTime < interval) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let framerate = Math.min(1000 / (elapsedTime / frameCount), clamp);
|
||||
timeline.push({ delta: prevTime, value: framerate });
|
||||
timeline.push({ delta: currTime, value: framerate });
|
||||
|
||||
frameCount = 0;
|
||||
prevTime = currTime;
|
||||
}
|
||||
|
||||
return timeline;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Plots the frames per second on a timeline.
|
||||
*
|
||||
* @param array ticks
|
||||
* The raw data received from the framerate actor, which represents
|
||||
* the elapsed time on each refresh driver tick.
|
||||
* @param number interval
|
||||
* The maximum amount of time to wait between calculations.
|
||||
* @param number clamp
|
||||
* The maximum allowed framerate value.
|
||||
* @return array
|
||||
* A collection of { delta, value } objects representing the
|
||||
* framerate value at every delta time.
|
||||
*/
|
||||
FramerateFront.plotFPS = function(ticks, interval = 100, clamp = 60) {
|
||||
let timeline = [];
|
||||
let totalTicks = ticks.length;
|
||||
|
||||
// If the refresh driver didn't get a chance to tick before the
|
||||
// recording was stopped, assume framerate was 0.
|
||||
if (totalTicks == 0) {
|
||||
timeline.push({ delta: 0, value: 0 });
|
||||
timeline.push({ delta: interval, value: 0 });
|
||||
return timeline;
|
||||
}
|
||||
|
||||
let frameCount = 0;
|
||||
let prevTime = ticks[0];
|
||||
|
||||
for (let i = 1; i < totalTicks; i++) {
|
||||
let currTime = ticks[i];
|
||||
frameCount++;
|
||||
|
||||
let elapsedTime = currTime - prevTime;
|
||||
if (elapsedTime < interval) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let framerate = Math.min(1000 / (elapsedTime / frameCount), clamp);
|
||||
timeline.push({ delta: prevTime, value: framerate });
|
||||
timeline.push({ delta: currTime, value: framerate });
|
||||
|
||||
frameCount = 0;
|
||||
prevTime = currTime;
|
||||
}
|
||||
|
||||
return timeline;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the top level browser window from a content window.
|
||||
|
|
|
@ -58,7 +58,7 @@ window.onload = function() {
|
|||
function onRecordingStopped(front, rawData) {
|
||||
ok(rawData, "There should be a recording available.");
|
||||
|
||||
var timeline = front.plotFPS(rawData);
|
||||
var timeline = FramerateFront.plotFPS(rawData);
|
||||
ok(timeline.length >= 2,
|
||||
"There should be at least one measurement available, with two entries.");
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ window.onload = function() {
|
|||
ok(rawData, "There should be a recording available.");
|
||||
is(rawData.length, 0, "...but it should be empty.");
|
||||
|
||||
var timeline = front.plotFPS(rawData);
|
||||
var timeline = FramerateFront.plotFPS(rawData);
|
||||
is(timeline.length, 2,
|
||||
"There should be one measurement plotted, with two entries.");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче