2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: Clock.hpp
|
|
|
|
Date: 2021-6-10
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-24 18:37:06 +00:00
|
|
|
#include "ETimezoneShift.hpp"
|
|
|
|
#include "TM.hpp"
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
namespace Aurora::Time
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
Converts milliseconds from the Aurora epoch to a civil timestamp structure
|
|
|
|
similar to or of std::tm
|
|
|
|
*/
|
2022-01-19 15:25:47 +00:00
|
|
|
AUKN_SYM tm ToCivilTime(AuInt64 time, bool UTC = true);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Converts civil time to milliseconds from the Aurora epoch
|
|
|
|
*/
|
2022-01-19 15:25:47 +00:00
|
|
|
AUKN_SYM AuInt64 FromCivilTime(const tm &time, bool UTC = true);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-24 18:37:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Normalizes a civil data structure with respect to UTC, given the two input parameters 'in' civil and 'shiftFrom' timezone hint
|
|
|
|
*/
|
|
|
|
AUKN_SYM tm NormalizeCivilTimezone(const tm &in, ETimezoneShift shiftFrom = ETimezoneShift::eUTC);
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
Translates the Aurora epoch to the standard unix epoch
|
2021-06-27 21:25:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuInt64 ConvertAuroraToUnixMS(AuInt64 in);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
Translates the Aurora epoch to the standard unix epoch
|
2021-06-27 21:25:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuInt64 ConvertAuroraToUnixNS(AuInt64 in);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
Translates a standard unix epoch to the Aurora epoch
|
2021-06-27 21:25:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuInt64 ConvertUnixToAuroraMS(AuInt64 in);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-12-06 22:53:37 +00:00
|
|
|
/**
|
|
|
|
Translates a standard unix epoch to the Aurora epoch
|
|
|
|
*/
|
|
|
|
AUKN_SYM AuInt64 ConvertUnixToAuroraNS(AuInt64 in);
|
2022-11-28 16:01:08 +00:00
|
|
|
|
2022-12-06 22:53:37 +00:00
|
|
|
/**
|
|
|
|
Retrieves wall clock in milliseconds from the Aurora epoch
|
|
|
|
*/
|
|
|
|
AUKN_SYM AuInt64 CurrentClockMS();
|
2022-11-28 16:01:08 +00:00
|
|
|
|
2021-10-21 10:04:29 +00:00
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
Retrieves wall clock in nanoseconds from the Aurora epoch
|
2021-10-21 10:04:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuInt64 CurrentClockNS();
|
2021-10-21 10:04:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
* @brief Steady clock in jiffies
|
|
|
|
* @return
|
2021-10-21 10:04:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuUInt64 SteadyClock();
|
2021-10-21 10:04:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
Returns a steady system clock of SteadyClockJiffies() with an undefined epoch.
|
|
|
|
|
|
|
|
These values should be used to drive thread primitives, IO time, and tick delta.
|
|
|
|
On a modern plaform, these should be affected by the users' calendar or NTP.
|
|
|
|
On stinkier platforms, who cares if we can run mostly bug free with an assumed-sane wall-clock, right?
|
2021-10-21 10:04:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuUInt64 SteadyClockMS();
|
2021-10-21 10:04:29 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-06 22:53:37 +00:00
|
|
|
* @brief
|
|
|
|
* @return
|
2021-10-21 10:04:29 +00:00
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuUInt64 SteadyClockNS();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the freqency of jiffies per second
|
|
|
|
*/
|
|
|
|
AUKN_SYM AuUInt64 SteadyClockJiffies();
|
2021-10-21 10:04:29 +00:00
|
|
|
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
/**
|
|
|
|
Returns a high resolution count of jiffies with an undefined epoch from a
|
|
|
|
high resolution clock.
|
|
|
|
|
2022-12-06 22:53:37 +00:00
|
|
|
These values should be used to drive benchmarks.
|
2021-06-27 21:25:29 +00:00
|
|
|
These values should not nor can be accurately converted meaningfully
|
|
|
|
*/
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuUInt64 HighResClock();
|
|
|
|
AUKN_SYM AuUInt64 HighResClockMS();
|
|
|
|
AUKN_SYM AuUInt64 HighResClockNS();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the freqency of jiffies per second
|
|
|
|
*/
|
|
|
|
AUKN_SYM AuUInt64 HighResClockJiffies();
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Let's say you're fucked and you need a ball park figure.
|
|
|
|
Enjoy...
|
|
|
|
*/
|
|
|
|
AUKN_SYM AuUInt64 ConvertInternalToAuroraEpochMS(AuUInt64 in);
|
|
|
|
AUKN_SYM AuUInt64 ConvertInternalToAuroraEpochNS(AuUInt64 in);
|
2021-10-21 10:04:29 +00:00
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
/**
|
2021-10-21 10:04:29 +00:00
|
|
|
Converts seconds from the Aurora epoch to time_t
|
2021-06-27 21:25:29 +00:00
|
|
|
*/
|
2021-10-21 10:04:29 +00:00
|
|
|
AUKN_SYM time_t SToCTime(AuInt64 time);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
2021-10-21 10:04:29 +00:00
|
|
|
Converts nanoseconds from the Aurora epoch to time_t
|
2021-06-27 21:25:29 +00:00
|
|
|
*/
|
2021-10-21 10:04:29 +00:00
|
|
|
AUKN_SYM time_t NSToCTime(AuInt64 time);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
2021-10-21 10:04:29 +00:00
|
|
|
Converts milliseconds from the Aurora epoch to time_t
|
2021-06-27 21:25:29 +00:00
|
|
|
*/
|
2021-10-21 10:04:29 +00:00
|
|
|
AUKN_SYM time_t MSToCTime(AuInt64 time);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-12-06 22:53:37 +00:00
|
|
|
AUKN_SYM AuInt64 CTimeToMS(time_t time);
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the freqency as a fraction of: jiffies per second / 1 * nanoseconds in a second
|
|
|
|
*/
|
|
|
|
AUKN_SYM double CPUFrequencyDeltaNS();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the freqency as a fraction of: jiffies per second / 1 * milliseconds in a second
|
|
|
|
*/
|
|
|
|
AUKN_SYM double CPUFrequencyDeltaMS();
|
|
|
|
|
2022-04-20 23:34:08 +00:00
|
|
|
}
|