forked from mirrors/gecko-dev
Bug 1554913 - Remove eslint-disable-next-line complexity from _setupHarTimings r=Honza
Differential Revision: https://phabricator.services.mozilla.com/D57877 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
bd02e0f831
commit
b111b012e8
1 changed files with 180 additions and 143 deletions
|
|
@ -1048,6 +1048,150 @@ NetworkObserver.prototype = {
|
||||||
this.openRequests.delete(httpActivity.channel);
|
this.openRequests.delete(httpActivity.channel);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getBlockedTiming: function(timings) {
|
||||||
|
if (timings.STATUS_RESOLVING && timings.STATUS_CONNECTING_TO) {
|
||||||
|
return timings.STATUS_RESOLVING.first - timings.REQUEST_HEADER.first;
|
||||||
|
} else if (timings.STATUS_SENDING_TO) {
|
||||||
|
return timings.STATUS_SENDING_TO.first - timings.REQUEST_HEADER.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getDnsTiming: function(timings) {
|
||||||
|
if (timings.STATUS_RESOLVING && timings.STATUS_RESOLVED) {
|
||||||
|
return timings.STATUS_RESOLVED.last - timings.STATUS_RESOLVING.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getConnectTiming: function(timings) {
|
||||||
|
if (timings.STATUS_CONNECTING_TO && timings.STATUS_CONNECTED_TO) {
|
||||||
|
return (
|
||||||
|
timings.STATUS_CONNECTED_TO.last - timings.STATUS_CONNECTING_TO.first
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getReceiveTiming: function(timings) {
|
||||||
|
if (timings.RESPONSE_START && timings.RESPONSE_COMPLETE) {
|
||||||
|
return timings.RESPONSE_COMPLETE.last - timings.RESPONSE_START.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getWaitTiming: function(timings) {
|
||||||
|
if (timings.RESPONSE_START) {
|
||||||
|
return (
|
||||||
|
timings.RESPONSE_START.first -
|
||||||
|
(timings.REQUEST_BODY_SENT || timings.STATUS_SENDING_TO).last
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getSslTiming: function(timings) {
|
||||||
|
if (timings.STATUS_TLS_STARTING && timings.STATUS_TLS_ENDING) {
|
||||||
|
return timings.STATUS_TLS_ENDING.last - timings.STATUS_TLS_STARTING.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getSendTiming: function(timings) {
|
||||||
|
if (timings.STATUS_SENDING_TO) {
|
||||||
|
return timings.STATUS_SENDING_TO.last - timings.STATUS_SENDING_TO.first;
|
||||||
|
} else if (timings.REQUEST_HEADER && timings.REQUEST_BODY_SENT) {
|
||||||
|
return timings.REQUEST_BODY_SENT.last - timings.REQUEST_HEADER.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getDataFromTimedChannel: function(timedChannel) {
|
||||||
|
const lookUpArr = [
|
||||||
|
"tcpConnectEndTime",
|
||||||
|
"connectStartTime",
|
||||||
|
"connectEndTime",
|
||||||
|
"secureConnectionStartTime",
|
||||||
|
"domainLookupEndTime",
|
||||||
|
"domainLookupStartTime",
|
||||||
|
];
|
||||||
|
|
||||||
|
return lookUpArr.reduce((prev, prop) => {
|
||||||
|
const propName = prop + "Tc";
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
[propName]: (() => {
|
||||||
|
if (!timedChannel) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = timedChannel[prop];
|
||||||
|
|
||||||
|
if (
|
||||||
|
value != 0 &&
|
||||||
|
timedChannel.asyncOpenTime &&
|
||||||
|
value < timedChannel.asyncOpenTime
|
||||||
|
) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
})(),
|
||||||
|
};
|
||||||
|
}, {});
|
||||||
|
},
|
||||||
|
|
||||||
|
_getSecureConnectionStartTimeInfo: function(timings) {
|
||||||
|
let secureConnectionStartTime = 0;
|
||||||
|
let secureConnectionStartTimeRelative = false;
|
||||||
|
|
||||||
|
if (timings.STATUS_TLS_STARTING && timings.STATUS_TLS_ENDING) {
|
||||||
|
if (timings.STATUS_CONNECTING_TO) {
|
||||||
|
secureConnectionStartTime =
|
||||||
|
timings.STATUS_TLS_STARTING.first -
|
||||||
|
timings.STATUS_CONNECTING_TO.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secureConnectionStartTime < 0) {
|
||||||
|
secureConnectionStartTime = 0;
|
||||||
|
}
|
||||||
|
secureConnectionStartTimeRelative = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
secureConnectionStartTime,
|
||||||
|
secureConnectionStartTimeRelative,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
_getStartSendingTimeInfo: function(timings, connectStartTimeTc) {
|
||||||
|
let startSendingTime = 0;
|
||||||
|
let startSendingTimeRelative = false;
|
||||||
|
|
||||||
|
if (timings.STATUS_SENDING_TO) {
|
||||||
|
if (timings.STATUS_CONNECTING_TO) {
|
||||||
|
startSendingTime =
|
||||||
|
timings.STATUS_SENDING_TO.first - timings.STATUS_CONNECTING_TO.first;
|
||||||
|
startSendingTimeRelative = true;
|
||||||
|
} else if (connectStartTimeTc != 0) {
|
||||||
|
startSendingTime = timings.STATUS_SENDING_TO.first - connectStartTimeTc;
|
||||||
|
startSendingTimeRelative = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startSendingTime < 0) {
|
||||||
|
startSendingTime = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { startSendingTime, startSendingTimeRelative };
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the HTTP activity object to include timing information as in the HAR
|
* Update the HTTP activity object to include timing information as in the HAR
|
||||||
* spec. The HTTP activity object holds the raw timing information in
|
* spec. The HTTP activity object holds the raw timing information in
|
||||||
|
|
@ -1064,7 +1208,7 @@ NetworkObserver.prototype = {
|
||||||
* - total - the total time for all of the request and response.
|
* - total - the total time for all of the request and response.
|
||||||
* - timings - the HAR timings object.
|
* - timings - the HAR timings object.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
_setupHarTimings: function(httpActivity, fromCache) {
|
_setupHarTimings: function(httpActivity, fromCache) {
|
||||||
if (fromCache) {
|
if (fromCache) {
|
||||||
// If it came from the browser cache, we have no timing
|
// If it came from the browser cache, we have no timing
|
||||||
|
|
@ -1100,50 +1244,18 @@ NetworkObserver.prototype = {
|
||||||
// relative to CONNECTING_TO.
|
// relative to CONNECTING_TO.
|
||||||
// Similary if 0RTT is used, data can be sent as soon as a TLS handshake
|
// Similary if 0RTT is used, data can be sent as soon as a TLS handshake
|
||||||
// starts.
|
// starts.
|
||||||
let secureConnectionStartTime = 0;
|
|
||||||
let secureConnectionStartTimeRelative = false;
|
|
||||||
let startSendingTime = 0;
|
|
||||||
let startSendingTimeRelative = false;
|
|
||||||
|
|
||||||
if (timings.STATUS_RESOLVING && timings.STATUS_CONNECTING_TO) {
|
|
||||||
harTimings.blocked =
|
|
||||||
timings.STATUS_RESOLVING.first - timings.REQUEST_HEADER.first;
|
|
||||||
} else if (timings.STATUS_SENDING_TO) {
|
|
||||||
harTimings.blocked =
|
|
||||||
timings.STATUS_SENDING_TO.first - timings.REQUEST_HEADER.first;
|
|
||||||
} else {
|
|
||||||
harTimings.blocked = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
harTimings.blocked = this._getBlockedTiming(timings);
|
||||||
// DNS timing information is available only in when the DNS record is not
|
// DNS timing information is available only in when the DNS record is not
|
||||||
// cached.
|
// cached.
|
||||||
harTimings.dns =
|
harTimings.dns = this._getDnsTiming(timings);
|
||||||
timings.STATUS_RESOLVING && timings.STATUS_RESOLVED
|
harTimings.connect = this._getConnectTiming(timings);
|
||||||
? timings.STATUS_RESOLVED.last - timings.STATUS_RESOLVING.first
|
harTimings.ssl = this._getSslTiming(timings);
|
||||||
: -1;
|
|
||||||
|
|
||||||
if (timings.STATUS_CONNECTING_TO && timings.STATUS_CONNECTED_TO) {
|
let {
|
||||||
harTimings.connect =
|
secureConnectionStartTime,
|
||||||
timings.STATUS_CONNECTED_TO.last - timings.STATUS_CONNECTING_TO.first;
|
secureConnectionStartTimeRelative,
|
||||||
} else {
|
} = this._getSecureConnectionStartTimeInfo(timings);
|
||||||
harTimings.connect = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timings.STATUS_TLS_STARTING && timings.STATUS_TLS_ENDING) {
|
|
||||||
harTimings.ssl =
|
|
||||||
timings.STATUS_TLS_ENDING.last - timings.STATUS_TLS_STARTING.first;
|
|
||||||
if (timings.STATUS_CONNECTING_TO) {
|
|
||||||
secureConnectionStartTime =
|
|
||||||
timings.STATUS_TLS_STARTING.first -
|
|
||||||
timings.STATUS_CONNECTING_TO.first;
|
|
||||||
}
|
|
||||||
if (secureConnectionStartTime < 0) {
|
|
||||||
secureConnectionStartTime = 0;
|
|
||||||
}
|
|
||||||
secureConnectionStartTimeRelative = true;
|
|
||||||
} else {
|
|
||||||
harTimings.ssl = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sometimes the connection information events are attached to a speculative
|
// sometimes the connection information events are attached to a speculative
|
||||||
// channel instead of this one, but necko might glue them back together in the
|
// channel instead of this one, but necko might glue them back together in the
|
||||||
|
|
@ -1152,73 +1264,26 @@ NetworkObserver.prototype = {
|
||||||
Ci.nsITimedChannel
|
Ci.nsITimedChannel
|
||||||
);
|
);
|
||||||
|
|
||||||
let tcTcpConnectEndTime = 0;
|
const {
|
||||||
let tcConnectStartTime = 0;
|
tcpConnectEndTimeTc,
|
||||||
let tcConnectEndTime = 0;
|
connectStartTimeTc,
|
||||||
let tcSecureConnectionStartTime = 0;
|
connectEndTimeTc,
|
||||||
let tcDomainLookupEndTime = 0;
|
secureConnectionStartTimeTc,
|
||||||
let tcDomainLookupStartTime = 0;
|
domainLookupEndTimeTc,
|
||||||
|
domainLookupStartTimeTc,
|
||||||
if (timedChannel) {
|
} = this._getDataFromTimedChannel(timedChannel);
|
||||||
tcTcpConnectEndTime = timedChannel.tcpConnectEndTime;
|
|
||||||
tcConnectStartTime = timedChannel.connectStartTime;
|
|
||||||
tcConnectEndTime = timedChannel.connectEndTime;
|
|
||||||
tcSecureConnectionStartTime = timedChannel.secureConnectionStartTime;
|
|
||||||
tcDomainLookupEndTime = timedChannel.domainLookupEndTime;
|
|
||||||
tcDomainLookupStartTime = timedChannel.domainLookupStartTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the above values are at least timedChannel.asyncOpenTime.
|
|
||||||
if (timedChannel && timedChannel.asyncOpenTime) {
|
|
||||||
if (
|
|
||||||
tcTcpConnectEndTime != 0 &&
|
|
||||||
tcTcpConnectEndTime < timedChannel.asyncOpenTime
|
|
||||||
) {
|
|
||||||
tcTcpConnectEndTime = 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
tcConnectStartTime != 0 &&
|
|
||||||
tcConnectStartTime < timedChannel.asyncOpenTime
|
|
||||||
) {
|
|
||||||
tcConnectStartTime = 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
tcConnectEndTime != 0 &&
|
|
||||||
tcConnectEndTime < timedChannel.asyncOpenTime
|
|
||||||
) {
|
|
||||||
tcConnectEndTime = 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
tcSecureConnectionStartTime != 0 &&
|
|
||||||
tcSecureConnectionStartTime < timedChannel.asyncOpenTime
|
|
||||||
) {
|
|
||||||
tcSecureConnectionStartTime = 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
tcDomainLookupEndTime != 0 &&
|
|
||||||
tcDomainLookupEndTime < timedChannel.asyncOpenTime
|
|
||||||
) {
|
|
||||||
tcDomainLookupEndTime = 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
tcDomainLookupStartTime != 0 &&
|
|
||||||
tcDomainLookupStartTime < timedChannel.asyncOpenTime
|
|
||||||
) {
|
|
||||||
tcDomainLookupStartTime = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
harTimings.connect <= 0 &&
|
harTimings.connect <= 0 &&
|
||||||
timedChannel &&
|
timedChannel &&
|
||||||
tcTcpConnectEndTime != 0 &&
|
tcpConnectEndTimeTc != 0 &&
|
||||||
tcConnectStartTime != 0
|
connectStartTimeTc != 0
|
||||||
) {
|
) {
|
||||||
harTimings.connect = tcTcpConnectEndTime - tcConnectStartTime;
|
harTimings.connect = tcpConnectEndTimeTc - connectStartTimeTc;
|
||||||
if (tcSecureConnectionStartTime != 0) {
|
if (secureConnectionStartTimeTc != 0) {
|
||||||
harTimings.ssl = tcConnectEndTime - tcSecureConnectionStartTime;
|
harTimings.ssl = connectEndTimeTc - secureConnectionStartTimeTc;
|
||||||
secureConnectionStartTime =
|
secureConnectionStartTime =
|
||||||
tcSecureConnectionStartTime - tcConnectStartTime;
|
secureConnectionStartTimeTc - connectStartTimeTc;
|
||||||
secureConnectionStartTimeRelative = true;
|
secureConnectionStartTimeRelative = true;
|
||||||
} else {
|
} else {
|
||||||
harTimings.ssl = -1;
|
harTimings.ssl = -1;
|
||||||
|
|
@ -1226,14 +1291,14 @@ NetworkObserver.prototype = {
|
||||||
} else if (
|
} else if (
|
||||||
timedChannel &&
|
timedChannel &&
|
||||||
timings.STATUS_TLS_STARTING &&
|
timings.STATUS_TLS_STARTING &&
|
||||||
tcSecureConnectionStartTime != 0
|
secureConnectionStartTimeTc != 0
|
||||||
) {
|
) {
|
||||||
// It can happen that TCP Fast Open actually have not sent any data and
|
// It can happen that TCP Fast Open actually have not sent any data and
|
||||||
// timings.STATUS_TLS_STARTING.first value will be corrected in
|
// timings.STATUS_TLS_STARTING.first value will be corrected in
|
||||||
// timedChannel.secureConnectionStartTime
|
// timedChannel.secureConnectionStartTime
|
||||||
if (tcSecureConnectionStartTime > timings.STATUS_TLS_STARTING.first) {
|
if (secureConnectionStartTimeTc > timings.STATUS_TLS_STARTING.first) {
|
||||||
// TCP Fast Open actually did not sent any data.
|
// TCP Fast Open actually did not sent any data.
|
||||||
harTimings.ssl = tcConnectEndTime - tcSecureConnectionStartTime;
|
harTimings.ssl = connectEndTimeTc - secureConnectionStartTimeTc;
|
||||||
secureConnectionStartTimeRelative = false;
|
secureConnectionStartTimeRelative = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1241,47 +1306,19 @@ NetworkObserver.prototype = {
|
||||||
if (
|
if (
|
||||||
harTimings.dns <= 0 &&
|
harTimings.dns <= 0 &&
|
||||||
timedChannel &&
|
timedChannel &&
|
||||||
tcDomainLookupEndTime != 0 &&
|
domainLookupEndTimeTc != 0 &&
|
||||||
tcDomainLookupStartTime != 0
|
domainLookupStartTimeTc != 0
|
||||||
) {
|
) {
|
||||||
harTimings.dns = tcDomainLookupEndTime - tcDomainLookupStartTime;
|
harTimings.dns = domainLookupEndTimeTc - domainLookupStartTimeTc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timings.STATUS_SENDING_TO) {
|
harTimings.send = this._getSendTiming(timings);
|
||||||
harTimings.send =
|
harTimings.wait = this._getWaitTiming(timings);
|
||||||
timings.STATUS_SENDING_TO.last - timings.STATUS_SENDING_TO.first;
|
harTimings.receive = this._getReceiveTiming(timings);
|
||||||
if (timings.STATUS_CONNECTING_TO) {
|
let {
|
||||||
startSendingTime =
|
startSendingTime,
|
||||||
timings.STATUS_SENDING_TO.first - timings.STATUS_CONNECTING_TO.first;
|
startSendingTimeRelative,
|
||||||
startSendingTimeRelative = true;
|
} = this._getStartSendingTimeInfo(timings, connectStartTimeTc);
|
||||||
} else if (tcConnectStartTime != 0) {
|
|
||||||
startSendingTime = timings.STATUS_SENDING_TO.first - tcConnectStartTime;
|
|
||||||
startSendingTimeRelative = true;
|
|
||||||
}
|
|
||||||
if (startSendingTime < 0) {
|
|
||||||
startSendingTime = 0;
|
|
||||||
}
|
|
||||||
} else if (timings.REQUEST_HEADER && timings.REQUEST_BODY_SENT) {
|
|
||||||
harTimings.send =
|
|
||||||
timings.REQUEST_BODY_SENT.last - timings.REQUEST_HEADER.first;
|
|
||||||
} else {
|
|
||||||
harTimings.send = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timings.RESPONSE_START) {
|
|
||||||
harTimings.wait =
|
|
||||||
timings.RESPONSE_START.first -
|
|
||||||
(timings.REQUEST_BODY_SENT || timings.STATUS_SENDING_TO).last;
|
|
||||||
} else {
|
|
||||||
harTimings.wait = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timings.RESPONSE_START && timings.RESPONSE_COMPLETE) {
|
|
||||||
harTimings.receive =
|
|
||||||
timings.RESPONSE_COMPLETE.last - timings.RESPONSE_START.first;
|
|
||||||
} else {
|
|
||||||
harTimings.receive = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secureConnectionStartTimeRelative) {
|
if (secureConnectionStartTimeRelative) {
|
||||||
const time = Math.max(Math.round(secureConnectionStartTime / 1000), -1);
|
const time = Math.max(Math.round(secureConnectionStartTime / 1000), -1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue