Skip to content

Commit

Permalink
Move groups & tasks to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Nov 19, 2017
1 parent 56e68a0 commit 6044966
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 179 deletions.
95 changes: 7 additions & 88 deletions lighthouse-core/audits/bootup-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,8 @@

const Audit = require('./audit');
const WebInspector = require('../lib/web-inspector');
const Util = require('../report/v2/renderer/util.js');

const group = {
loading: 'Network request loading',
parseHTML: 'Parsing DOM',
styleLayout: 'Style & Layout',
compositing: 'Compositing',
painting: 'Paint',
gpu: 'GPU',
scripting: 'Script Evaluation',
scriptParseCompile: 'Script Parsing & Compile',
scriptGC: 'Garbage collection',
other: 'Other',
images: 'Images',
};
const taskToGroup = {
'Animation': group.painting,
'Async Task': group.other,
'Frame Start': group.painting,
'Frame Start (main thread)': group.painting,
'Cancel Animation Frame': group.scripting,
'Cancel Idle Callback': group.scripting,
'Compile Script': group.scriptParseCompile,
'Composite Layers': group.compositing,
'Console Time': group.scripting,
'Image Decode': group.images,
'Draw Frame': group.painting,
'Embedder Callback': group.scripting,
'Evaluate Script': group.scripting,
'Event': group.scripting,
'Animation Frame Fired': group.scripting,
'Fire Idle Callback': group.scripting,
'Function Call': group.scripting,
'DOM GC': group.scriptGC,
'GC Event': group.scriptGC,
'GPU': group.gpu,
'Hit Test': group.compositing,
'Invalidate Layout': group.styleLayout,
'JS Frame': group.scripting,
'Input Latency': group.scripting,
'Layout': group.styleLayout,
'Major GC': group.scriptGC,
'DOMContentLoaded event': group.scripting,
'First paint': group.painting,
'FMP': group.painting,
'FMP candidate': group.painting,
'Load event': group.scripting,
'Minor GC': group.scriptGC,
'Paint': group.painting,
'Paint Image': group.images,
'Paint Setup': group.painting,
'Parse Stylesheet': group.parseHTML,
'Parse HTML': group.parseHTML,
'Parse Script': group.scriptParseCompile,
'Other': group.other,
'Rasterize Paint': group.painting,
'Recalculate Style': group.styleLayout,
'Request Animation Frame': group.scripting,
'Request Idle Callback': group.scripting,
'Request Main Thread Frame': group.painting,
'Image Resize': group.images,
'Finish Loading': group.loading,
'Receive Data': group.loading,
'Receive Response': group.loading,
'Send Request': group.loading,
'Run Microtasks': group.scripting,
'Schedule Style Recalculation': group.styleLayout,
'Scroll': group.compositing,
'Task': group.other,
'Timer Fired': group.scripting,
'Install Timer': group.scripting,
'Remove Timer': group.scripting,
'Timestamp': group.scripting,
'Update Layer': group.compositing,
'Update Layer Tree': group.compositing,
'User Timing': group.scripting,
'Create WebSocket': group.scripting,
'Destroy WebSocket': group.scripting,
'Receive WebSocket Handshake': group.scripting,
'Send WebSocket Handshake': group.scripting,
'XHR Load': group.scripting,
'XHR Ready State Change': group.scripting,
};
const Util = require('../report/v2/renderer/util');
const {groups, taskToGroup} = require('../lib/task-groups');

