[+] ISocketStats::GetUptimeNS

[*] Some socket stat cleanup+fixes
This commit is contained in:
Reece Wilson 2023-10-23 09:04:36 +01:00
parent a5b7ea9af4
commit 1f685b635b
6 changed files with 76 additions and 14 deletions

View File

@ -34,5 +34,11 @@ namespace Aurora::IO::Net
* @return bytes / second
*/
virtual double GetApproximatedThroughput() = 0;
/**
* @brief
* @return
*/
virtual AuUInt64 GetUptimeNS() = 0;
};
}

View File

@ -339,6 +339,8 @@ namespace Aurora::IO::Net
this->RejectAllListeners();
this->socketChannel_.StopTime();
if (this->pSocketDriver_)
{
try
@ -363,6 +365,8 @@ namespace Aurora::IO::Net
this->error_ = error;
this->socketChannel_.StopTime();
if (this->pSocketDriver_)
{
try
@ -544,6 +548,8 @@ namespace Aurora::IO::Net
this->socketChannel_.uBytesInputBuffer = pServer->uDefaultInputStreamSize;
}
this->socketChannel_.StartTime();
this->socketChannel_.inputChannel.WarmOnEstablish(); // Allocate stream resources, in case we need to start working with the source buffer
// think: setting up protocol stacks, accessing the base bytebuffer, without the pipe being
// allocated already
@ -570,6 +576,8 @@ namespace Aurora::IO::Net
return;
}
this->socketChannel_.StopTime();
if (this->pSocketDriver_)
{
try
@ -592,6 +600,8 @@ namespace Aurora::IO::Net
return;
}
this->socketChannel_.StopTime();
this->pWorker_->RemoveSocket(this);
if (this->bHasErrored_)

View File

@ -525,9 +525,22 @@ namespace Aurora::IO::Net
return true;
}
void SocketChannel::StopTime()
{
this->sendStats_.End();
this->recvStats_.End();
}
void SocketChannel::StartTime()
{
this->sendStats_.Start();
this->recvStats_.Start();
}
void SocketChannel::Release()
{
this->StopTime();
this->PrivateUserDataClear();
this->pCachedReader.reset();

View File

@ -119,6 +119,9 @@ namespace Aurora::IO::Net
AuThreadPrimitives::SpinLock spinLock;
AuList<AuSPtr<ISocketChannelEventListener>> eventListeners;
void StopTime();
void StartTime();
void Release();
private:

View File

@ -12,26 +12,18 @@ namespace Aurora::IO::Net
{
void SocketStats::AddBytes(AuUInt32 uBytes)
{
this->Start();
this->calculator.AddData(uBytes);
auto uNow = AuTime::CurrentClockMS();
if (!this->iFirstTime)
{
this->iFirstTime = uNow;
}
this->iLastTime = uNow;
this->uLastTimeSteadyMS = AuTime::SteadyClockMS();
}
AuInt64 SocketStats::GetFirstTickTimeMS()
{
return this->iFirstTime;
return this->uFirstTime;
}
AuInt64 SocketStats::GetLastTickTimeMS()
{
return this->iLastTime;
return this->calculator.GetLastFrameTimeWall();
}
AuUInt64 SocketStats::GetTotalBytesTransferred()
@ -43,4 +35,37 @@ namespace Aurora::IO::Net
{
return this->calculator.GetEstimatedHertz();
}
AuUInt64 SocketStats::GetUptimeNS()
{
if (auto uStartTime = this->uStartSteadyTime)
{
if (auto uEndTime = this->uEndSteadyTime)
{
return uEndTime - uStartTime;
}
else
{
return AuTime::SteadyClockNS() - uStartTime;
}
}
else
{
return 0;
}
}
void SocketStats::Start()
{
if (!this->uFirstTime)
{
this->uFirstTime = AuTime::CurrentClockMS();
this->uStartSteadyTime = AuTime::SteadyClockNS();
}
}
void SocketStats::End()
{
this->uEndSteadyTime = AuTime::SteadyClockNS();
}
}

View File

@ -23,11 +23,16 @@ namespace Aurora::IO::Net
virtual double GetApproximatedThroughput() override;
virtual AuUInt64 GetUptimeNS() override;
void Start();
void End();
AuUInt64 uLastTimeSteadyMS {};
private:
Aurora::Utility::ThroughputCalculator calculator;
AuInt64 iFirstTime {};
AuInt64 iLastTime {};
AuUInt64 uTotalTransferred {};
AuUInt64 uFirstTime {};
AuUInt64 uStartSteadyTime {};
AuUInt64 uEndSteadyTime {};
};
}