Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
239 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* @license Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const Audit = require('../../audits/audit.js'); | ||
const TraceOfTab = require('../trace-of-tab.js'); | ||
const Speedline = require('../speedline.js'); | ||
const FirstContentfulPaint = require('./first-contentful-paint.js'); | ||
const FirstMeaningfulPaint = require('./first-meaningful-paint.js'); | ||
const LargestContentfulPaint = require('./largest-contentful-paint.js'); | ||
const FirstCPUIdle = require('./first-cpu-idle.js'); | ||
const Interactive = require('./interactive.js'); | ||
const SpeedIndex = require('./speed-index.js'); | ||
const EstimatedInputLatency = require('./estimated-input-latency.js'); | ||
const TotalBlockingTime = require('./total-blocking-time.js'); | ||
|
||
class TimingSummary { | ||
/** | ||
* @param {LH.Artifacts} artifacts | ||
* @param {LH.Audit.Context} context | ||
* @return {Promise<{metrics: LH.Artifacts.TimingSummary, debugInfo: Array<Record<string,boolean>>}>} | ||
*/ | ||
static async summarize(artifacts, context) { | ||
const trace = artifacts.traces[Audit.DEFAULT_PASS]; | ||
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS]; | ||
const settings = context.settings; | ||
const metricComputationData = {trace, devtoolsLog, settings}; | ||
|
||
/** | ||
* @template TArtifacts | ||
* @template TReturn | ||
* @param {{request: (artifact: TArtifacts, context: LH.Audit.Context) => Promise<TReturn>}} Artifact | ||
* @param {TArtifacts} artifact | ||
* @return {Promise<TReturn|undefined>} | ||
*/ | ||
const requestOrUndefined = (Artifact, artifact) => { | ||
return Artifact.request(artifact, context).catch(_ => undefined); | ||
}; | ||
|
||
const traceOfTab = await TraceOfTab.request(trace, context); | ||
const speedline = await Speedline.request(trace, context); | ||
const firstContentfulPaint = await FirstContentfulPaint.request(metricComputationData, context); | ||
const firstMeaningfulPaint = await FirstMeaningfulPaint.request(metricComputationData, context); | ||
const largestContentfulPaint = await requestOrUndefined(LargestContentfulPaint, metricComputationData); // eslint-disable-line max-len | ||
const firstCPUIdle = await requestOrUndefined(FirstCPUIdle, metricComputationData); | ||
const interactive = await requestOrUndefined(Interactive, metricComputationData); | ||
const speedIndex = await requestOrUndefined(SpeedIndex, metricComputationData); | ||
const estimatedInputLatency = await EstimatedInputLatency.request(metricComputationData, context); // eslint-disable-line max-len | ||
const totalBlockingTime = await TotalBlockingTime.request(metricComputationData, context); // eslint-disable-line max-len | ||
|
||
/** @type {LH.Artifacts.TimingSummary} */ | ||
const metrics = { | ||
// Include the simulated/observed performance metrics | ||
firstContentfulPaint: firstContentfulPaint.timing, | ||
firstContentfulPaintTs: firstContentfulPaint.timestamp, | ||
firstMeaningfulPaint: firstMeaningfulPaint.timing, | ||
firstMeaningfulPaintTs: firstMeaningfulPaint.timestamp, | ||
largestContentfulPaint: largestContentfulPaint && largestContentfulPaint.timing, | ||
largestContentfulPaintTs: largestContentfulPaint && largestContentfulPaint.timestamp, | ||
firstCPUIdle: firstCPUIdle && firstCPUIdle.timing, | ||
firstCPUIdleTs: firstCPUIdle && firstCPUIdle.timestamp, | ||
interactive: interactive && interactive.timing, | ||
interactiveTs: interactive && interactive.timestamp, | ||
speedIndex: speedIndex && speedIndex.timing, | ||
speedIndexTs: speedIndex && speedIndex.timestamp, | ||
estimatedInputLatency: estimatedInputLatency.timing, | ||
estimatedInputLatencyTs: estimatedInputLatency.timestamp, | ||
totalBlockingTime: totalBlockingTime.timing, | ||
|
||
// Include all timestamps of interest from trace of tab | ||
observedNavigationStart: traceOfTab.timings.navigationStart, | ||
observedNavigationStartTs: traceOfTab.timestamps.navigationStart, | ||
observedFirstPaint: traceOfTab.timings.firstPaint, | ||
observedFirstPaintTs: traceOfTab.timestamps.firstPaint, | ||
observedFirstContentfulPaint: traceOfTab.timings.firstContentfulPaint, | ||
observedFirstContentfulPaintTs: traceOfTab.timestamps.firstContentfulPaint, | ||
observedFirstMeaningfulPaint: traceOfTab.timings.firstMeaningfulPaint, | ||
observedFirstMeaningfulPaintTs: traceOfTab.timestamps.firstMeaningfulPaint, | ||
observedLargestContentfulPaint: traceOfTab.timings.largestContentfulPaint, | ||
observedLargestContentfulPaintTs: traceOfTab.timestamps.largestContentfulPaint, | ||
observedTraceEnd: traceOfTab.timings.traceEnd, | ||
observedTraceEndTs: traceOfTab.timestamps.traceEnd, | ||
observedLoad: traceOfTab.timings.load, | ||
observedLoadTs: traceOfTab.timestamps.load, | ||
observedDomContentLoaded: traceOfTab.timings.domContentLoaded, | ||
observedDomContentLoadedTs: traceOfTab.timestamps.domContentLoaded, | ||
|
||
// Include some visual metrics from speedline | ||
observedFirstVisualChange: speedline.first, | ||
observedFirstVisualChangeTs: (speedline.first + speedline.beginning) * 1000, | ||
observedLastVisualChange: speedline.complete, | ||
observedLastVisualChangeTs: (speedline.complete + speedline.beginning) * 1000, | ||
observedSpeedIndex: speedline.speedIndex, | ||
observedSpeedIndexTs: (speedline.speedIndex + speedline.beginning) * 1000, | ||
}; | ||
/** @type {Array<Record<string,boolean>>} */ | ||
const debugInfo = [{lcpInvalidated: trace.lcpInvalidated}]; | ||
|
||
return {metrics, debugInfo}; | ||
} | ||
} | ||
|
||
module.exports = TimingSummary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
lighthouse-core/test/computed/metrics/timing-summary-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @license Copyright 2019 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const TimingSummary = require('../../../computed/metrics/timing-summary.js'); | ||
|
||
const trace = require('../../fixtures/traces/progressive-app-m60.json'); | ||
const devtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json'); | ||
|
||
/* eslint-env jest */ | ||
describe('Timing summary', () => { | ||
it('contains the correct data', async () => { | ||
const artifacts = { | ||
traces: {defaultPass: trace}, | ||
devtoolsLogs: {defaultPass: devtoolsLog}, | ||
}; | ||
const context = {settings: {throttlingMethod: 'simulate'}, computedCache: new Map()}; | ||
const result = await TimingSummary.summarize(artifacts, context); | ||
|
||
expect(result.metrics).toMatchInlineSnapshot(` | ||
Object { | ||
"estimatedInputLatency": 77.79999999999995, | ||
"estimatedInputLatencyTs": undefined, | ||
"firstCPUIdle": 3351.3320000492968, | ||
"firstCPUIdleTs": undefined, | ||
"firstContentfulPaint": 1306.6100000208244, | ||
"firstContentfulPaintTs": undefined, | ||
"firstMeaningfulPaint": 1510.6100000208241, | ||
"firstMeaningfulPaintTs": undefined, | ||
"interactive": 3426.8545000551967, | ||
"interactiveTs": undefined, | ||
"largestContentfulPaint": undefined, | ||
"largestContentfulPaintTs": undefined, | ||
"observedDomContentLoaded": 560.294, | ||
"observedDomContentLoadedTs": 225414732309, | ||
"observedFirstContentfulPaint": 498.87, | ||
"observedFirstContentfulPaintTs": 225414670885, | ||
"observedFirstMeaningfulPaint": 783.328, | ||
"observedFirstMeaningfulPaintTs": 225414955343, | ||
"observedFirstPaint": 498.853, | ||
"observedFirstPaintTs": 225414670868, | ||
"observedFirstVisualChange": 520, | ||
"observedFirstVisualChangeTs": 225414692015, | ||
"observedLargestContentfulPaint": undefined, | ||
"observedLargestContentfulPaintTs": undefined, | ||
"observedLastVisualChange": 818, | ||
"observedLastVisualChangeTs": 225414990015, | ||
"observedLoad": 2198.898, | ||
"observedLoadTs": 225416370913, | ||
"observedNavigationStart": 0, | ||
"observedNavigationStartTs": 225414172015, | ||
"observedSpeedIndex": 604.7093900063634, | ||
"observedSpeedIndexTs": 225414776724.39, | ||
"observedTraceEnd": 12539.872, | ||
"observedTraceEndTs": 225426711887, | ||
"speedIndex": 1656.6335047609864, | ||
"speedIndexTs": undefined, | ||
"totalBlockingTime": 726.4774999940996, | ||
} | ||
`); | ||
// Includes performance metrics | ||
expect(result.metrics.firstContentfulPaint).toBeDefined(); | ||
// Includes timestamps from trace of tab | ||
expect(result.metrics.observedFirstContentfulPaint).toBeDefined(); | ||
// Includs visual metrics from Speedline | ||
expect(result.metrics.observedFirstVisualChange).toBeDefined(); | ||
|
||
expect(result.debugInfo).toEqual([{'lcpInvalidated': undefined}]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.