mirror of
https://github.com/neovim/neovim.git
synced 2026-08-28 18:11:47 +00:00
fix(excmd): use realtime for v:starttime, :uptime #39425
Problem: `v:starttime`, `:uptime` use a monotonic high-resolution timer. This only works as long as the timer keeps running (if the computer is suspended the timer is paused). This is somewhat unintuitive, and doesn't match the behavior of the `uptime` shell command. Solution: Implement `os_realtime` to get the real time since the epoch in nanoseconds.
This commit is contained in:
@@ -259,7 +259,9 @@ function M.ex_terminal(eap, shell_argv)
|
||||
end
|
||||
|
||||
function M.ex_uptime()
|
||||
local uptime = math.floor((uv.hrtime() - vim.v.starttime) / 1e9)
|
||||
-- os.time() might lead to uptime == -1 when this is called too quickly after startup
|
||||
local now = assert(uv.clock_gettime('realtime'))
|
||||
local uptime = math.floor((now.sec * 1e9 + now.nsec - vim.v.starttime) / 1e9)
|
||||
local uptime_display = time.fmt_rtime(uptime)
|
||||
api.nvim_echo({ { N_('Up %s'):format(uptime_display) } }, true, {})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user