-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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(metrics): move FMP to computed artifact #4951
Changes from 3 commits
192e659
060179f
91611cc
63a2f22
339d05e
74724d4
e94a99e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @license Copyright 2018 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('./audit'); | ||
|
||
class Metrics extends Audit { | ||
/** | ||
* @return {!AuditMeta} | ||
*/ | ||
static get meta() { | ||
return { | ||
name: 'metrics', | ||
informative: true, | ||
description: 'Metrics', | ||
helpText: 'Collects all available metrics.', | ||
requiredArtifacts: ['traces', 'devtoolsLogs'], | ||
}; | ||
} | ||
|
||
/** | ||
* @param {!Artifacts} artifacts | ||
* @return {!AuditResult} | ||
*/ | ||
static async audit(artifacts, context) { | ||
const trace = artifacts.traces[Audit.DEFAULT_PASS]; | ||
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS]; | ||
const metricComputationData = {trace, devtoolsLog, settings: context.settings}; | ||
|
||
const traceOfTab = await artifacts.requestTraceOfTab(trace); | ||
const firstContentfulPaint = await artifacts.requestFirstContentfulPaint(metricComputationData); | ||
const firstMeaningfulPaint = await artifacts.requestFirstMeaningfulPaint(metricComputationData); | ||
const timeToInteractive = await artifacts.requestConsistentlyInteractive(metricComputationData); | ||
const metrics = []; | ||
|
||
// Include the simulated/observed performance metrics | ||
const metricsMap = {firstContentfulPaint, firstMeaningfulPaint, timeToInteractive}; | ||
for (const [metricName, values] of Object.entries(metricsMap)) { | ||
metrics.push(Object.assign({metricName}, values)); | ||
} | ||
|
||
// Include all timestamps of interest from trace of tab | ||
for (const [traceEventName, timing] of Object.entries(traceOfTab.timings)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const uppercased = traceEventName.slice(0, 1).toUpperCase() + traceEventName.slice(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol no hope of inferring type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure there is! :D string -> string -> string + string -> string => string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha, I meant of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh lol, yes :) |
||
const metricName = `trace${uppercased}`; | ||
const timestamp = traceOfTab.timestamps[traceEventName]; | ||
metrics.push({metricName, timing, timestamp}); | ||
} | ||
|
||
const headings = [ | ||
{key: 'metricName', itemType: 'text', text: 'Name'}, | ||
{key: 'timing', itemType: 'ms', granularity: 10, text: 'Value (ms)'}, | ||
]; | ||
|
||
const tableDetails = Audit.makeTableDetails(headings, metrics); | ||
|
||
return { | ||
score: 1, | ||
rawValue: timeToInteractive.timing, | ||
details: tableDetails, | ||
}; | ||
} | ||
} | ||
|
||
module.exports = Metrics; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @license Copyright 2018 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 MetricArtifact = require('./metric'); | ||
const LHError = require('../../../lib/errors'); | ||
|
||
class FirstMeaningfulPaint extends MetricArtifact { | ||
get name() { | ||
return 'FirstMeaningfulPaint'; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @return {Promise<LH.Artifacts.Metric>} | ||
*/ | ||
computeObservedMetric(data) { | ||
const {traceOfTab} = data; | ||
if (!traceOfTab.timestamps.firstMeaningfulPaint) { | ||
throw new LHError(LHError.errors.NO_FMP); | ||
} | ||
|
||
return Promise.resolve({ | ||
timing: traceOfTab.timings.firstMeaningfulPaint, | ||
timestamp: traceOfTab.timestamps.firstMeaningfulPaint, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = FirstMeaningfulPaint; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ class TraceOfTab extends ComputedArtifact { | |
firstMeaningfulPaint = lastCandidate; | ||
} | ||
|
||
const onLoad = frameEvents.find(e => e.name === 'loadEventEnd' && e.ts > navigationStart.ts); | ||
const load = frameEvents.find(e => e.name === 'loadEventEnd' && e.ts > navigationStart.ts); | ||
const domContentLoaded = frameEvents.find( | ||
e => e.name === 'domContentLoadedEventEnd' && e.ts > navigationStart.ts | ||
); | ||
|
@@ -116,7 +116,7 @@ class TraceOfTab extends ComputedArtifact { | |
firstContentfulPaint, | ||
firstMeaningfulPaint, | ||
traceEnd: {ts: traceEnd.ts + (traceEnd.dur || 0)}, | ||
onLoad, | ||
load, | ||
domContentLoaded, | ||
}; | ||
|
||
|
@@ -138,7 +138,8 @@ class TraceOfTab extends ComputedArtifact { | |
firstPaintEvt: firstPaint, | ||
firstContentfulPaintEvt: firstContentfulPaint, | ||
firstMeaningfulPaintEvt: firstMeaningfulPaint, | ||
onLoadEvt: onLoad, | ||
loadEvt: load, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will you add the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
domContentLoadedEvt: domContentLoaded, | ||
fmpFellBack, | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done