AuroraRuntime/Source/IO/Net/AuSocketStats.cpp
Jamie Reece Wilson 1f685b635b [+] ISocketStats::GetUptimeNS
[*] Some socket stat cleanup+fixes
2023-10-23 09:17:46 +01:00

71 lines
1.5 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuSocketStats.cpp
Date: 2022-12-06
Author: Reece
***/
#include "Networking.hpp"
#include "AuSocketStats.hpp"
namespace Aurora::IO::Net
{
void SocketStats::AddBytes(AuUInt32 uBytes)
{
this->Start();
this->calculator.AddData(uBytes);
}
AuInt64 SocketStats::GetFirstTickTimeMS()
{
return this->uFirstTime;
}
AuInt64 SocketStats::GetLastTickTimeMS()
{
return this->calculator.GetLastFrameTimeWall();
}
AuUInt64 SocketStats::GetTotalBytesTransferred()
{
return this->calculator.GetTotalStats();
}
double SocketStats::GetApproximatedThroughput()
{
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();
}
}