Skip to content

Commit 1af2edd

Browse files
committed
core(tracehouse): modify files for move to tracehouse
1 parent 9f80524 commit 1af2edd

23 files changed

+280
-105
lines changed

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ driver.sendCommand('Security.enable');
3939

4040
## Understanding a Trace
4141

42-
`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).
42+
`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).
4343

4444
### Example Trace Event
4545
```js

lighthouse-core/audits/bootup-time.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const Audit = require('./audit.js');
99
const NetworkRequest = require('../lib/network-request.js');
10-
const {taskGroups} = require('../lib/task-groups.js');
10+
const {taskGroups} = require('../lib/tracehouse/task-groups.js');
1111
const i18n = require('../lib/i18n/i18n.js');
1212
const NetworkRecords = require('../computed/network-records.js');
1313
const MainThreadTasks = require('../computed/main-thread-tasks.js');

lighthouse-core/audits/mainthread-work-breakdown.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'use strict';
1212

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

@@ -29,7 +29,7 @@ const UIStrings = {
2929

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

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

3434
class MainThreadWorkBreakdown extends Audit {
3535
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license Copyright 2019 Google Inc. All Rights Reserved.
3+
* 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
4+
* 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.
5+
*/
6+
'use strict';
7+
8+
const makeComputedArtifact = require('./computed-artifact.js');
9+
const MainThreadTasks_ = require('../lib/tracehouse/main-thread-tasks.js');
10+
const TraceOfTab = require('./trace-of-tab.js');
11+
12+
class MainThreadTasks {
13+
/**
14+
* @param {LH.Trace} trace
15+
* @param {LH.Audit.Context} context
16+
* @return {Promise<Array<LH.Artifacts.TaskNode>>}
17+
*/
18+
static async compute_(trace, context) {
19+
const {mainThreadEvents, timestamps} = await TraceOfTab.request(trace, context);
20+
return MainThreadTasks_.getMainThreadTasks(mainThreadEvents, timestamps.traceEnd);
21+
}
22+
}
23+
24+
module.exports = makeComputedArtifact(MainThreadTasks);

lighthouse-core/computed/metrics/estimated-input-latency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const makeComputedArtifact = require('../computed-artifact.js');
99
const ComputedMetric = require('./metric.js');
1010
const LHError = require('../../lib/lh-error.js');
11-
const TracingProcessor = require('../../lib/traces/tracing-processor.js');
11+
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');
1212
const LanternEstimatedInputLatency = require('./lantern-estimated-input-latency.js');
1313

1414
const ROLLING_WINDOW_SIZE = 5000;

lighthouse-core/computed/metrics/first-cpu-idle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

lighthouse-core/computed/metrics/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ComputedMetric = require('./metric.js');
1010
const LanternInteractive = require('./lantern-interactive.js');
1111

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

1616
const REQUIRED_QUIET_WINDOW = 5000;

lighthouse-core/computed/metrics/max-potential-fid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const makeComputedArtifact = require('../computed-artifact.js');
99
const MetricArtifact = require('./metric.js');
1010
const LanternMaxPotentialFID = require('./lantern-max-potential-fid.js');
1111
const LHError = require('../../lib/lh-error.js');
12-
const TracingProcessor = require('../../lib/traces/tracing-processor.js');
12+
const TracingProcessor = require('../../lib/tracehouse/tracing-processor.js');
1313

1414
class MaxPotentialFID extends MetricArtifact {
1515
/**

lighthouse-core/computed/metrics/metric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
'use strict';
77

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

lighthouse-core/computed/page-dependency-graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const makeComputedArtifact = require('./computed-artifact.js');
99
const NetworkNode = require('../lib/dependency-graph/network-node.js');
1010
const CPUNode = require('../lib/dependency-graph/cpu-node.js');
1111
const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analyzer.js');
12-
const TracingProcessor = require('../lib/traces/tracing-processor.js');
12+
const TracingProcessor = require('../lib/tracehouse/tracing-processor.js');
1313
const NetworkRequest = require('../lib/network-request.js');
1414
const TraceOfTab = require('./trace-of-tab.js');
1515
const NetworkRecords = require('./network-records.js');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license Copyright 2019 Google Inc. All Rights Reserved.
3+
* 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
4+
* 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.
5+
*/
6+
'use strict';
7+
8+
const makeComputedArtifact = require('./computed-artifact.js');
9+
const TraceOfTab_ = require('../lib/tracehouse/trace-of-tab.js');
10+
11+
class TraceOfTab {
12+
/**
13+
* Finds key trace events, identifies main process/thread, and returns timings of trace events
14+
* in milliseconds since navigation start in addition to the standard microsecond monotonic timestamps.
15+
* @param {LH.Trace} trace
16+
* @return {Promise<LH.Artifacts.TraceOfTab>}
17+
*/
18+
static async compute_(trace) {
19+
return TraceOfTab_.compute(trace);
20+
}
21+
}
22+
23+
module.exports = makeComputedArtifact(TraceOfTab);

lighthouse-core/lib/minify-trace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
/**
1111
* @fileoverview Minifies a trace by removing unnecessary events, throttling screenshots, etc.
1212
* See the following files for necessary events:
13-
* - lighthouse-core/computed/trace-of-tab.js
1413
* - lighthouse-core/computed/page-dependency-graph.js
1514
* - lighthouse-core/lib/dependency-graph/cpu-node.js
16-
* - lighthouse-core/lib/traces/tracing-processor.js
15+
* - lighthouse-core/lib/tracehouse/trace-of-tab.js
16+
* - lighthouse-core/lib/tracehouse/tracing-processor.js
1717
*/
1818

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

2121
const toplevelTaskNames = new Set([
2222
'RunTask', // m71+

lighthouse-core/lib/tracehouse/main-thread-tasks.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
'use strict';
77

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

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

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

3129
/**
3230
* @typedef TaskNode
@@ -263,16 +261,6 @@ class MainThreadTasks {
263261

264262
return tasks;
265263
}
266-
267-
/**
268-
* @param {LH.Trace} trace
269-
* @param {LH.Audit.Context} context
270-
* @return {Promise<Array<TaskNode>>} networkRecords
271-
*/
272-
static async compute_(trace, context) {
273-
const {mainThreadEvents, timestamps} = await TraceOfTab.request(trace, context);
274-
return MainThreadTasks.getMainThreadTasks(mainThreadEvents, timestamps.traceEnd);
275-
}
276264
}
277265

278-
module.exports = makeComputedArtifact(MainThreadTasks);
266+
module.exports = MainThreadTasks;

lighthouse-core/lib/tracehouse/trace-of-tab.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
* 4. Return all those items in one handy bundle.
1717
*/
1818

19-
const makeComputedArtifact = require('./computed-artifact.js');
2019
const log = require('lighthouse-logger');
21-
const TracingProcessor = require('../lib/traces/tracing-processor.js');
22-
const LHError = require('../lib/lh-error.js');
23-
const Sentry = require('../lib/sentry.js');
20+
const TracingProcessor = require('./tracing-processor.js');
21+
const LHError = require('../lh-error.js');
22+
const Sentry = require('../sentry.js');
2423

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

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

192-
module.exports = makeComputedArtifact(TraceOfTab);
191+
module.exports = TraceOfTab;

lighthouse-core/scripts/lantern/minify-trace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* eslint-disable no-console */
1010

11+
1112
const fs = require('fs');
1213
const path = require('path');
1314
const {minifyTrace} = require('../../lib/minify-trace.js');

lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('Cache headers audit', () => {
9393

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

9898
const networkRecords = [
9999
networkRecord({headers: {expires: expiresIn(86400 * 365)}}), // a year
@@ -132,9 +132,9 @@ describe('Cache headers audit', () => {
132132
return CacheHeadersAudit.audit(getArtifacts(networkRecords), context).then(result => {
133133
const items = result.extendedInfo.value.results;
134134
assert.equal(items.length, 2);
135-
assert.ok(Math.abs(items[0].cacheLifetimeMs - 3600 * 1000) <= 1, 'invalid expires parsing');
135+
assert.ok(Math.abs(items[0].cacheLifetimeMs - 3600 * 1000) <= 5, 'invalid expires parsing');
136136
assert.equal(Math.round(items[0].wastedBytes), 8000);
137-
assert.ok(Math.abs(items[1].cacheLifetimeMs - 86400 * 1000) <= 1, 'invalid expires parsing');
137+
assert.ok(Math.abs(items[1].cacheLifetimeMs - 86400 * 1000) <= 5, 'invalid expires parsing');
138138
assert.equal(Math.round(items[1].wastedBytes), 4000);
139139
});
140140
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license Copyright 2019 Google Inc. All Rights Reserved.
3+
* 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
4+
* 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.
5+
*/
6+
'use strict';
7+
8+
/* eslint-env jest */
9+
10+
const MainThreadTasks = require('../../computed/main-thread-tasks.js');
11+
const pwaTrace = require('../fixtures/traces/progressive-app-m60.json');
12+
13+
describe('MainThreadTasksComputed', () => {
14+
it('computes the artifact', async () => {
15+
const context = {computedCache: new Map()};
16+
const tasks = await MainThreadTasks.request(pwaTrace, context);
17+
expect(tasks.length).toEqual(4784);
18+
});
19+
});

lighthouse-core/test/computed/metrics/first-cpu-idle-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

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

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

0 commit comments

Comments
 (0)