Skip to content

Commit 1275762

Browse files
surmapaulirish
authored andcommitted
Trace buckets (#531)
* Allow each pass to save its own trace
1 parent 50c3ced commit 1275762

File tree

16 files changed

+110
-47
lines changed

16 files changed

+110
-47
lines changed

lighthouse-core/audits/audit.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616
*/
1717
'use strict';
1818

19+
const DEFAULT_TRACE = 'defaultPass';
20+
1921
class Audit {
22+
/**
23+
* @return {!String}
24+
*/
25+
static get DEFAULT_TRACE() {
26+
return DEFAULT_TRACE;
27+
}
28+
2029
/**
2130
* @return {!AuditMeta}
2231
*/

lighthouse-core/audits/estimated-input-latency.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ class EstimatedInputLatency extends Audit {
5050
// Use speedline's first paint as start of range for input latency check.
5151
const startTime = artifacts.Speedline.first;
5252

53-
const trace = artifacts.traceContents;
53+
const trace = artifacts.traces[this.DEFAULT_TRACE] &&
54+
artifacts.traces[this.DEFAULT_TRACE].traceContents;
5455
const tracingProcessor = new TracingProcessor();
55-
const model = tracingProcessor.init(artifacts.traceContents);
56+
const model = tracingProcessor.init(trace);
5657
const latencyPercentiles = TracingProcessor.getRiskToResponsiveness(model, trace, startTime);
5758

5859
const ninetieth = latencyPercentiles.find(result => result.percentile === 0.9);

lighthouse-core/audits/first-meaningful-paint.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ class FirstMeaningfulPaint extends Audit {
5353
*/
5454
static audit(artifacts) {
5555
return new Promise((resolve, reject) => {
56-
if (!artifacts.traceContents || !Array.isArray(artifacts.traceContents)) {
56+
const traceContents = artifacts.traces[this.DEFAULT_TRACE].traceContents;
57+
if (!traceContents || !Array.isArray(traceContents)) {
5758
throw new Error(FAILURE_MESSAGE);
5859
}
5960

60-
const evts = this.collectEvents(artifacts.traceContents);
61+
const evts = this.collectEvents(traceContents);
6162

6263
const navStart = evts.navigationStart;
6364
const fCP = evts.firstContentfulPaint;

lighthouse-core/audits/time-to-interactive.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class TTIMetric extends Audit {
6868

6969
// Process the trace
7070
const tracingProcessor = new TracingProcessor();
71-
const model = tracingProcessor.init(artifacts.traceContents);
71+
const traceContents = artifacts.traces[Audit.DEFAULT_TRACE].traceContents;
72+
const model = tracingProcessor.init(traceContents);
7273
const endOfTraceTime = model.bounds.max;
7374

7475
// TODO: Wait for DOMContentLoadedEndEvent
@@ -109,7 +110,7 @@ class TTIMetric extends Audit {
109110
}
110111
// Get our expected latency for the time window
111112
const latencies = TracingProcessor.getRiskToResponsiveness(
112-
model, artifacts.traceContents, startTime, endTime, percentiles);
113+
model, traceContents, startTime, endTime, percentiles);
113114
const estLatency = latencies[0].time.toFixed(2);
114115
foundLatencies.push({
115116
estLatency: estLatency,

lighthouse-core/audits/user-timings.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ class UserTimings extends Audit {
128128
*/
129129
static audit(artifacts) {
130130
return new Promise((resolve, reject) => {
131-
if (!artifacts.traceContents || !Array.isArray(artifacts.traceContents)) {
131+
const traceContents =
132+
artifacts.traces[this.DEFAULT_TRACE] &&
133+
artifacts.traces[this.DEFAULT_TRACE].traceContents;
134+
if (!traceContents || !Array.isArray(traceContents)) {
132135
throw new Error(FAILURE_MESSAGE);
133136
}
134137

135-
const userTimings = filterTrace(artifacts.traceContents);
136-
138+
const userTimings = filterTrace(traceContents);
137139
resolve(UserTimings.generateAuditResult({
138140
rawValue: userTimings.length,
139141
extendedInfo: {

lighthouse-core/closure/typedefs/Artifacts.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ Artifacts.prototype.HTMLWithoutJavaScript;
3636
Artifacts.prototype.HTTPS;
3737

3838
/** @type {!Array<!Object>} */
39-
Artifacts.prototype.networkRecords;
40-
41-
/** @type {?} */
42-
Artifacts.prototype.traceContents;
39+
Artifacts.prototype.traces;
4340

4441
/** @type {!ManifestNode<(!Manifest|undefined)>} */
4542
Artifacts.prototype.Manifest;

lighthouse-core/config/default.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"passes": [{
33
"network": true,
44
"trace": true,
5-
"loadDataName": "first-pass",
65
"loadPage": true,
76
"gatherers": [
87
"url",

lighthouse-core/config/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ function expandArtifacts(artifacts) {
100100
const expandedArtifacts = Object.assign({}, artifacts);
101101

102102
// currently only trace logs and performance logs should be imported
103-
if (artifacts.traceContents) {
104-
expandedArtifacts.traceContents = require(artifacts.traceContents);
103+
if (artifacts.traces) {
104+
Object.keys(artifacts.traces).forEach(key => {
105+
if (artifacts.traces[key].traceContents) {
106+
expandedArtifacts.traces[key].traceContents =
107+
require(artifacts.traces[key].traceContents);
108+
}
109+
});
105110
}
106111
if (artifacts.performanceLog) {
107112
expandedArtifacts.CriticalRequestChains =

lighthouse-core/driver/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
'use strict';
1818

1919
const log = require('../lib/log.js');
20+
const Audit = require('../audits/audit');
2021

2122
class Driver {
22-
2323
static loadPage(driver, options) {
2424
// Since a Page.reload command does not let a service worker take over, we
2525
// navigate away and then come back to reload. We do not `waitForLoad` on
@@ -107,15 +107,19 @@ class Driver {
107107
const driver = options.driver;
108108
const config = options.config;
109109
const gatherers = config.gatherers;
110-
const loadData = {};
110+
const loadData = {traces: {}};
111111
let pass = Promise.resolve();
112+
let traceName = Audit.DEFAULT_TRACE;
113+
if (config.traceName) {
114+
traceName = config.traceName;
115+
}
112116

113117
if (config.trace) {
114118
pass = pass.then(_ => {
115-
log.log('status', 'Gathering: trace');
119+
log.log('status', `Gathering: trace "${traceName}"`);
116120
return driver.endTrace().then(traceContents => {
117-
loadData.traceContents = traceContents;
118-
log.log('statusEnd', 'Gathering: trace');
121+
loadData.traces[traceName] = {traceContents};
122+
log.log('statusEnd', `Gathering: trace "${traceName}"`);
119123
});
120124
});
121125
}
@@ -136,6 +140,9 @@ class Driver {
136140
return chain.then(_ => {
137141
const status = `Gathering: ${gatherer.name}`;
138142
log.log('status', status);
143+
if (config.trace) {
144+
loadData.traceContents = loadData.traces[traceName].traceContents;
145+
}
139146
return Promise.resolve(gatherer.afterPass(options, loadData)).then(ret => {
140147
log.log('statusEnd', status);
141148
return ret;
@@ -155,7 +162,7 @@ class Driver {
155162

156163
static run(passes, options) {
157164
const driver = options.driver;
158-
const tracingData = {};
165+
const tracingData = {traces: {}};
159166

160167
if (typeof options.url !== 'string' || options.url.length === 0) {
161168
return Promise.reject(new Error('You must provide a url to the driver'));
@@ -190,6 +197,9 @@ class Driver {
190197
.then(_ => this.pass(runOptions))
191198
.then(_ => this.afterPass(runOptions))
192199
.then(loadData => {
200+
// Need to manually merge traces property before
201+
// merging loadDat into tracingData to avoid data loss.
202+
Object.assign(loadData.traces, tracingData.traces);
193203
Object.assign(tracingData, loadData);
194204
})
195205
.then(_ => this.tearDown(runOptions));
@@ -212,7 +222,6 @@ class Driver {
212222
artifacts[gatherer.name] = gatherer.artifact;
213223
});
214224
});
215-
216225
return artifacts;
217226
});
218227
}

lighthouse-core/test/audits/estimated-input-latency.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const traceContents = require('../fixtures/traces/progressive-app.json');
2424
describe('Performance: estimated-input-latency audit', () => {
2525
it('scores a -1 with invalid trace data', () => {
2626
const output = Audit.audit({
27-
traceContents: '[{"pid": 15256,"tid": 1295,"t',
27+
traces: {[Audit.DEFAULT_TRACE]: {traceContents: '[{"pid": 15256,"tid": 1295,"t'}},
2828
Speedline: {
2929
first: 500
3030
}
@@ -35,7 +35,7 @@ describe('Performance: estimated-input-latency audit', () => {
3535

3636
it('evaluates valid input correctly', () => {
3737
const output = Audit.audit({
38-
traceContents,
38+
traces: {[Audit.DEFAULT_TRACE]: {traceContents}},
3939
Speedline: {
4040
first: 500
4141
}

0 commit comments

Comments
 (0)