2023-07-10 15:29:38 +00:00
|
|
|
/***
|
|
|
|
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"
|
2023-07-10 20:37:28 +00:00
|
|
|
#include <Time/Time.hpp>
|
2023-07-10 15:29:38 +00:00
|
|
|
|
|
|
|
namespace Aurora::Process
|
|
|
|
{
|
2023-12-18 05:57:37 +00:00
|
|
|
static AuOptional<AuUInt64> gOptKnownStartupWallTime;
|
|
|
|
static AuOptional<AuUInt64> gOptKnownStartupSteadyTime;
|
2023-07-10 15:29:38 +00:00
|
|
|
|
2023-12-18 05:57:37 +00:00
|
|
|
void WarmStartupCaches()
|
|
|
|
{
|
2023-07-10 20:37:28 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
FILETIME creation, exit, kernel, user;
|
|
|
|
if (::GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user))
|
2023-07-10 15:29:38 +00:00
|
|
|
{
|
2023-12-18 05:57:37 +00:00
|
|
|
auto u64 = AuTime::ConvertTimestampNs(creation);
|
|
|
|
gOptKnownStartupWallTime = u64;
|
|
|
|
u64 += AuTime::SteadyClockNS() - AuTime::CurrentClockNS();
|
|
|
|
gOptKnownStartupSteadyTime = u64;
|
2023-07-10 15:29:38 +00:00
|
|
|
}
|
2023-07-10 20:37:28 +00:00
|
|
|
#else
|
2023-12-18 05:57:37 +00:00
|
|
|
auto u64 = AuTime::ThreadClockNS();
|
|
|
|
gOptKnownStartupWallTime = AuTime::CurrentClockNS() - u64;
|
|
|
|
gOptKnownStartupSteadyTime = AuTime::SteadyClockNS() - u64;
|
2023-07-10 20:37:28 +00:00
|
|
|
#endif
|
2023-12-18 05:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuUInt64 GetProcessStartupTimeNS()
|
|
|
|
{
|
|
|
|
if (gOptKnownStartupWallTime.has_value())
|
|
|
|
{
|
|
|
|
return gOptKnownStartupWallTime.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
WarmStartupCaches();
|
2023-07-10 15:29:38 +00:00
|
|
|
|
2023-12-18 05:57:37 +00:00
|
|
|
return gOptKnownStartupWallTime.value();
|
2023-07-10 15:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuUInt64 GetProcessStartupTimeMS()
|
|
|
|
{
|
|
|
|
return AuNSToMS<AuUInt64>(GetProcessStartupTimeNS());
|
|
|
|
}
|
2023-12-13 22:13:28 +00:00
|
|
|
|
|
|
|
AUKN_SYM AuUInt64 GetProcessStartupSteadyTimeNS()
|
|
|
|
{
|
2023-12-18 05:57:37 +00:00
|
|
|
if (gOptKnownStartupSteadyTime.has_value())
|
2023-12-13 22:13:28 +00:00
|
|
|
{
|
2023-12-18 05:57:37 +00:00
|
|
|
return gOptKnownStartupSteadyTime.value();
|
2023-12-13 22:13:28 +00:00
|
|
|
}
|
|
|
|
|
2023-12-18 05:57:37 +00:00
|
|
|
WarmStartupCaches();
|
2023-12-13 22:13:28 +00:00
|
|
|
|
2023-12-18 05:57:37 +00:00
|
|
|
return gOptKnownStartupSteadyTime.value();
|
2023-12-13 22:13:28 +00:00
|
|
|
}
|
2023-07-10 15:29:38 +00:00
|
|
|
}
|