Skip to content

profile uses uv.hrtime #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lua/nvim-tree/log.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local uv = vim.loop

local M = {
config = nil,
path = nil,
Expand All @@ -21,18 +23,24 @@ end

--- Write to log file via M.line
--- START is prefixed
--- @return reltime to pass to profile_end
--- @return nanos to pass to profile_end
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 "???"), ...)
return vim.fn.reltime()
return uv.hrtime()
end

--- Write to log file via M.line
--- 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, ...)
local dur = vim.fn.reltimestr(vim.fn.reltime(start, vim.fn.reltime()))
M.line("profile", "END " .. (fmt or "???") .. " " .. dur .. "s", ...)
if not M.path or not M.config.types.profile and not M.config.types.all then
return
end
local millis = start and math.modf((uv.hrtime() - start) / 1000000) or -1
M.line("profile", "END " .. (fmt or "???") .. " " .. millis .. "ms", ...)
end

-- Write to log file via M.raw
Expand Down