class BootupTime extends Audit {
/**
Expand Down Expand Up @@ -126,7 +45,7 @@ class BootupTime extends Audit {
// eventStyle() returns a string like 'Evaluate Script'
const task = WebInspector.TimelineUIUtils.eventStyle(perTaskPerUrlNode.event);
// Resolve which taskGroup we're using
const groupName = taskToGroup[task.title] || group.other;
const groupName = taskToGroup[task.title] || groups.other;
const groupTotal = taskGroups[groupName] || 0;
taskGroups[groupName] = groupTotal + (perTaskPerUrlNode.selfTime || 0);
});
Expand All @@ -149,8 +68,8 @@ class BootupTime extends Audit {

const headings = [
{key: 'url', itemType: 'url', text: 'URL'},
{key: 'scripting', itemType: 'text', text: group.scripting},
{key: 'scriptParseCompile', itemType: 'text', text: group.scriptParseCompile},
{key: 'scripting', itemType: 'text', text: groups.scripting},
{key: 'scriptParseCompile', itemType: 'text', text: groups.scriptParseCompile},
];

// map data in correct format to create a table
Expand All @@ -159,8 +78,8 @@ class BootupTime extends Audit {
totalBootupTime += Object.keys(groups).reduce((sum, name) => sum += groups[name], 0);
extendedInfo[url] = groups;

const scriptingTotal = groups[group.scripting] || 0;
const parseCompileTotal = groups[group.scriptParseCompile] || 0;
const scriptingTotal = groups[groups.scripting] || 0;
const parseCompileTotal = groups[groups.scriptParseCompile] || 0;
return {
url: url,
sum: scriptingTotal + parseCompileTotal,
Expand Down
84 changes: 1 addition & 83 deletions lighthouse-core/audits/mainthread-work-breakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,90 +12,8 @@

const Audit = require('./audit');
const Util = require('../report/v2/renderer/util');

// We group all trace events into groups to show a highlevel breakdown of the page
const group = {
loading: 'Network request loading',
parseHTML: 'Parsing DOM',
styleLayout: 'Style & Layout',
compositing: 'Compositing',
painting: 'Paint',
gpu: 'GPU',
scripting: 'Script Evaluation',
scriptParseCompile: 'Script Parsing & Compile',
scriptGC: 'Garbage collection',
other: 'Other',
images: 'Images',
};

const taskToGroup = {
'Animation': group.painting,
'Async Task': group.other,
'Frame Start': group.painting,
'Frame Start (main thread)': group.painting,
'Cancel Animation Frame': group.scripting,
'Cancel Idle Callback': group.scripting,
'Compile Script': group.scriptParseCompile,
'Composite Layers': group.compositing,
'Console Time': group.scripting,
'Image Decode': group.images,
'Draw Frame': group.painting,
'Embedder Callback': group.scripting,
'Evaluate Script': group.scripting,
'Event': group.scripting,
'Animation Frame Fired': group.scripting,
'Fire Idle Callback': group.scripting,
'Function Call': group.scripting,
'DOM GC': group.scriptGC,
'GC Event': group.scriptGC,
'GPU': group.gpu,
'Hit Test': group.compositing,
'Invalidate Layout': group.styleLayout,
'JS Frame': group.scripting,
'Input Latency': group.scripting,
'Layout': group.styleLayout,
'Major GC': group.scriptGC,
'DOMContentLoaded event': group.scripting,
'First paint': group.painting,
'FMP': group.painting,
'FMP candidate': group.painting,
'Load event': group.scripting,
'Minor GC': group.scriptGC,
'Paint': group.painting,
'Paint Image': group.images,
'Paint Setup': group.painting,
'Parse Stylesheet': group.parseHTML,
'Parse HTML': group.parseHTML,
'Parse Script': group.scriptParseCompile,
'Other': group.other,
'Rasterize Paint': group.painting,
'Recalculate Style': group.styleLayout,
'Request Animation Frame': group.scripting,
'Request Idle Callback': group.scripting,
'Request Main Thread Frame': group.painting,
'Image Resize': group.images,
'Finish Loading': group.loading,
'Receive Data': group.loading,
'Receive Response': group.loading,
'Send Request': group.loading,
'Run Microtasks': group.scripting,
'Schedule Style Recalculation': group.styleLayout,
'Scroll': group.compositing,
'Task': group.other,
'Timer Fired': group.scripting,
'Install Timer': group.scripting,
'Remove Timer': group.scripting,
'Timestamp': group.scripting,
'Update Layer': group.compositing,
'Update Layer Tree': group.compositing,
'User Timing': group.scripting,
'Create WebSocket': group.scripting,
'Destroy WebSocket': group.scripting,
'Receive WebSocket Handshake': group.scripting,
'Send WebSocket Handshake': group.scripting,
'XHR Load': group.scripting,
'XHR Ready State Change': group.scripting,
};
const {taskToGroup} = require('../lib/task-groups');

class PageExecutionTimings extends Audit {
/**
Expand Down
94 changes: 94 additions & 0 deletions lighthouse-core/lib/task-groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @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 groups = {
loading: 'Network request loading',
parseHTML: 'Parsing HTML & CSS',
styleLayout: 'Style & Layout',
compositing: 'Compositing',
painting: 'Paint',
gpu: 'GPU',
scripting: 'Script Evaluation',
scriptParseCompile: 'Script Parsing & Compile',
scriptGC: 'Garbage collection',
other: 'Other',
images: 'Images',
};

const taskToGroup = {
'Animation': groups.painting,
'Async Task': groups.other,
'Frame Start': groups.painting,
'Frame Start (main thread)': groups.painting,
'Cancel Animation Frame': groups.scripting,
'Cancel Idle Callback': groups.scripting,
'Compile Script': groups.scriptParseCompile,
'Composite Layers': groups.compositing,
'Console Time': groups.scripting,
'Image Decode': groups.images,
'Draw Frame': groups.painting,
'Embedder Callback': groups.scripting,
'Evaluate Script': groups.scripting,
'Event': groups.scripting,
'Animation Frame Fired': groups.scripting,
'Fire Idle Callback': groups.scripting,
'Function Call': groups.scripting,
'DOM GC': groups.scriptGC,
'GC Event': groups.scriptGC,
'GPU': groups.gpu,
'Hit Test': groups.compositing,
'Invalidate Layout': groups.styleLayout,
'JS Frame': groups.scripting,
'Input Latency': groups.scripting,
'Layout': groups.styleLayout,
'Major GC': groups.scriptGC,
'DOMContentLoaded event': groups.scripting,
'First paint': groups.painting,
'FMP': groups.painting,
'FMP candidate': groups.painting,
'Load event': groups.scripting,
'Minor GC': groups.scriptGC,
'Paint': groups.painting,
'Paint Image': groups.images,
'Paint Setup': groups.painting,
'Parse Stylesheet': groups.parseHTML,
'Parse HTML': groups.parseHTML,
'Parse Script': groups.scriptParseCompile,
'Other': groups.other,
'Rasterize Paint': groups.painting,
'Recalculate Style': groups.styleLayout,
'Request Animation Frame': groups.scripting,
'Request Idle Callback': groups.scripting,
'Request Main Thread Frame': groups.painting,
'Image Resize': groups.images,
'Finish Loading': groups.loading,
'Receive Data': groups.loading,
'Receive Response': groups.loading,
'Send Request': groups.loading,
'Run Microtasks': groups.scripting,
'Schedule Style Recalculation': groups.styleLayout,
'Scroll': groups.compositing,
'Task': groups.other,
'Timer Fired': groups.scripting,
'Install Timer': groups.scripting,
'Remove Timer': groups.scripting,
'Timestamp': groups.scripting,
'Update Layer': groups.compositing,
'Update Layer Tree': groups.compositing,
'User Timing': groups.scripting,
'Create WebSocket': groups.scripting,
'Destroy WebSocket': groups.scripting,
'Receive WebSocket Handshake': groups.scripting,
'Send WebSocket Handshake': groups.scripting,
'XHR Load': groups.scripting,
'XHR Ready State Change': groups.scripting,
};

module.exports = {
groups,
taskToGroup,
};
17 changes: 9 additions & 8 deletions lighthouse-core/test/audits/bootup-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const BootupTime = require('../../audits/bootup-time.js');
const DevtoolsTimelineGather = require('../../gather/computed/devtools-timeline-model');
const assert = require('assert');
const {groups} = require('../../lib/task-groups');

const devtoolsTimelineGather = new DevtoolsTimelineGather({});

Expand Down Expand Up @@ -39,14 +40,14 @@ describe('Performance: bootup-time audit', () => {
return roundedValue;
};

assert.deepEqual(roundedValueOf('https://www.google-analytics.com/analytics.js'), {'Script Evaluation': 40.1, 'Script Parsing & Compile': 9.6, 'Style & Layout': 0.2});
assert.deepEqual(roundedValueOf('https://pwa.rocks/script.js'), {'Script Evaluation': 31.8, 'Style & Layout': 5.5, 'Script Parsing & Compile': 1.3});
assert.deepEqual(roundedValueOf('https://www.googletagmanager.com/gtm.js?id=GTM-Q5SW'), {'Script Evaluation': 25, 'Script Parsing & Compile': 5.5, 'Style & Layout': 1.2});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/plugins/ua/linkid.js'), {'Script Evaluation': 25.2, 'Script Parsing & Compile': 1.2});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/cx/api.js?experiment=jdCfRmudTmy-0USnJ8xPbw'), {'Script Parsing & Compile': 3, 'Script Evaluation': 1.2});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/cx/api.js?experiment=qvpc5qIfRC2EMnbn6bbN5A'), {'Script Parsing & Compile': 2.5, 'Script Evaluation': 1});
assert.deepEqual(roundedValueOf('https://pwa.rocks/'), {'Parsing DOM': 14.2, 'Script Evaluation': 6.1, 'Script Parsing & Compile': 1.2});
assert.deepEqual(roundedValueOf('https://pwa.rocks/0ff789bf.js'), {'Parsing DOM': 0});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/analytics.js'), {[groups.scripting]: 40.1, [groups.scriptParseCompile]: 9.6, [groups.styleLayout]: 0.2});
assert.deepEqual(roundedValueOf('https://pwa.rocks/script.js'), {[groups.scripting]: 31.8, [groups.styleLayout]: 5.5, [groups.scriptParseCompile]: 1.3});
assert.deepEqual(roundedValueOf('https://www.googletagmanager.com/gtm.js?id=GTM-Q5SW'), {[groups.scripting]: 25, [groups.scriptParseCompile]: 5.5, [groups.styleLayout]: 1.2});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/plugins/ua/linkid.js'), {[groups.scripting]: 25.2, [groups.scriptParseCompile]: 1.2});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/cx/api.js?experiment=jdCfRmudTmy-0USnJ8xPbw'), {[groups.scriptParseCompile]: 3, [groups.scripting]: 1.2});
assert.deepEqual(roundedValueOf('https://www.google-analytics.com/cx/api.js?experiment=qvpc5qIfRC2EMnbn6bbN5A'), {[groups.scriptParseCompile]: 2.5, [groups.scripting]: 1});
assert.deepEqual(roundedValueOf('https://pwa.rocks/'), {[groups.parseHTML]: 14.2, [groups.scripting]: 6.1, [groups.scriptParseCompile]: 1.2});
assert.deepEqual(roundedValueOf('https://pwa.rocks/0ff789bf.js'), {[groups.parseHTML]: 0});
});
});

Expand Down

0 comments on commit 6044966

Please sign in to comment.