Skip to content

Commit 4ef3c98

Browse files
committed
support collecting network records per pass
1 parent 1fb77ae commit 4ef3c98

23 files changed

+221
-82
lines changed

lighthouse-core/audits/audit.js

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

19-
const DEFAULT_TRACE = 'defaultPass';
19+
const DEFAULT_PASS = 'defaultPass';
2020

2121
class Audit {
2222
/**
2323
* @return {!String}
2424
*/
25-
static get DEFAULT_TRACE() {
26-
return DEFAULT_TRACE;
25+
static get DEFAULT_PASS() {
26+
return DEFAULT_PASS;
2727
}
2828

2929
/**

lighthouse-core/audits/critical-request-chains.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class CriticalRequestChains extends Audit {
4040
* @return {!AuditResult} The score from the audit, ranging from 0-100.
4141
*/
4242
static audit(artifacts) {
43-
return artifacts.requestCriticalRequestChains(artifacts.networkRecords).then(chains => {
43+
const networkRecord = artifacts.networkRecords[Audit.DEFAULT_PASS];
44+
return artifacts.requestCriticalRequestChains(networkRecord).then(chains => {
4445
let chainCount = 0;
4546
function walk(node, depth) {
4647
const children = Object.keys(node);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class EstimatedInputLatency extends Audit {
7979
* @return {!Promise<!AuditResult>} The score from the audit, ranging from 0-100.
8080
*/
8181
static audit(artifacts) {
82-
const trace = artifacts.traces[this.DEFAULT_TRACE];
82+
const trace = artifacts.traces[this.DEFAULT_PASS];
8383

8484
return artifacts.requestSpeedline(trace)
8585
.then(speedline => EstimatedInputLatency.calculate(speedline, trace))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FirstMeaningfulPaint extends Audit {
5353
*/
5454
static audit(artifacts) {
5555
return new Promise((resolve, reject) => {
56-
const traceContents = artifacts.traces[this.DEFAULT_TRACE].traceEvents;
56+
const traceContents = artifacts.traces[this.DEFAULT_PASS].traceEvents;
5757
if (!traceContents || !Array.isArray(traceContents)) {
5858
throw new Error(FAILURE_MESSAGE);
5959
}

lighthouse-core/audits/screenshots.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Screenshots extends Audit {
3838
* @return {!Promise<!AuditResult>}
3939
*/
4040
static audit(artifacts) {
41-
const trace = artifacts.traces[this.DEFAULT_TRACE];
41+
const trace = artifacts.traces[this.DEFAULT_PASS];
4242
if (typeof trace === 'undefined') {
4343
return Promise.resolve(Screenshots.generateAuditResult({
4444
rawValue: -1,

lighthouse-core/audits/speed-index-metric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SpeedIndexMetric extends Audit {
4747
* @return {!Promise<!AuditResult>} The score from the audit, ranging from 0-100.
4848
*/
4949
static audit(artifacts) {
50-
const trace = artifacts.traces[this.DEFAULT_TRACE];
50+
const trace = artifacts.traces[this.DEFAULT_PASS];
5151
if (typeof trace === 'undefined') {
5252
return SpeedIndexMetric.generateAuditResult({
5353
rawValue: -1,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TTIMetric extends Audit {
5757
* @return {!Promise<!AuditResult>} The score from the audit, ranging from 0-100.
5858
*/
5959
static audit(artifacts) {
60-
const trace = artifacts.traces[Audit.DEFAULT_TRACE];
60+
const trace = artifacts.traces[Audit.DEFAULT_PASS];
6161
const pendingSpeedline = artifacts.requestSpeedline(trace);
6262
const pendingFMP = FMPMetric.audit(artifacts);
6363

@@ -74,7 +74,7 @@ class TTIMetric extends Audit {
7474

7575
// Process the trace
7676
const tracingProcessor = new TracingProcessor();
77-
const trace = artifacts.traces[Audit.DEFAULT_TRACE];
77+
const trace = artifacts.traces[Audit.DEFAULT_PASS];
7878
const model = tracingProcessor.init(trace);
7979
const endOfTraceTime = model.bounds.max;
8080

lighthouse-core/audits/user-timings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class UserTimings extends Audit {
129129
static audit(artifacts) {
130130
return new Promise((resolve, reject) => {
131131
const traceContents =
132-
artifacts.traces[this.DEFAULT_TRACE] &&
133-
artifacts.traces[this.DEFAULT_TRACE].traceEvents;
132+
artifacts.traces[this.DEFAULT_PASS] &&
133+
artifacts.traces[this.DEFAULT_PASS].traceEvents;
134134
if (!traceContents || !Array.isArray(traceContents)) {
135135
throw new Error(FAILURE_MESSAGE);
136136
}

lighthouse-core/closure/typedefs/Artifacts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Artifacts.prototype.HTTPS;
3838
/** @type {!Array<!Object>} */
3939
Artifacts.prototype.traces;
4040

41+
/** @type {!Object<!Array>} */
42+
Artifacts.prototype.networkRecords;
43+
4144
/** @type {!ManifestNode<(!Manifest|undefined)>} */
4245
Artifacts.prototype.Manifest;
4346

lighthouse-core/config/config.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const recordsFromLogs = require('../lib/network-recorder').recordsFromLogs;
2222
const GatherRunner = require('../gather/gather-runner');
2323
const log = require('../lib/log');
2424
const path = require('path');
25+
const Audit = require('../audits/audit');
2526

2627
// cleanTrace is run to remove duplicate TracingStartedInPage events,
2728
// and to change TracingStartedInBrowser events into TracingStartedInPage.
@@ -122,6 +123,21 @@ function validatePasses(passes, audits, rootPath) {
122123
}
123124
});
124125
});
126+
127+
// Log if multiple passes require trace or network data and could overwrite one another.
128+
const usedNames = new Set();
129+
passes.forEach((pass, index) => {
130+
if (!pass.network && !pass.trace) {
131+
return;
132+
}
133+
134+
const passName = pass.traceName || Audit.DEFAULT_PASS;
135+
if (usedNames.has(passName)) {
136+
log.warn('config', `passes[${index}] may overwrite trace or network ` +
137+
`data of earlier pass without a unique traceName (repeated name: ${passName}.`);
138+
}
139+
usedNames.add(passName);
140+
});
125141
}
126142

127143
function getGatherersNeededByAudits(audits) {
@@ -238,8 +254,21 @@ function expandArtifacts(artifacts) {
238254
artifacts.traces[key] = trace;
239255
});
240256
}
257+
241258
if (artifacts.performanceLog) {
242-
artifacts.networkRecords = recordsFromLogs(require(artifacts.performanceLog));
259+
if (typeof artifacts.performanceLog === 'string') {
260+
// Support older format of a single performance log.
261+
const log = require(artifacts.performanceLog);
262+
artifacts.networkRecords = {
263+
[Audit.DEFAULT_PASS]: recordsFromLogs(log)
264+
};
265+
} else {
266+
artifacts.networkRecords = {};
267+
Object.keys(artifacts.performanceLog).forEach(key => {
268+
const log = require(artifacts.performanceLog[key]);
269+
artifacts.networkRecords[key] = recordsFromLogs(log);
270+
});
271+
}
243272
}
244273

245274
return artifacts;

0 commit comments

Comments
 (0)