From ff21a33a4343ffe8205e0aa3f3bce304ef2560a0 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Tue, 2 May 2017 17:47:14 -0700 Subject: [PATCH] fix: only record a trace if needed by an audit (#2117) --- lighthouse-core/config/config.js | 9 +++++++++ lighthouse-core/test/config/config-test.js | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index fa30a9917915..0aa32e3d972d 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -487,6 +487,7 @@ class Config { * @return {!Object} fresh passes object */ static generatePassesNeededByGatherers(oldPasses, requiredGatherers) { + const auditsNeedTrace = requiredGatherers.has('traces'); const passes = JSON.parse(JSON.stringify(oldPasses)); const filteredPasses = passes.map(pass => { // remove any unncessary gatherers from within the passes @@ -494,6 +495,14 @@ class Config { gathererName = GatherRunner.getGathererClass(gathererName).name; return requiredGatherers.has(gathererName); }); + + // disable the trace if no audit requires a trace + if (pass.recordTrace && !auditsNeedTrace) { + const passName = pass.passName || 'unknown pass'; + log.warn('config', `Trace not requested by an audit, dropping trace in ${passName}`); + pass.recordTrace = false; + } + return pass; }).filter(pass => { // remove any passes lacking concrete gatherers, unless they are dependent on the trace diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index 95bc990f2771..8965822ecceb 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -304,12 +304,31 @@ describe('Config', () => { assert.ok(config.audits.length, 3); assert.equal(config.passes.length, 2); + assert.ok(config.passes[0].recordTrace, 'preserves recordTrace pass'); assert.ok(!config.categories['unused-category'], 'removes unused categories'); assert.equal(config.categories['needed-category'].audits.length, 2); assert.equal(config.categories['other-category'].audits.length, 1); }); - it('filtering works with extension', () => { + it('filtering filters out traces when not needed', () => { + const warnings = []; + const saveWarning = evt => warnings.push(evt); + log.events.addListener('warning', saveWarning); + const config = new Config({ + extends: true, + settings: { + onlyCategories: ['accessibility'], + }, + }); + + log.events.removeListener('warning', saveWarning); + assert.ok(config.audits.length, 'inherited audits by extension'); + assert.equal(config.passes.length, 1, 'filtered out passes'); + assert.equal(warnings.length, 1, 'warned about dropping trace'); + assert.equal(config.passes[0].recordTrace, false, 'turns off tracing if not needed'); + }); + + it('filters works with extension', () => { const config = new Config({ extends: true, settings: {