Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
core(tracehouse): modify files for move to tracehouse
  • Loading branch information
patrickhulce committed Jun 5, 2019
1 parent 9f80524 commit 1af2edd
Show file tree
Hide file tree
Showing 23 changed files with 280 additions and 105 deletions.
2 changes: 1 addition & 1 deletion docs/architecture.md
Expand Up @@ -39,7 +39,7 @@ driver.sendCommand('Security.enable');

## Understanding a Trace

`lighthouse-core/computed/trace-of-tab.js` and `lighthouse-core/lib/traces/tracing-processor.js` provide the core transformation of a trace into more meaningful objects. Each raw trace event has a monotonically increasing timestamp in microseconds, a thread ID, a process ID, a duration in microseconds (potentially), and other applicable metadata properties such as the event type, the task name, the frame, etc. [Learn more about trace events](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview).
`lighthouse-core/lib/tracehouse/trace-of-tab.js` and `lighthouse-core/lib/tracehouse/tracing-processor.js` provide the core transformation of a trace into more meaningful objects. Each raw trace event has a monotonically increasing timestamp in microseconds, a thread ID, a process ID, a duration in microseconds (potentially), and other applicable metadata properties such as the event type, the task name, the frame, etc. [Learn more about trace events](https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview).

### Example Trace Event
```js
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/bootup-time.js
Expand Up @@ -7,7 +7,7 @@

const Audit = require('./audit.js');
const NetworkRequest = require('../lib/network-request.js');
const {taskGroups} = require('../lib/task-groups.js');
const {taskGroups} = require('../lib/tracehouse/task-groups.js');
const i18n = require('../lib/i18n/i18n.js');
const NetworkRecords = require('../computed/network-records.js');
const MainThreadTasks = require('../computed/main-thread-tasks.js');
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/mainthread-work-breakdown.js
Expand Up @@ -11,7 +11,7 @@
'use strict';

const Audit = require('./audit.js');
const {taskGroups} = require('../lib/task-groups.js');
const {taskGroups} = require('../lib/tracehouse/task-groups.js');
const i18n = require('../lib/i18n/i18n.js');
const MainThreadTasks = require('../computed/main-thread-tasks.js');

Expand All @@ -29,7 +29,7 @@ const UIStrings = {

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);

/** @typedef {import('../lib/task-groups.js').TaskGroupIds} TaskGroupIds */
/** @typedef {import('../lib/tracehouse/task-groups.js').TaskGroupIds} TaskGroupIds */

class MainThreadWorkBreakdown extends Audit {
/**
Expand Down
24 changes: 24 additions & 0 deletions lighthouse-core/computed/main-thread-tasks.js
@@ -0,0 +1,24 @@
/**
* @license Copyright 2019 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 makeComputedArtifact = require('./computed-artifact.js');
const MainThreadTasks_ = require('../lib/tracehouse/main-thread-tasks.js');
const TraceOfTab = require('./trace-of-tab.js');

class MainThreadTasks {
/**
* @param {LH.Trace} trace
* @param {LH.Audit.Context} context
* @return {Promise<Array<LH.Artifacts.TaskNode>>}
*/
static async compute_(trace, context) {
const {mainThreadEvents, timestamps} = await TraceOfTab.request(trace, context);
return MainThreadTasks_.getMainThreadTasks(mainThreadEvents, timestamps.traceEnd);
}
}

module.exports = makeComputedArtifact(MainThreadTasks);
Expand Up @@ -8,7 +8,7 @@
const makeComputedArtifact = require('../computed-artifact.js');
const ComputedMetric = require('./metric.js');
const LHError = require('../../lib/lh-error.js');
const TracingProcessor = require('../../lib/traces/tracing-processor.js');
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');
const LanternEstimatedInputLatency = require('./lantern-estimated-input-latency.js');

const ROLLING_WINDOW_SIZE = 5000;
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/first-cpu-idle.js
Expand Up @@ -7,7 +7,7 @@

const makeComputedArtifact = require('../computed-artifact.js');
const ComputedMetric = require('./metric.js');
const TracingProcessor = require('../../lib/traces/tracing-processor.js');
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');
const LHError = require('../../lib/lh-error.js');
const LanternFirstCPUIdle = require('./lantern-first-cpu-idle.js');

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/interactive.js
Expand Up @@ -10,7 +10,7 @@ const ComputedMetric = require('./metric.js');
const LanternInteractive = require('./lantern-interactive.js');

const NetworkRecorder = require('../../lib/network-recorder.js');
const TracingProcessor = require('../../lib/traces/tracing-processor.js');
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');
const LHError = require('../../lib/lh-error.js');

const REQUIRED_QUIET_WINDOW = 5000;
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/max-potential-fid.js
Expand Up @@ -9,7 +9,7 @@ const makeComputedArtifact = require('../computed-artifact.js');
const MetricArtifact = require('./metric.js');
const LanternMaxPotentialFID = require('./lantern-max-potential-fid.js');
const LHError = require('../../lib/lh-error.js');
const TracingProcessor = require('../../lib/traces/tracing-processor.js');
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');

class MaxPotentialFID extends MetricArtifact {
/**
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/metric.js
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

const TracingProcessor = require('../../lib/traces/tracing-processor.js');
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');
const TraceOfTab = require('../trace-of-tab.js');
const NetworkRecords = require('../network-records.js');

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/page-dependency-graph.js
Expand Up @@ -9,7 +9,7 @@ const makeComputedArtifact = require('./computed-artifact.js');
const NetworkNode = require('../lib/dependency-graph/network-node.js');
const CPUNode = require('../lib/dependency-graph/cpu-node.js');
const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analyzer.js');
const TracingProcessor = require('../lib/traces/tracing-processor.js');
const TracingProcessor = require('../lib/tracehouse/tracing-processor.js');
const NetworkRequest = require('../lib/network-request.js');
const TraceOfTab = require('./trace-of-tab.js');
const NetworkRecords = require('./network-records.js');
Expand Down
23 changes: 23 additions & 0 deletions lighthouse-core/computed/trace-of-tab.js
@@ -0,0 +1,23 @@
/**
* @license Copyright 2019 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 makeComputedArtifact = require('./computed-artifact.js');
const TraceOfTab_ = require('../lib/tracehouse/trace-of-tab.js');

class TraceOfTab {
/**
* Finds key trace events, identifies main process/thread, and returns timings of trace events
* in milliseconds since navigation start in addition to the standard microsecond monotonic timestamps.
* @param {LH.Trace} trace
* @return {Promise<LH.Artifacts.TraceOfTab>}
*/
static async compute_(trace) {
return TraceOfTab_.compute(trace);
}
}

module.exports = makeComputedArtifact(TraceOfTab);
6 changes: 3 additions & 3 deletions lighthouse-core/lib/minify-trace.js
Expand Up @@ -10,13 +10,13 @@
/**
* @fileoverview Minifies a trace by removing unnecessary events, throttling screenshots, etc.
* See the following files for necessary events:
* - lighthouse-core/computed/trace-of-tab.js
* - lighthouse-core/computed/page-dependency-graph.js
* - lighthouse-core/lib/dependency-graph/cpu-node.js
* - lighthouse-core/lib/traces/tracing-processor.js
* - lighthouse-core/lib/tracehouse/trace-of-tab.js
* - lighthouse-core/lib/tracehouse/tracing-processor.js
*/

const TracingProcessor = require('./traces/tracing-processor.js');
const TracingProcessor = require('./tracehouse/tracing-processor.js');

const toplevelTaskNames = new Set([
'RunTask', // m71+
Expand Down
18 changes: 3 additions & 15 deletions lighthouse-core/lib/tracehouse/main-thread-tasks.js
Expand Up @@ -5,9 +5,7 @@
*/
'use strict';

const makeComputedArtifact = require('./computed-artifact.js');
const {taskGroups, taskNameToGroup} = require('../lib/task-groups.js');
const TraceOfTab = require('./trace-of-tab.js');
const {taskGroups, taskNameToGroup} = require('./task-groups.js');

/**
* @fileoverview
Expand All @@ -26,7 +24,7 @@ const TraceOfTab = require('./trace-of-tab.js');
* attributableURL for the script that was executing/forced this execution.
*/

/** @typedef {import('../lib/task-groups.js').TaskGroup} TaskGroup */
/** @typedef {import('./task-groups.js').TaskGroup} TaskGroup */

/**
* @typedef TaskNode
Expand Down Expand Up @@ -263,16 +261,6 @@ class MainThreadTasks {

return tasks;
}

/**
* @param {LH.Trace} trace
* @param {LH.Audit.Context} context
* @return {Promise<Array<TaskNode>>} networkRecords
*/
static async compute_(trace, context) {
const {mainThreadEvents, timestamps} = await TraceOfTab.request(trace, context);
return MainThreadTasks.getMainThreadTasks(mainThreadEvents, timestamps.traceEnd);
}
}

module.exports = makeComputedArtifact(MainThreadTasks);
module.exports = MainThreadTasks;
13 changes: 6 additions & 7 deletions lighthouse-core/lib/tracehouse/trace-of-tab.js
Expand Up @@ -16,11 +16,10 @@
* 4. Return all those items in one handy bundle.
*/

const makeComputedArtifact = require('./computed-artifact.js');
const log = require('lighthouse-logger');
const TracingProcessor = require('../lib/traces/tracing-processor.js');
const LHError = require('../lib/lh-error.js');
const Sentry = require('../lib/sentry.js');
const TracingProcessor = require('./tracing-processor.js');
const LHError = require('../lh-error.js');
const Sentry = require('../sentry.js');

const ACCEPTABLE_NAVIGATION_URL_REGEX = /^(chrome|https?):/;

Expand Down Expand Up @@ -69,9 +68,9 @@ class TraceOfTab {
* Finds key trace events, identifies main process/thread, and returns timings of trace events
* in milliseconds since navigation start in addition to the standard microsecond monotonic timestamps.
* @param {LH.Trace} trace
* @return {Promise<LH.Artifacts.TraceOfTab>}
* @return {LH.Artifacts.TraceOfTab}
*/
static async compute_(trace) {
static compute(trace) {
// Parse the trace for our key events and sort them by timestamp. Note: sort
// *must* be stable to keep events correctly nested.
const keyEvents = TraceOfTab.filteredStableSort(trace.traceEvents, e => {
Expand Down Expand Up @@ -189,4 +188,4 @@ class TraceOfTab {
}
}

module.exports = makeComputedArtifact(TraceOfTab);
module.exports = TraceOfTab;
1 change: 1 addition & 0 deletions lighthouse-core/scripts/lantern/minify-trace.js
Expand Up @@ -8,6 +8,7 @@

/* eslint-disable no-console */


const fs = require('fs');
const path = require('path');
const {minifyTrace} = require('../../lib/minify-trace.js');
Expand Down
Expand Up @@ -93,7 +93,7 @@ describe('Cache headers audit', () => {

it('detects low value expires headers', () => {
const expiresIn = seconds => new Date(Date.now() + seconds * 1000).toGMTString();
const closeEnough = (actual, exp) => assert.ok(Math.abs(actual - exp) <= 1, 'invalid expires');
const closeEnough = (actual, exp) => assert.ok(Math.abs(actual - exp) <= 5, 'invalid expires');

const networkRecords = [
networkRecord({headers: {expires: expiresIn(86400 * 365)}}), // a year
Expand Down Expand Up @@ -132,9 +132,9 @@ describe('Cache headers audit', () => {
return CacheHeadersAudit.audit(getArtifacts(networkRecords), context).then(result => {
const items = result.extendedInfo.value.results;
assert.equal(items.length, 2);
assert.ok(Math.abs(items[0].cacheLifetimeMs - 3600 * 1000) <= 1, 'invalid expires parsing');
assert.ok(Math.abs(items[0].cacheLifetimeMs - 3600 * 1000) <= 5, 'invalid expires parsing');
assert.equal(Math.round(items[0].wastedBytes), 8000);
assert.ok(Math.abs(items[1].cacheLifetimeMs - 86400 * 1000) <= 1, 'invalid expires parsing');
assert.ok(Math.abs(items[1].cacheLifetimeMs - 86400 * 1000) <= 5, 'invalid expires parsing');
assert.equal(Math.round(items[1].wastedBytes), 4000);
});
});
Expand Down
19 changes: 19 additions & 0 deletions lighthouse-core/test/computed/main-thread-tasks-test.js
@@ -0,0 +1,19 @@
/**
* @license Copyright 2019 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';

/* eslint-env jest */

const MainThreadTasks = require('../../computed/main-thread-tasks.js');
const pwaTrace = require('../fixtures/traces/progressive-app-m60.json');

describe('MainThreadTasksComputed', () => {
it('computes the artifact', async () => {
const context = {computedCache: new Map()};
const tasks = await MainThreadTasks.request(pwaTrace, context);
expect(tasks.length).toEqual(4784);
});
});
Expand Up @@ -6,7 +6,7 @@
'use strict';

const FirstCPUIdle = require('../../../computed/metrics/first-cpu-idle.js');
const TracingProcessor = require('../../../lib/traces/tracing-processor.js');
const TracingProcessor = require('../../../lib/tracehouse/tracing-processor.js');

const tooShortTrace = require('../../fixtures/traces/progressive-app.json');
const acceptableTrace = require('../../fixtures/traces/progressive-app-m60.json');
Expand Down

0 comments on commit 1af2edd

Please sign in to comment.