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

docs: add primer on viewing the timing data #6393

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions docs/hacking-tips.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
A few assorted scripts and tips to make hacking on Lighthouse a bit easier

## Evaluate Lighthouse's runtime performance

Lighthouse has instrumentation to collect timing data for its operations. The data is exposed at `LHR.timing.entries`. You can generate a trace from this data for closer analysis.

![image](https://user-images.githubusercontent.com/39191/47525915-3c477000-d853-11e8-90a2-27036f93e682.png)
[View example trace](https://ahead-daughter.surge.sh/paulirish.json.timing.trace.html)

To generate, run `yarn timing-trace` with the LHR json:
```sh
lighthouse http://example.com --output=json --output-path=lhr.json
yarn timing-trace lhr.json
```

That will generate `lhr.json.timing.trace.json`. Then, drag 'n drop that file into `chrome://tracing`.

## Unhandled promise rejections

Getting errors like these?
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class GatherRunner {

const status = {
msg: 'Loading page & waiting for onload',
id: 'lh:gather:loadPage',
id: `lh:gather:loadPage-${passContext.passConfig.passName}`,
args: [gatherers.map(g => g.instance.name).join(', ')],
};
log.time(status);
Expand Down Expand Up @@ -271,8 +271,8 @@ class GatherRunner {
gathererResult.push(artifactPromise);
gathererResults[gatherer.name] = gathererResult;
await artifactPromise.catch(() => {});
log.timeEnd(status);
}
log.timeEnd(status);
log.timeEnd(pStatus);
}

Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ class Runner {
const timingEntriesKeyValues = [
...timingEntriesFromArtifacts,
...timingEntriesFromRunner,
].map(entry => /** @type {[string, PerformanceEntry]} */ ([entry.name, entry]));
// As entries can share a name, dedupe based on the startTime timestamp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

].map(entry => /** @type {[number, PerformanceEntry]} */ ([entry.startTime, entry]));
const timingEntries = Array.from(new Map(timingEntriesKeyValues).values());
const runnerEntry = timingEntries.find(e => e.name === 'lh:runner:run');
return {entries: timingEntries, total: runnerEntry && runnerEntry.duration || 0};
Expand Down