Skip to content

Commit

Permalink
core(lantern): replace usage of LH.Artifacts.ProcessedTrace (#15905)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Apr 1, 2024
1 parent acfd1fb commit 4f54d5a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
3 changes: 2 additions & 1 deletion core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class PageDependencyGraph {
// Calculates the URL artifact from the processed trace and DT log.
const URL = data.URL || await DocumentUrls.request(data, context);

const mainThreadEvents = processedTrace.mainThreadEvents;
const lanternRequests = networkRecords.map(NetworkRequest.asLanternNetworkRequest);
return LanternPageDependencyGraph.createGraph(processedTrace, lanternRequests, URL);
return LanternPageDependencyGraph.createGraph(mainThreadEvents, lanternRequests, URL);
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/lib/lantern/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ class PageDependencyGraph {
}

/**
* @param {LH.Artifacts.ProcessedTrace} processedTrace
* @param {LH.TraceEvent[]} mainThreadEvents
* @return {Array<CPUNode>}
*/
static getCPUNodes({mainThreadEvents}) {
static getCPUNodes(mainThreadEvents) {
/** @type {Array<CPUNode>} */
const nodes = [];
let i = 0;
Expand Down Expand Up @@ -393,14 +393,14 @@ class PageDependencyGraph {
}

/**
* @param {LH.Artifacts.ProcessedTrace} processedTrace
* @param {LH.TraceEvent[]} mainThreadEvents
* @param {Array<Lantern.NetworkRequest>} networkRecords
* @param {URLArtifact} URL
* @return {Node}
*/
static createGraph(processedTrace, networkRecords, URL) {
static createGraph(mainThreadEvents, networkRecords, URL) {
const networkNodeOutput = PageDependencyGraph.getNetworkNodeOutput(networkRecords);
const cpuNodes = PageDependencyGraph.getCPUNodes(processedTrace);
const cpuNodes = PageDependencyGraph.getCPUNodes(mainThreadEvents);
const {requestedUrl, mainDocumentUrl} = URL;
if (!requestedUrl) throw new Error('requestedUrl is required to get the root request');
if (!mainDocumentUrl) throw new Error('mainDocumentUrl is required to get the main resource');
Expand Down
48 changes: 24 additions & 24 deletions core/test/lib/lantern/page-dependency-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function createRequest(

const TOPLEVEL_TASK_NAME = 'TaskQueueManager::ProcessTaskFromWorkQueue';
describe('PageDependencyGraph computed artifact:', () => {
let processedTrace;
let traceEvents;
let URL;

function addTaskEvents(startTs, duration, evts) {
Expand All @@ -43,12 +43,12 @@ describe('PageDependencyGraph computed artifact:', () => {
args: {},
};

processedTrace.mainThreadEvents.push(mainEvent);
traceEvents.push(mainEvent);

let i = 0;
for (const evt of evts) {
i++;
processedTrace.mainThreadEvents.push({
traceEvents.push({
name: evt.name,
ts: (evt.ts * 1000) || (startTs * 1000 + i),
args: {data: evt.data},
Expand All @@ -57,7 +57,7 @@ describe('PageDependencyGraph computed artifact:', () => {
}

beforeEach(() => {
processedTrace = {mainThreadEvents: []};
traceEvents = [];
URL = {requestedUrl: 'https://example.com/', mainDocumentUrl: 'https://example.com/'};
});

Expand Down Expand Up @@ -142,21 +142,21 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'LaterEvent'},
]);

assert.equal(processedTrace.mainThreadEvents.length, 7);
const nodes = PageDependencyGraph.getCPUNodes(processedTrace);
assert.equal(traceEvents.length, 7);
const nodes = PageDependencyGraph.getCPUNodes(traceEvents);
assert.equal(nodes.length, 2);

const node1 = nodes[0];
assert.equal(node1.id, '1.0');
assert.equal(node1.type, 'cpu');
assert.equal(node1.event, processedTrace.mainThreadEvents[0]);
assert.equal(node1.event, traceEvents[0]);
assert.equal(node1.childEvents.length, 2);
assert.equal(node1.childEvents[1].name, 'OtherEvent');

const node2 = nodes[1];
assert.equal(node2.id, '1.250000');
assert.equal(node2.type, 'cpu');
assert.equal(node2.event, processedTrace.mainThreadEvents[5]);
assert.equal(node2.event, traceEvents[5]);
assert.equal(node2.childEvents.length, 1);
assert.equal(node2.childEvents[0].name, 'LaterEvent');
});
Expand All @@ -172,7 +172,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -201,7 +201,7 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'XHRReadyStateChange', data: {readyState: 4, url: 'https://example.com/page3'}},
]);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand All @@ -227,7 +227,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -266,7 +266,7 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'ResourceSendRequest', data: {requestId: 5}},
]);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -294,7 +294,7 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'TimerFire', data: {timerId: 'timer1'}},
]);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -328,7 +328,7 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'XHRReadyStateChange', data: {readyState: 4, url: 'https://example.com/page3'}},
]);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -374,7 +374,7 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'XHRReadyStateChange', data: {readyState: 4, url: 'https://example.com/page3'}},
]);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand All @@ -398,7 +398,7 @@ describe('PageDependencyGraph computed artifact:', () => {
URL = {requestedUrl: 'https://example.com/page0', mainDocumentUrl: 'https://example.com/page0'};

const makeShortEvent = firstEventName => {
const startTs = processedTrace.mainThreadEvents.length * 100;
const startTs = traceEvents.length * 100;
addTaskEvents(startTs, 5, [
{name: firstEventName, data: {url: 'https://example.com/page0'}},
]);
Expand All @@ -414,7 +414,7 @@ describe('PageDependencyGraph computed artifact:', () => {
makeShortEvent(eventName);
}

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const cpuNodes = [];
graph.traverse(node => node.type === 'cpu' && cpuNodes.push(node));

Expand Down Expand Up @@ -451,7 +451,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -479,7 +479,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand All @@ -504,7 +504,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down Expand Up @@ -533,7 +533,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand All @@ -557,7 +557,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));
nodes.sort((a, b) => a.id - b.id);
Expand Down Expand Up @@ -587,7 +587,7 @@ describe('PageDependencyGraph computed artifact:', () => {

addTaskEvents(0, 0, []);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));
nodes.sort((a, b) => a.id - b.id);
Expand All @@ -610,7 +610,7 @@ describe('PageDependencyGraph computed artifact:', () => {
{name: 'EvaluateScript'},
]);

const graph = PageDependencyGraph.createGraph(processedTrace, networkRecords, URL);
const graph = PageDependencyGraph.createGraph(traceEvents, networkRecords, URL);
const nodes = [];
graph.traverse(node => nodes.push(node));

Expand Down

0 comments on commit 4f54d5a

Please sign in to comment.