Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: enable async stacks #5504

Merged
merged 4 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lighthouse-core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ class PageDependencyGraph {
static getNetworkInitiators(record) {
if (!record.initiator) return [];
if (record.initiator.url) return [record.initiator.url];
if (record.initiator.type === 'script' && record.initiator.stack) {
const frames = record.initiator.stack.callFrames;
return Array.from(new Set(frames.map(frame => frame.url))).filter(Boolean);
if (record.initiator.type === 'script') {
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
/** @type {Set<string>} */
const scriptURLs = new Set();
for (let stack = record.initiator.stack; stack; stack = stack.parent) {
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
const callFrames = stack.callFrames || [];
for (const frame of callFrames) {
if (frame.url) scriptURLs.add(frame.url);
}
}

return Array.from(scriptURLs);
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
}

return [];
Expand Down
12 changes: 9 additions & 3 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,6 @@ class Driver {
const uniqueCategories = Array.from(new Set(traceCategories));

// Check any domains that could interfere with or add overhead to the trace.
if (this.isDomainEnabled('Debugger')) {
throw new Error('Debugger domain enabled when starting trace');
}
if (this.isDomainEnabled('CSS')) {
throw new Error('CSS domain enabled when starting trace');
}
Expand Down Expand Up @@ -1401,6 +1398,15 @@ class Driver {
return this.sendCommand('Runtime.enable');
}

/**
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
* @return {Promise<void>}
*/
async enableAsyncStacks() {
await this.sendCommand('Debugger.enable');
await this.sendCommand('Debugger.setSkipAllPauses', {skip: true});
await this.sendCommand('Debugger.setAsyncCallStackDepth', {maxDepth: 8});
}

/**
* @param {LH.Config.Settings} settings
* @return {Promise<void>}
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Driver = require('../gather/driver.js'); // eslint-disable-line no-unused-
* i. assertNoSameOriginServiceWorkerClients
* ii. retrieve and save userAgent
* iii. beginEmulation
* iv. enableRuntimeEvents
* iv. enableRuntimeEvents/enableAsyncStacks
* v. evaluateScriptOnLoad rescue native Promise from potential polyfill
* vi. register a performance observer
* vii. register dialog dismisser
Expand Down Expand Up @@ -108,6 +108,7 @@ class GatherRunner {
await driver.assertNoSameOriginServiceWorkerClients(options.requestedUrl);
await driver.beginEmulation(options.settings);
await driver.enableRuntimeEvents();
await driver.enableAsyncStacks();
await driver.cacheNatives();
await driver.registerPerformanceObserver();
await driver.dismissJavaScriptDialogs();
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/test/gather/fake-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function makeFakeDriver({protocolGetVersionResponse}) {
enableRuntimeEvents() {
return Promise.resolve();
},
enableAsyncStacks() {
return Promise.resolve();
},
evaluateScriptOnLoad() {
return Promise.resolve();
},
Expand Down
5 changes: 5 additions & 0 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function getMockedEmulationDriver(emulationFn, netThrottleFn, cpuThrottleFn,
enableRuntimeEvents() {
return Promise.resolve();
}
enableAsyncStacks() {
return Promise.resolve();
}
assertNoSameOriginServiceWorkerClients() {
return Promise.resolve();
}
Expand Down Expand Up @@ -360,6 +363,7 @@ describe('GatherRunner', function() {
setThrottling: asyncFunc,
dismissJavaScriptDialogs: asyncFunc,
enableRuntimeEvents: asyncFunc,
enableAsyncStacks: asyncFunc,
cacheNatives: asyncFunc,
gotoURL: asyncFunc,
registerPerformanceObserver: asyncFunc,
Expand Down Expand Up @@ -419,6 +423,7 @@ describe('GatherRunner', function() {
setThrottling: asyncFunc,
dismissJavaScriptDialogs: asyncFunc,
enableRuntimeEvents: asyncFunc,
enableAsyncStacks: asyncFunc,
cacheNatives: asyncFunc,
gotoURL: asyncFunc,
registerPerformanceObserver: asyncFunc,
Expand Down