You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes comparing file system timestamp with "current time" is necessary. An example would be doing something like make.
To make it reliable, this ""current time" should be get from a clock source that is compatible with file system.
On Posix, I assume it is roughly CLOCK_REALTIME, and possibly around CLOCK_REALTIME_COARSE for linux.
Currently, node doesn't seem to have such API.
process.hrtime() is a monotonic clock, which can drift from real time clock. (so it should be used even if the origin is synced with utc)
Date.now() goes through a series of indrects and ends up with v8/src/base/platform/time.cc: Time::Now(),
which becomes gettimeofday(timezone=null) on linux, and an interpolated value between (rebased) QueryPerformanceCounter() and GetSystemTimeAsFileTime() on windows.
What is the feature you are proposing to solve the problem?
Add an API: fs.hrtime(), which uses:
clock_gettime(CLOCK_REALTIME_COARSE) on linux.
Use accurate file system clock if possible, on other platforms.
Fallback to libuv uv_clock_gettime(UV_CLOCK_REALTIME) otherwise,
which ends up with clock_gettime(CLOCK_REALTIME) on posix, and GetSystemTimePreciseAsFileTime() on windows.
What alternatives have you considered?
Add a explicit clock API, maybe under process, which doesn't imply that it is a file system clock.
Expose the relevant platform specific clock sources under it:
Posix clock_gettime(CLOCK_REALTIME)
Linux clock_gettime(CLOCK_REALTIME_COARSE)
Windows GetSystemTimePreciseAsFileTime()
The text was updated successfully, but these errors were encountered:
What is the problem this feature will solve?
Sometimes comparing file system timestamp with "current time" is necessary. An example would be doing something like
make
.To make it reliable, this ""current time" should be get from a clock source that is compatible with file system.
https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime
https://learn.microsoft.com/en-us/windows/win32/sysinfo/file-times
CLOCK_REALTIME
, and possibly aroundCLOCK_REALTIME_COARSE
for linux.Currently, node doesn't seem to have such API.
process.hrtime()
is a monotonic clock, which can drift from real time clock. (so it should be used even if the origin is synced with utc)Date.now()
goes through a series of indrects and ends up withv8/src/base/platform/time.cc: Time::Now()
,which becomes
gettimeofday(timezone=null)
on linux, and an interpolated value between(rebased) QueryPerformanceCounter()
andGetSystemTimeAsFileTime()
on windows.What is the feature you are proposing to solve the problem?
Add an API:
fs.hrtime()
, which uses:clock_gettime(CLOCK_REALTIME_COARSE)
on linux.uv_clock_gettime(UV_CLOCK_REALTIME)
otherwise,which ends up with
clock_gettime(CLOCK_REALTIME)
on posix, andGetSystemTimePreciseAsFileTime()
on windows.What alternatives have you considered?
Add a explicit clock API, maybe under
process
, which doesn't imply that it is a file system clock.Expose the relevant platform specific clock sources under it:
clock_gettime(CLOCK_REALTIME)
clock_gettime(CLOCK_REALTIME_COARSE)
GetSystemTimePreciseAsFileTime()
The text was updated successfully, but these errors were encountered: