Bug 1127322 - Create helper function for converting allocation sites data from the memory actor to samples similar to the profiler data, r=fitzgen

This commit is contained in:
Victor Porof 2015-01-29 13:37:55 -05:00
Родитель 1bdcff6e82
Коммит d14c15d8bf
3 изменённых файлов: 120 добавлений и 0 удалений

Просмотреть файл

@ -57,3 +57,43 @@ exports.RecordingUtils.offsetMarkerTimes = function(markers, timeOffset) {
marker.end -= timeOffset;
}
}
/**
* Converts allocation data from the memory actor to something that follows
* the same structure as the samples data received from the profiler.
*
* @see MemoryActor.prototype.getAllocations for more information.
*
* @param object allocations
* A list of { sites, timestamps, frames, counts } arrays.
* @return array
* The samples data.
*/
exports.RecordingUtils.getSamplesFromAllocations = function(allocations) {
let { sites, timestamps, frames, counts } = allocations;
let samples = [];
for (let i = 0, len = sites.length; i < len; i++) {
let site = sites[i];
let timestamp = timestamps[i];
let frame = frames[site];
let count = counts[site];
let sample = { time: timestamp, frames: [] };
samples.push(sample);
while (frame) {
sample.frames.push({
location: frame.source + ":" + frame.line + ":" + frame.column,
allocations: count
});
site = frame.parent;
frame = frames[site];
count = counts[site];
}
sample.frames.reverse();
}
return samples;
}

Просмотреть файл

@ -9,6 +9,7 @@ support-files =
# that need to be moved over to performance tool
[browser_perf-aaa-run-first-leaktest.js]
[browser_perf-allocations-to-samples.js]
[browser_perf-data-massaging-01.js]
[browser_perf-data-samples.js]
[browser_perf-details-calltree-render.js]

Просмотреть файл

@ -0,0 +1,79 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if allocations data received from the memory actor is properly
* converted to something that follows the same structure as the samples data
* received from the profiler.
*/
function test() {
let { RecordingUtils } = devtools.require("devtools/performance/recording-utils");
let output = RecordingUtils.getSamplesFromAllocations(TEST_DATA);
is(output.toSource(), EXPECTED_OUTPUT.toSource(), "The output is correct.");
finish();
}
let TEST_DATA = {
sites: [0, 0, 1, 2, 3],
timestamps: [50, 100, 150, 200, 250],
frames: [
null,
{
source: "A",
line: 1,
column: 2,
parent: 0
},
{
source: "B",
line: 3,
column: 4,
parent: 1
},
{
source: "C",
line: 5,
column: 6,
parent: 2
}
],
counts: [11, 22, 33, 44]
};
let EXPECTED_OUTPUT = [{
time: 50,
frames: []
}, {
time: 100,
frames: []
}, {
time: 150,
frames: [{
location: "A:1:2",
allocations: 22
}]
}, {
time: 200,
frames: [{
location: "A:1:2",
allocations: 22
}, {
location: "B:3:4",
allocations: 33
}]
}, {
time: 250,
frames: [{
location: "A:1:2",
allocations: 22
}, {
location: "B:3:4",
allocations: 33
}, {
location: "C:5:6",
allocations: 44
}]
}];