More firefox import fixes (#128)

This commit is contained in:
Jamie Wong
2018-08-08 17:15:33 -07:00
committed by GitHub
parent 182563dc7c
commit fc9260ba1d
8 changed files with 133 additions and 23 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
<script src="./recursion.js"></script>

View File

@@ -0,0 +1,41 @@
function alpha(depth) {
if (depth > 15 * Math.random()) {
return
}
beta(depth + 1)
delta()
gamma()
}
function beta(depth) {
alpha(depth + 1)
for (let i = 0; i < 10; i++) {
gamma()
}
}
function delta() {
for (let i = 0; i < 10; i++) {
gamma()
}
}
function gamma() {
let prod = 1
for (let i = 1; i < 1000; i++) {
prod *= i
}
return prod
}
function main() {
for (let i = 0; i < 100; i++) {
alpha(0)
}
}
console.profile('recursion')
main()
setTimeout(() => {
console.profileEnd('recursion')
}, 0)

View File

@@ -1,23 +1,23 @@
function a() {
function alpha() {
for (let i = 0; i < 1000; i++) {
b()
c()
beta()
delta()
}
}
function b() {
function beta() {
for (let i = 0; i < 10; i++) {
d()
gamma()
}
}
function c() {
function delta() {
for (let i = 0; i < 10; i++) {
d()
gamma()
}
}
function d() {
function gamma() {
let prod = 1
for (let i = 1; i < 1000; i++) {
prod *= i
@@ -25,10 +25,8 @@ function d() {
return prod
}
console.profile('a')
a()
console.profile('simple')
alpha()
setTimeout(() => {
console.profileEnd('a')
console.profileEnd('simple')
}, 0)
window.addEventListener('click', a)

View File

@@ -57,3 +57,66 @@ Object {
],
}
`;
exports[`importFromFirefox recursion 1`] = `
Object {
"frames": Array [
Frame {
"col": undefined,
"file": "file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js",
"key": "main (file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js:31)",
"line": 31,
"name": "main",
"selfWeight": 1.1944820000207983,
"totalWeight": 11.149112000013702,
},
Frame {
"col": undefined,
"file": "file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js",
"key": "alpha (file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js:1)",
"line": 1,
"name": "alpha",
"selfWeight": 0,
"totalWeight": 9.954629999992903,
},
Frame {
"col": undefined,
"file": "file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js",
"key": "beta (file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js:10)",
"line": 10,
"name": "beta",
"selfWeight": 0,
"totalWeight": 8.962158999987878,
},
Frame {
"col": undefined,
"file": "file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js",
"key": "delta (file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js:17)",
"line": 17,
"name": "delta",
"selfWeight": 0,
"totalWeight": 6.859736999962479,
},
Frame {
"col": undefined,
"file": "file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js",
"key": "gamma (file:///Users/jlfwong/code/speedscope/sample/programs/javascript/recursion.js:23)",
"line": 23,
"name": "gamma",
"selfWeight": 9.954629999992903,
"totalWeight": 9.954629999992903,
},
],
"stacks": Array [
"main;alpha;beta;alpha;beta;alpha;beta;alpha;delta;gamma 998.89µs",
"main 1.19ms",
"main;alpha;beta;alpha;delta;gamma 1.83ms",
"main;alpha;beta;alpha;beta;alpha;beta;gamma 1.16ms",
"main;alpha;beta;alpha;delta;gamma 1.84ms",
"main;alpha;beta;alpha;beta;alpha;beta;alpha;gamma 964.81µs",
"main;alpha;beta;alpha;beta;alpha;beta;alpha;delta;gamma 1.19ms",
"main;alpha;beta;gamma 965.25µs",
"main;alpha;delta;gamma 992.47µs",
],
}
`;

View File

@@ -3,3 +3,7 @@ import {checkProfileSnapshot} from '../lib/test-utils'
test('importFromFirefox', async () => {
await checkProfileSnapshot('./sample/profiles/Firefox/59/simple-firefox.json')
})
test('importFromFirefox recursion', async () => {
await checkProfileSnapshot('./sample/profiles/Firefox/61/recursion.json')
})

View File

@@ -1,5 +1,5 @@
import {Profile, FrameInfo, CallTreeProfileBuilder} from '../lib/profile'
import {getOrInsert, lastOf} from '../lib/utils'
import {getOrInsert} from '../lib/utils'
import {TimeFormatter} from '../lib/value-formatters'
interface Allocations {
@@ -203,25 +203,22 @@ export function importFromFirefox(firefoxProfile: FirefoxProfile): Profile {
const value = sample[1]
// Find lowest common ancestor of the current stack and the previous one
let lca: FrameInfo | null = null
let lcaIndex = -1
for (let i = 0; i < Math.min(stack.length, prevStack.length); i++) {
if (prevStack[i] !== stack[i]) {
break
}
lca = stack[i]
lcaIndex = i
}
// Close frames that are no longer open
while (prevStack.length > 0 && (!lca || lastOf(prevStack) !== lca)) {
const closingFrame = prevStack.pop()!
profile.leaveFrame(closingFrame, value)
for (let i = prevStack.length - 1; i > lcaIndex; i--) {
profile.leaveFrame(prevStack[i], value)
}
// Open frames that are now becoming open
for (let i = lca ? stack.indexOf(lca) + 1 : 0; i < stack.length; i++) {
const frame = stack[i]
profile.enterFrame(frame, value)
for (let i = lcaIndex + 1; i < stack.length; i++) {
profile.enterFrame(stack[i], value)
}
prevStack = stack

View File

@@ -586,6 +586,11 @@ export class CallTreeProfileBuilder extends Profile {
}
build(): Profile {
// Each stack is expected to contain a single node which we initialize to be
// the root node.
if (this.appendOrderStack.length > 1 || this.groupedOrderStack.length > 1) {
throw new Error('Tried to complete profile construction with a non-empty stack')
}
return this
}
}