Skip to content

Commit

Permalink
perf: tracingModel to computed artifact (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored and brendankenny committed Feb 8, 2017
1 parent 4e66001 commit ec5fbe3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 17 deletions.
13 changes: 7 additions & 6 deletions lighthouse-core/audits/estimated-input-latency.js
Expand Up @@ -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));

Expand Down Expand Up @@ -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));
}
}

Expand Down
17 changes: 6 additions & 11 deletions lighthouse-core/audits/time-to-interactive.js
Expand Up @@ -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;

Expand Down
41 changes: 41 additions & 0 deletions 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;
30 changes: 30 additions & 0 deletions 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');
});
});

0 comments on commit ec5fbe3

Please sign in to comment.