diff --git a/lighthouse-core/audits/estimated-input-latency.js b/lighthouse-core/audits/estimated-input-latency.js index 640f35d8b0df..9569c14e9f70 100644 --- a/lighthouse-core/audits/estimated-input-latency.js +++ b/lighthouse-core/audits/estimated-input-latency.js @@ -44,14 +44,11 @@ class EstimatedInputLatency extends Audit { }; } - static calculate(speedline, trace) { + static calculate(speedline, model, trace) { // Use speedline's first paint as start of range for input latency check. const startTime = speedline.first; - const tracingProcessor = new TracingProcessor(); - const model = tracingProcessor.init(trace); const latencyPercentiles = TracingProcessor.getRiskToResponsiveness(model, trace, startTime); - const ninetieth = latencyPercentiles.find(result => result.percentile === 0.9); const rawValue = parseFloat(ninetieth.time.toFixed(1)); @@ -86,8 +83,12 @@ class EstimatedInputLatency extends Audit { static audit(artifacts) { const trace = artifacts.traces[this.DEFAULT_PASS]; - return artifacts.requestSpeedline(trace) - .then(speedline => EstimatedInputLatency.calculate(speedline, trace)); + const pending = [ + artifacts.requestSpeedline(trace), + artifacts.requestTracingModel(trace) + ]; + return Promise.all(pending).then(([speedline, model]) => + EstimatedInputLatency.calculate(speedline, model, trace)); } } diff --git a/lighthouse-core/audits/time-to-interactive.js b/lighthouse-core/audits/time-to-interactive.js index 1b4b17a27fbe..00bf9c8b0734 100644 --- a/lighthouse-core/audits/time-to-interactive.js +++ b/lighthouse-core/audits/time-to-interactive.js @@ -63,20 +63,15 @@ class TTIMetric extends Audit { */ static audit(artifacts) { const trace = artifacts.traces[Audit.DEFAULT_PASS]; - const pendingSpeedline = artifacts.requestSpeedline(trace); - const pendingFMP = FMPMetric.audit(artifacts); // We start looking at Math.Max(FMPMetric, visProgress[0.85]) - return Promise.all([pendingSpeedline, pendingFMP]).then(results => { - const speedline = results[0]; - const fmpResult = results[1]; - - // Process the trace - const tracingProcessor = new TracingProcessor(); - const trace = artifacts.traces[Audit.DEFAULT_PASS]; - const model = tracingProcessor.init(trace); + const pending = [ + artifacts.requestSpeedline(trace), + FMPMetric.audit(artifacts), + artifacts.requestTracingModel(trace) + ]; + return Promise.all(pending).then(([speedline, fmpResult, model]) => { const endOfTraceTime = model.bounds.max; - const fmpTiming = fmpResult.rawValue; const fmpResultExt = fmpResult.extendedInfo.value; diff --git a/lighthouse-core/gather/computed/tracing-model.js b/lighthouse-core/gather/computed/tracing-model.js new file mode 100644 index 000000000000..f12dc985b5d8 --- /dev/null +++ b/lighthouse-core/gather/computed/tracing-model.js @@ -0,0 +1,41 @@ +/** + * @license + * Copyright 2017 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 ComputedArtifact = require('./computed-artifact'); +const TracingProcessor = require('../../lib/traces/tracing-processor'); + +class TracingModel extends ComputedArtifact { + + get name() { + return 'TracingModel'; + } + + /** + * Return catapult traceviewer model + * @param {{traceEvents: !Array}} trace + * @return {!TracingProcessorModel} + */ + compute_(trace) { + const tracingProcessor = new TracingProcessor(); + return tracingProcessor.init(trace); + } + +} + +module.exports = TracingModel; diff --git a/lighthouse-core/test/gather/computed/tracing-model-test.js b/lighthouse-core/test/gather/computed/tracing-model-test.js new file mode 100644 index 000000000000..82dccd721dd5 --- /dev/null +++ b/lighthouse-core/test/gather/computed/tracing-model-test.js @@ -0,0 +1,30 @@ +/** + * Copyright 2017 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 TracingModel = require('../../../gather/computed/tracing-model'); + +const assert = require('assert'); +const pwaTrace = require('../../fixtures/traces/progressive-app.json'); + +/* eslint-env mocha */ +describe('Tracing model computed artifact:', () => { + it('gets a tracing model', () => { + const tracingModel = new TracingModel(); + const model = tracingModel.compute_(pwaTrace); + assert.ok(model instanceof global.tr.Model, 'return is not an instance of tr.Model'); + }); +});