Skip to content

Commit

Permalink
core(network-request): add rendererStartTime (#14711)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Jan 26, 2023
1 parent 955586c commit c14aaee
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 193 deletions.
13 changes: 7 additions & 6 deletions core/audits/network-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class NetworkRequests extends Audit {
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const records = await NetworkRecords.request(devtoolsLog, context);
const earliestStartTime = records.reduce(
(min, record) => Math.min(min, record.startTime),
const earliestRendererStartTime = records.reduce(
(min, record) => Math.min(min, record.rendererStartTime),
Infinity
);

Expand All @@ -47,8 +47,8 @@ class NetworkRequests extends Audit {
}

/** @param {number} time */
const normalizeTime = time => time < earliestStartTime || !Number.isFinite(time) ?
undefined : (time - earliestStartTime);
const normalizeTime = time => time < earliestRendererStartTime || !Number.isFinite(time) ?
undefined : (time - earliestRendererStartTime);

const results = records.map(record => {
const endTimeDeltaMs = record.lrStatistics?.endTimeDeltaMs;
Expand All @@ -64,6 +64,7 @@ class NetworkRequests extends Audit {
return {
url: UrlUtils.elideDataURI(record.url),
protocol: record.protocol,
rendererStartTime: normalizeTime(record.rendererStartTime),
startTime: normalizeTime(record.startTime),
endTime: normalizeTime(record.endTime),
finished: record.finished,
Expand Down Expand Up @@ -111,8 +112,8 @@ class NetworkRequests extends Audit {
const tableDetails = Audit.makeTableDetails(headings, results);

// Include starting timestamp to allow syncing requests with navStart/metric timestamps.
const networkStartTimeTs = Number.isFinite(earliestStartTime) ?
earliestStartTime * 1000 : undefined;
const networkStartTimeTs = Number.isFinite(earliestRendererStartTime) ?
earliestRendererStartTime * 1000 : undefined;
tableDetails.debugData = {
type: 'debugdata',
networkStartTimeTs,
Expand Down
3 changes: 3 additions & 0 deletions core/lib/network-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class NetworkRequest {
this.parsedURL = /** @type {ParsedURL} */ ({scheme: ''});
this.documentURL = '';

/** When the renderer process initially discovers a network request, in milliseconds. */
this.rendererStartTime = -1;
/**
* When the network service is about to handle a request, ie. just before going to the
* HTTP cache or going to the network for DNS/connection setup, in milliseconds.
Expand Down Expand Up @@ -222,6 +224,7 @@ class NetworkRequest {
};
this.isSecure = UrlUtils.isSecureScheme(this.parsedURL.scheme);

this.rendererStartTime = data.timestamp * 1000;
// Expected to be overriden with better value in `_recomputeTimesWithResourceTiming`.
this.startTime = data.timestamp * 1000;

Expand Down
13 changes: 8 additions & 5 deletions core/test/audits/network-requests-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ describe('Network requests audit', () => {
const output = await NetworkRequests.audit(artifacts, {computedCache: new Map()});

expect(output.details.items[0]).toMatchObject({
startTime: 0,
endTime: expect.toBeApproximately(701, 0),
rendererStartTime: 0,
startTime: expect.toBeApproximately(1, 0),
endTime: expect.toBeApproximately(702, 0),
finished: true,
transferSize: 11358,
resourceSize: 39471,
Expand All @@ -38,7 +39,8 @@ describe('Network requests audit', () => {
priority: 'VeryHigh',
});
expect(output.details.items[2]).toMatchObject({
startTime: expect.toBeApproximately(711, 0),
rendererStartTime: expect.toBeApproximately(710, 0),
startTime: expect.toBeApproximately(712, 0),
endTime: expect.toBeApproximately(1289, 0),
finished: false,
transferSize: 26441,
Expand All @@ -49,8 +51,9 @@ describe('Network requests audit', () => {
priority: 'Low',
});
expect(output.details.items[5]).toMatchObject({
rendererStartTime: expect.toBeApproximately(713, 0),
startTime: expect.toBeApproximately(717, 0),
endTime: expect.toBeApproximately(1296, 0),
endTime: expect.toBeApproximately(1297, 0),
finished: false,
transferSize: 58571,
resourceSize: 0,
Expand All @@ -62,7 +65,7 @@ describe('Network requests audit', () => {

expect(output.details.debugData).toStrictEqual({
type: 'debugdata',
networkStartTimeTs: 360725781425,
networkStartTimeTs: 360725780729,
});
});

Expand Down
Loading

0 comments on commit c14aaee

Please sign in to comment.