Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(network): fix time units in network quiet calc #16013

Merged
merged 5 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/computed/metrics/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ export {InteractiveComputed as Interactive};

/**
* @typedef TimePeriod
* @property {number} start
* @property {number} end
* @property {number} start In ms.
* @property {number} end In ms.
*/
6 changes: 3 additions & 3 deletions core/gather/driver/network-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
/**
* Finds all time periods where the number of inflight requests is less than or equal to the
* number of allowed concurrent requests.
* The time periods returned are in ms.
* @param {Array<LH.Artifacts.NetworkRequest>} requests
* @param {number} allowedConcurrentRequests
* @param {number=} endTime
Expand All @@ -215,10 +216,9 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
if (UrlUtils.isNonNetworkProtocol(request.protocol)) return;
if (request.protocol === 'ws' || request.protocol === 'wss') return;

// convert the network timestamp to ms
timeBoundaries.push({time: request.networkRequestTime * 1000, isStart: true});
timeBoundaries.push({time: request.networkRequestTime, isStart: true});
if (request.finished) {
timeBoundaries.push({time: request.networkEndTime * 1000, isStart: false});
timeBoundaries.push({time: request.networkEndTime, isStart: false});
}
});

Expand Down
4 changes: 2 additions & 2 deletions core/test/computed/metrics/interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function generateNetworkRecords(partialRecords, timeOrigin) {
statusCode: item.statusCode || 200,
requestMethod: item.requestMethod || 'GET',
finished: typeof item.finished === 'undefined' ? true : item.finished,
networkRequestTime: (item.start + timeOriginInMs) / 1000,
networkEndTime: item.end === -1 ? -1 : (item.end + timeOriginInMs) / 1000,
networkRequestTime: item.start + timeOriginInMs,
networkEndTime: item.end === -1 ? -1 : item.end + timeOriginInMs,
};
return /** @type {LH.Artifacts.NetworkRequest} */ (record);
});
Expand Down
48 changes: 24 additions & 24 deletions core/test/gather/driver/network-monitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ describe('NetworkMonitor', () => {

it('should find the 0-quiet periods', () => {
const records = [
record({networkRequestTime: 0, networkEndTime: 1}),
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
record({networkRequestTime: 2, networkEndTime: 3}),
record({networkRequestTime: 4, networkEndTime: 5}),
record({networkRequestTime: 0, networkEndTime: 1000}),
record({networkRequestTime: 2000, networkEndTime: 3000}),
record({networkRequestTime: 4000, networkEndTime: 5000}),
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 0);
Expand All @@ -396,11 +396,11 @@ describe('NetworkMonitor', () => {

it('should find the 2-quiet periods', () => {
const records = [
record({networkRequestTime: 0, networkEndTime: 1.5}),
record({networkRequestTime: 0, networkEndTime: 2}),
record({networkRequestTime: 0, networkEndTime: 2.5}),
record({networkRequestTime: 2, networkEndTime: 3}),
record({networkRequestTime: 4, networkEndTime: 5}),
record({networkRequestTime: 0, networkEndTime: 1500}),
record({networkRequestTime: 0, networkEndTime: 2000}),
record({networkRequestTime: 0, networkEndTime: 2500}),
record({networkRequestTime: 2000, networkEndTime: 3000}),
record({networkRequestTime: 4000, networkEndTime: 5000}),
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 2);
Expand All @@ -409,14 +409,14 @@ describe('NetworkMonitor', () => {

it('should handle unfinished requests', () => {
const records = [
record({networkRequestTime: 0, networkEndTime: 1.5}),
record({networkRequestTime: 0, networkEndTime: 2}),
record({networkRequestTime: 0, networkEndTime: 2.5}),
record({networkRequestTime: 2, networkEndTime: 3}),
record({networkRequestTime: 2}),
record({networkRequestTime: 2}),
record({networkRequestTime: 4, networkEndTime: 5}),
record({networkRequestTime: 5.5}),
record({networkRequestTime: 0, networkEndTime: 1500}),
record({networkRequestTime: 0, networkEndTime: 2000}),
record({networkRequestTime: 0, networkEndTime: 2500}),
record({networkRequestTime: 2000, networkEndTime: 3000}),
record({networkRequestTime: 2000}),
record({networkRequestTime: 2000}),
record({networkRequestTime: 4000, networkEndTime: 5000}),
record({networkRequestTime: 5500}),
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 2);
Expand All @@ -429,8 +429,8 @@ describe('NetworkMonitor', () => {

it('should ignore data URIs', () => {
const records = [
record({networkRequestTime: 0, networkEndTime: 1}),
record({networkRequestTime: 0, networkEndTime: 2, url: 'data:image/png;base64,',
record({networkRequestTime: 0, networkEndTime: 1000}),
record({networkRequestTime: 0, networkEndTime: 2000, url: 'data:image/png;base64,',
protocol: 'data'}),
];

Expand All @@ -443,12 +443,12 @@ describe('NetworkMonitor', () => {
finished: false,
url: 'https://iframe.com',
documentURL: 'https://iframe.com',
responseHeadersEndTime: 1.2,
responseHeadersEndTime: 1200,
};

const records = [
record({networkRequestTime: 0, networkEndTime: 1}),
record({networkRequestTime: 0, networkEndTime: 1.2, ...iframeRequest}),
record({networkRequestTime: 0, networkEndTime: 1000}),
record({networkRequestTime: 0, networkEndTime: 1200, ...iframeRequest}),
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 0);
Expand All @@ -460,12 +460,12 @@ describe('NetworkMonitor', () => {
const quicRequest = {
finished: false,
responseHeaders: [{name: 'ALT-SVC', value: 'hq=":49288";quic="1,1abadaba,51303334,0"'}],
timing: /** @type {*} */ ({receiveHeadersEnd: 1.28}),
timing: /** @type {*} */ ({receiveHeadersEnd: 1280}),
};

const records = [
record({networkRequestTime: 0, networkEndTime: 1}),
record({networkRequestTime: 0, networkEndTime: 2, ...quicRequest}),
record({networkRequestTime: 0, networkEndTime: 1000}),
record({networkRequestTime: 0, networkEndTime: 2000, ...quicRequest}),
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 0);
Expand Down
Loading