AuroraRuntime/Source/Process/AuProcessStartTime.cpp

63 lines
1.7 KiB
C++
Raw Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuProcessStartTime.cpp
Date: 2023-7-10
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuProcessStartTime.hpp"
#include <Time/Time.hpp>
namespace Aurora::Process
{
static AuOptional<AuUInt64> gOptKnownStartupWallTime;
static AuOptional<AuUInt64> gOptKnownStartupSteadyTime;
void WarmStartupCaches()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
FILETIME creation, exit, kernel, user;
if (::GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user))
{
auto u64 = AuTime::ConvertTimestampNs(creation);
gOptKnownStartupWallTime = u64;
u64 += AuTime::SteadyClockNS() - AuTime::CurrentClockNS();
gOptKnownStartupSteadyTime = u64;
}
#else
auto u64 = AuTime::ThreadClockNS();
gOptKnownStartupWallTime = AuTime::CurrentClockNS() - u64;
gOptKnownStartupSteadyTime = AuTime::SteadyClockNS() - u64;
#endif
}
AUKN_SYM AuUInt64 GetProcessStartupTimeNS()
{
if (gOptKnownStartupWallTime.has_value())
{
return gOptKnownStartupWallTime.value();
}
WarmStartupCaches();
return gOptKnownStartupWallTime.value();
}
AUKN_SYM AuUInt64 GetProcessStartupTimeMS()
{
return AuNSToMS<AuUInt64>(GetProcessStartupTimeNS());
}
AUKN_SYM AuUInt64 GetProcessStartupSteadyTimeNS()
{
if (gOptKnownStartupSteadyTime.has_value())
{
return gOptKnownStartupSteadyTime.value();
}
WarmStartupCaches();
return gOptKnownStartupSteadyTime.value();
}
}