Skip to content

Commit

Permalink
fix(stats): use fallback for cputime on windows. Fixes #280
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 2, 2023
1 parent c1a50a7 commit ddcdc5e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/lazy/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ M.C = nil

function M.on_ui_enter()
M._stats.startuptime = M.track("UIEnter")
M._stats.startuptime_cputime = M.C ~= false
M._stats.startuptime_cputime = M.C.clock_gettime ~= nil
vim.cmd([[do User LazyVimStarted]])
end

Expand All @@ -33,7 +33,7 @@ end

function M.cputime()
if M.C == nil then
local ok = pcall(function()
pcall(function()
ffi.cdef([[
typedef long time_t;
typedef int clockid_t;
Expand All @@ -44,9 +44,9 @@ function M.cputime()
int clock_gettime(clockid_t clk_id, struct timespec *tp);
]])
end)
M.C = ok and ffi.C or false
M.C = ffi.C
end
if M.C then
if M.C.clock_gettime then
local pnano = assert(ffi.new("nanotime[?]", 1))
local CLOCK_PROCESS_CPUTIME_ID = jit.os == "OSX" and 12 or 2
ffi.C.clock_gettime(CLOCK_PROCESS_CPUTIME_ID, pnano)
Expand Down

0 comments on commit ddcdc5e

Please sign in to comment.