getMonotonicNanosecondsSinceUnixEpoch#
Fully qualified name: carb::time::getMonotonicNanosecondsSinceUnixEpoch
Defined in carb/time/Util.h
- inline std::chrono::nanoseconds carb::time::getMonotonicNanosecondsSinceUnixEpoch(
- std::chrono::nanoseconds absTimestampNs,
- std::chrono::nanoseconds steadyTimestampNs = std::chrono::nanoseconds(0),
Calculates the approximate monotonic time in nanoseconds since the Unix epoch.
Note
If the system wall clock time is incorrect on the first call, the results from this function will continue to be incorrect for the remainder of the process. All of the returned times will still be somewhat accurate relative to the steady clock epoch (usually system boot time).
Note
All clocks drift. The system wall clock time is periodically corrected through NTP updates because of this. However, the monotonic clocks do not get such updates and any drift that occurs in them will be permanent for the session and accumulate in timing results.
- Parameters:
absTimestampNs – [in] The absolute timestamp in nanoseconds since the Unix epoch to be used to calculate the absolute timestamp of the arbitrary epoch used for the steady clock. This value will only be consumed on the first call so that a consistent epoch is used for all calculations.
steadyTimestampNs – [in] The current monotonic/steady timestamp in nanoseconds since an arbitrary but consistent epoch (usually system boot time). This can be the value returned from getSteadyTimestampNs(). The source of this value should be consistent for all calls. This value may be 0 to use getSteadyTimestampNs() instead to get the monotonic timestamp. Defaults to 0.
- Returns:
The calculated absolute monotonic timestamp in nanoseconds. This will always be relative to the Unix epoch (midnight January 1, 1970) but is not guaranteed to be accurate since it would not be subject to wall clock time corrections All the returned timestamps will be monotonically increasing, but will likely drift especially over very long sessions.