2023-03-21 10:05:45 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuClocks.cpp
|
|
|
|
Date: 2023-3-21
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <RuntimeInternal.hpp>
|
|
|
|
#include "AuClocks.hpp"
|
|
|
|
|
|
|
|
namespace Aurora::Time
|
|
|
|
{
|
|
|
|
#define ADD_CLOCK(name, enum, jiffies, getNs, getMs) \
|
|
|
|
struct name ## Clock_t : IClock \
|
|
|
|
{ \
|
|
|
|
EClock GetType() override \
|
|
|
|
{ \
|
|
|
|
return EClock::enum; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
AuUInt64 GetHertz() override \
|
|
|
|
{ \
|
|
|
|
return jiffies(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
AuUInt64 NowNS() override \
|
|
|
|
{ \
|
|
|
|
return getNs(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
AuUInt64 NowMS() override \
|
|
|
|
{ \
|
|
|
|
return getMs(); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static name ## Clock_t gClock## name ## Instance; \
|
|
|
|
\
|
|
|
|
AUKN_SYM AuSPtr<IClock> Get ## name ## Clock() \
|
|
|
|
{ \
|
|
|
|
return AuUnsafeRaiiToShared(&gClock## name ## Instance); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FILE_AND_USR_DIR_STEP (AuMSToNS<AuUInt64>(AuSToMS<AuUInt64>(1)) / 100ull)
|
|
|
|
|
|
|
|
ADD_CLOCK(Steady, eSteady, SteadyClockJiffies, SteadyClockNS, SteadyClockMS);
|
|
|
|
ADD_CLOCK(Wall, eWall, FILE_AND_USR_DIR_STEP + AuUInt64, CurrentClockNS, CurrentClockMS);
|
2023-04-21 21:08:56 +00:00
|
|
|
ADD_CLOCK(Process, eProcessTime, ProcessClockJiffies, ProcessClockNS, ProcessClockMS);
|
2023-06-19 16:26:41 +00:00
|
|
|
ADD_CLOCK(ProcessKernel, eProcessKernelTime, ProcessKernelClockJiffies, ProcessKernelClockNS, ProcessKernelClockMS);
|
|
|
|
ADD_CLOCK(ProcessUser, eProcessUserTime, ProcessUserClockJiffies, ProcessUserClockNS, ProcessUserClockMS);
|
2023-04-21 21:08:56 +00:00
|
|
|
ADD_CLOCK(Thread, eThreadTime, ThreadClockJiffies, ThreadClockNS, ThreadClockMS);
|
2023-06-19 16:26:41 +00:00
|
|
|
ADD_CLOCK(ThreadKernel, eThreadKernelTime, ThreadKernelClockJiffies, ThreadKernelClockNS, ThreadKernelClockMS);
|
|
|
|
ADD_CLOCK(ThreadUser, eThreadUserTime, ThreadUserClockJiffies, ThreadUserClockNS, ThreadUserClockMS);
|
2023-03-21 10:05:45 +00:00
|
|
|
|
|
|
|
#undef FILE_AND_USR_DIR_STEP
|
|
|
|
#undef ADD_CLOCK
|
|
|
|
|
|
|
|
AUKN_SYM AuSPtr<IClock> GetClockFromEnum(EClock clock)
|
|
|
|
{
|
|
|
|
switch (clock)
|
|
|
|
{
|
|
|
|
case EClock::eWall:
|
|
|
|
return GetWallClock();
|
2023-06-19 16:26:41 +00:00
|
|
|
case EClock::eSteady:
|
|
|
|
return GetSteadyClock();
|
2023-03-21 10:05:45 +00:00
|
|
|
case EClock::eProcessTime:
|
|
|
|
return GetProcessClock();
|
2023-06-19 16:26:41 +00:00
|
|
|
case EClock::eProcessUserTime:
|
|
|
|
return GetProcessUserClock();
|
|
|
|
case EClock::eProcessKernelTime:
|
|
|
|
return GetProcessKernelClock();
|
2023-04-21 21:08:56 +00:00
|
|
|
case EClock::eThreadTime:
|
2023-06-19 16:26:41 +00:00
|
|
|
return GetThreadClock();
|
|
|
|
case EClock::eThreadUserTime:
|
|
|
|
return GetThreadUserClock();
|
|
|
|
case EClock::eThreadKernelTime:
|
|
|
|
return GetThreadKernelClock();
|
2023-03-21 10:05:45 +00:00
|
|
|
default:
|
|
|
|
SysPushErrorArg("Invalid clock");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|