Bug 1243062 - Add telemetry for PR_Close time. r=mcmanus

This commit is contained in:
Dragana Damjanovic 2016-01-26 11:15:00 +01:00
Родитель 4aff274ce6
Коммит 9422329793
2 изменённых файлов: 61 добавлений и 4 удалений

Просмотреть файл

@ -1205,7 +1205,7 @@ nsSocketTransport::BuildSocket(PRFileDesc *&fd, bool &proxyTransparent, bool &us
if (NS_FAILED(rv)) {
SOCKET_LOG((" error pushing io layer [%u:%s rv=%x]\n", i, mTypes[i], rv));
if (fd) {
PR_Close(fd);
CloseSocket(fd, mSocketTransportService->IsTelemetryEnabled());
}
}
}
@ -1369,7 +1369,7 @@ nsSocketTransport::InitiateSocket()
// inform socket transport about this newly created socket...
rv = mSocketTransportService->AttachSocket(fd, this);
if (NS_FAILED(rv)) {
PR_Close(fd);
CloseSocket(fd, mSocketTransportService->IsTelemetryEnabled());
return rv;
}
mAttached = true;
@ -1727,7 +1727,8 @@ public:
NS_IMETHOD Run()
{
PR_Close(mFD);
nsSocketTransport::CloseSocket(mFD,
gSocketTransportService->IsTelemetryEnabled());
return NS_OK;
}
private:
@ -1764,7 +1765,7 @@ nsSocketTransport::ReleaseFD_Locked(PRFileDesc *fd)
SOCKET_LOG(("Intentional leak"));
} else if (PR_GetCurrentThread() == gSocketThread) {
SOCKET_LOG(("nsSocketTransport: calling PR_Close [this=%p]\n", this));
PR_Close(mFD);
CloseSocket(mFD, mSocketTransportService->IsTelemetryEnabled());
} else {
// Can't PR_Close() a socket off STS thread. Thunk it to STS to die
STS_PRCloseOnSocketTransport(mFD);
@ -3069,6 +3070,29 @@ nsSocketTransport::PRFileDescAutoLock::SetKeepaliveVals(bool aEnabled,
#endif
}
void
nsSocketTransport::CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled) {
// We use PRIntervalTime here because we need
// nsIOService::LastOfflineStateChange time and
// nsIOService::LastConectivityChange time to be atomic.
PRIntervalTime closeStarted;
if (aTelemetryEnabled) {
closeStarted = PR_IntervalNow();
}
PR_Close(aFd);
if (aTelemetryEnabled) {
SendPRBlockingTelemetry(closeStarted,
Telemetry::PRCLOSE_TCP_BLOCKING_TIME_NORMAL,
Telemetry::PRCLOSE_TCP_BLOCKING_TIME_SHUTDOWN,
Telemetry::PRCLOSE_TCP_BLOCKING_TIME_CONNECTIVITY_CHANGE,
Telemetry::PRCLOSE_TCP_BLOCKING_TIME_LINK_CHANGE,
Telemetry::PRCLOSE_TCP_BLOCKING_TIME_OFFLINE);
}
}
void
nsSocketTransport::SendPRBlockingTelemetry(PRIntervalTime aStart,
Telemetry::ID aIDNormal,

Просмотреть файл

@ -784,7 +784,40 @@ nsUDPSocket::CloseSocket()
// If shutdown last to long, let the socket leak and do not close it.
UDPSOCKET_LOG(("Intentional leak"));
} else {
PRIntervalTime closeStarted = 0;
if (gSocketTransportService->IsTelemetryEnabled()) {
closeStarted = PR_IntervalNow();
}
PR_Close(mFD);
if (gSocketTransportService->IsTelemetryEnabled()) {
PRIntervalTime now = PR_IntervalNow();
if (gIOService->IsNetTearingDown()) {
Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_SHUTDOWN,
PR_IntervalToMilliseconds(now - closeStarted));
} else if (PR_IntervalToSeconds(now - gIOService->LastConnectivityChange())
< 60) {
Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_CONNECTIVITY_CHANGE,
PR_IntervalToMilliseconds(now - closeStarted));
} else if (PR_IntervalToSeconds(now - gIOService->LastNetworkLinkChange())
< 60) {
Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_LINK_CHANGE,
PR_IntervalToMilliseconds(now - closeStarted));
} else if (PR_IntervalToSeconds(now - gIOService->LastOfflineStateChange())
< 60) {
Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_OFFLINE,
PR_IntervalToMilliseconds(now - closeStarted));
} else {
Telemetry::Accumulate(Telemetry::PRCLOSE_UDP_BLOCKING_TIME_NORMAL,
PR_IntervalToMilliseconds(now - closeStarted));
}
}
}
mFD = nullptr;
}