[+] 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 * @return bytes / second
*/ */
virtual double GetApproximatedThroughput() = 0; virtual double GetApproximatedThroughput() = 0;
/**
* @brief
* @return
*/
virtual AuUInt64 GetUptimeNS() = 0;
}; };
} }

View File

@ -339,6 +339,8 @@ namespace Aurora::IO::Net
this->RejectAllListeners(); this->RejectAllListeners();
this->socketChannel_.StopTime();
if (this->pSocketDriver_) if (this->pSocketDriver_)
{ {
try try
@ -363,6 +365,8 @@ namespace Aurora::IO::Net
this->error_ = error; this->error_ = error;
this->socketChannel_.StopTime();
if (this->pSocketDriver_) if (this->pSocketDriver_)
{ {
try try
@ -544,6 +548,8 @@ namespace Aurora::IO::Net
this->socketChannel_.uBytesInputBuffer = pServer->uDefaultInputStreamSize; 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 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 // think: setting up protocol stacks, accessing the base bytebuffer, without the pipe being
// allocated already // allocated already
@ -570,6 +576,8 @@ namespace Aurora::IO::Net
return; return;
} }
this->socketChannel_.StopTime();
if (this->pSocketDriver_) if (this->pSocketDriver_)
{ {
try try
@ -592,6 +600,8 @@ namespace Aurora::IO::Net
return; return;
} }
this->socketChannel_.StopTime();
this->pWorker_->RemoveSocket(this); this->pWorker_->RemoveSocket(this);
if (this->bHasErrored_) if (this->bHasErrored_)

View File

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

View File

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

View File

@ -12,26 +12,18 @@ namespace Aurora::IO::Net
{ {
void SocketStats::AddBytes(AuUInt32 uBytes) void SocketStats::AddBytes(AuUInt32 uBytes)
{ {
this->Start();
this->calculator.AddData(uBytes); this->calculator.AddData(uBytes);
auto uNow = AuTime::CurrentClockMS();
if (!this->iFirstTime)
{
this->iFirstTime = uNow;
}
this->iLastTime = uNow;
this->uLastTimeSteadyMS = AuTime::SteadyClockMS();
} }
AuInt64 SocketStats::GetFirstTickTimeMS() AuInt64 SocketStats::GetFirstTickTimeMS()
{ {
return this->iFirstTime; return this->uFirstTime;
} }
AuInt64 SocketStats::GetLastTickTimeMS() AuInt64 SocketStats::GetLastTickTimeMS()
{ {
return this->iLastTime; return this->calculator.GetLastFrameTimeWall();
} }
AuUInt64 SocketStats::GetTotalBytesTransferred() AuUInt64 SocketStats::GetTotalBytesTransferred()
@ -43,4 +35,37 @@ namespace Aurora::IO::Net
{ {
return this->calculator.GetEstimatedHertz(); 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 double GetApproximatedThroughput() override;
virtual AuUInt64 GetUptimeNS() override;
void Start();
void End();
AuUInt64 uLastTimeSteadyMS {}; AuUInt64 uLastTimeSteadyMS {};
private: private:
Aurora::Utility::ThroughputCalculator calculator; Aurora::Utility::ThroughputCalculator calculator;
AuInt64 iFirstTime {}; AuUInt64 uFirstTime {};
AuInt64 iLastTime {}; AuUInt64 uStartSteadyTime {};
AuUInt64 uTotalTransferred {}; AuUInt64 uEndSteadyTime {};
}; };
} }