profile uses uv.hrtime (#1110)
This commit is contained in:
committed by
GitHub
parent
591b64873f
commit
bd23c88608
@@ -1,3 +1,5 @@
|
|||||||
|
local uv = vim.loop
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
config = nil,
|
config = nil,
|
||||||
path = nil,
|
path = nil,
|
||||||
@@ -21,18 +23,24 @@ end
|
|||||||
|
|
||||||
--- Write to log file via M.line
|
--- Write to log file via M.line
|
||||||
--- START is prefixed
|
--- START is prefixed
|
||||||
--- @return reltime to pass to profile_end
|
--- @return nanos to pass to profile_end
|
||||||
function M.profile_start(fmt, ...)
|
function M.profile_start(fmt, ...)
|
||||||
|
if not M.path or not M.config.types.profile and not M.config.types.all then
|
||||||
|
return
|
||||||
|
end
|
||||||
M.line("profile", "START " .. (fmt or "???"), ...)
|
M.line("profile", "START " .. (fmt or "???"), ...)
|
||||||
return vim.fn.reltime()
|
return uv.hrtime()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Write to log file via M.line
|
--- Write to log file via M.line
|
||||||
--- END is prefixed and duration in seconds is suffixed
|
--- END is prefixed and duration in seconds is suffixed
|
||||||
--- @param start reltime returned from profile_start
|
--- @param start nanos returned from profile_start
|
||||||
function M.profile_end(start, fmt, ...)
|
function M.profile_end(start, fmt, ...)
|
||||||
local dur = vim.fn.reltimestr(vim.fn.reltime(start, vim.fn.reltime()))
|
if not M.path or not M.config.types.profile and not M.config.types.all then
|
||||||
M.line("profile", "END " .. (fmt or "???") .. " " .. dur .. "s", ...)
|
return
|
||||||
|
end
|
||||||
|
local millis = start and math.modf((uv.hrtime() - start) / 1000000) or -1
|
||||||
|
M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Write to log file via M.raw
|
-- Write to log file via M.raw
|
||||||
|
|||||||
Reference in New Issue
Block a user