oz
oz
DDeno
Created by oz on 8/18/2024 in #help
Which CLOCK does `Temporal` API implementation use in a deno runtime?
How is the following typescript line implemented in the deno runtime to get the nanoseconds from epoch, which system CLOCK or SYSCALL does it use, is it possible for a deno contributor to point me towards the (rust?) source code for the implementation?
return Temporal.Now.instant().epochNanoseconds;
return Temporal.Now.instant().epochNanoseconds;
Details: I'm writing an extternal process that uses ffi to integrate with a typescript process in a deno runtime. I want to get nanosecond-precision timestamps in my ffi process that are consistent with the timestamps in ts. When I use REALTIME as the clock: - On ubuntu I get nanoseconds from epoch resolution, and I'm good. :check: - On macosx I get microseconds from epoch resolution, and that's a problem. :no: Below I've read the various clocks on macosx preceeded by their resolutions. Notice .nsec field in the first res line for a clock gives the resolution in nanoseconds, and the .sec + .nsec fields in the second now line for a clock reading give the current time stamp for that clock. Notice only REALTIME clock has the proper time since epoch, but has it in 1000 .nsec => microsecond resolution so returns 000 for the last three digits of .nsec in the reading. The other clocks will drift from real time over time, and I may not get consistent readings in the ffi process as in the deno typescript process.
REALTIME
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1000 }
now: c.timespec__struct_1709{ .sec = 1723929530, .nsec = 899220000 }
MONOTONIC
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1000 }
now: c.timespec__struct_1709{ .sec = 2251, .nsec = 728543000 }
MONOTONIC_RAW
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810452119 }
MONOTONIC_RAW_APPROX
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810428836 }
UPTIME_RAW
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810461026 }
UPTIME_RAW_APPROX
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810428836 }
PROCESS_CPUTIME_ID
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1000 }
now: c.timespec__struct_1709{ .sec = 0, .nsec = 874756000 }
THREAD_CPUTIME_ID
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 0, .nsec = 874763051 }
REALTIME
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1000 }
now: c.timespec__struct_1709{ .sec = 1723929530, .nsec = 899220000 }
MONOTONIC
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1000 }
now: c.timespec__struct_1709{ .sec = 2251, .nsec = 728543000 }
MONOTONIC_RAW
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810452119 }
MONOTONIC_RAW_APPROX
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810428836 }
UPTIME_RAW
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810461026 }
UPTIME_RAW_APPROX
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 2253, .nsec = 810428836 }
PROCESS_CPUTIME_ID
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1000 }
now: c.timespec__struct_1709{ .sec = 0, .nsec = 874756000 }
THREAD_CPUTIME_ID
res: c.timespec__struct_1709{ .sec = 0, .nsec = 1 }
now: c.timespec__struct_1709{ .sec = 0, .nsec = 874763051 }
Question How is the following typescript line implemented in the deno runtime to get the nanoseconds from epoch, which system CLOCK or SYSCALL does it use, is it possible for a deno contributor to point me towards the (rust?) source code for the implementation?
return Temporal.Now.instant().epochNanoseconds;
return Temporal.Now.instant().epochNanoseconds;
2 replies