Skip to content

Commit bd23c88

Browse files
authored
profile uses uv.hrtime (#1110)
1 parent 591b648 commit bd23c88

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lua/nvim-tree/log.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local uv = vim.loop
2+
13
local M = {
24
config = nil,
35
path = nil,
@@ -21,18 +23,24 @@ end
2123

2224
--- Write to log file via M.line
2325
--- START is prefixed
24-
--- @return reltime to pass to profile_end
26+
--- @return nanos to pass to profile_end
2527
function M.profile_start(fmt, ...)
28+
if not M.path or not M.config.types.profile and not M.config.types.all then
29+
return
30+
end
2631
M.line("profile", "START " .. (fmt or "???"), ...)
27-
return vim.fn.reltime()
32+
return uv.hrtime()
2833
end
2934

3035
--- Write to log file via M.line
3136
--- END is prefixed and duration in seconds is suffixed
32-
--- @param start reltime returned from profile_start
37+
--- @param start nanos returned from profile_start
3338
function M.profile_end(start, fmt, ...)
34-
local dur = vim.fn.reltimestr(vim.fn.reltime(start, vim.fn.reltime()))
35-
M.line("profile", "END " .. (fmt or "???") .. " " .. dur .. "s", ...)
39+
if not M.path or not M.config.types.profile and not M.config.types.all then
40+
return
41+
end
42+
local millis = start and math.modf((uv.hrtime() - start) / 1000000) or -1
43+
M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...)
3644
end
3745

3846
-- Write to log file via M.raw

0 commit comments

Comments
 (0)