feat: added profiler view

This commit is contained in:
Folke Lemaitre 2022-11-29 12:02:25 +01:00
parent 08b7e42fb0
commit 20ff5fa218
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
9 changed files with 81 additions and 61 deletions

View file

@ -17,7 +17,7 @@ M.defaults = {
view = {
icons = {
start = "",
plugin = "",
plugin = " ",
source = "",
config = "",
event = "",

View file

@ -53,7 +53,7 @@ function M.handlers.event(grouped)
once = true,
pattern = pattern,
callback = function()
Util.track("event: " .. (_event == "User" and pattern or event))
Util.track({ event = event })
Loader.load(plugins, { event = event })
Util.track()
end,
@ -67,7 +67,7 @@ function M.handlers.keys(grouped)
---@cast keys string
vim.keymap.set("n", keys, function()
vim.keymap.del("n", keys)
Util.track("keys: " .. keys)
Util.track({ keys = keys })
Loader.load(plugins, { keys = keys })
vim.api.nvim_input(keys)
Util.track()
@ -84,7 +84,7 @@ function M.handlers.ft(grouped)
pattern = ft,
group = group,
callback = function()
Util.track("filetype: " .. ft)
Util.track({ ft = ft })
Loader.load(plugins, { ft = ft })
Util.track()
end,
@ -95,13 +95,9 @@ end
function M.handlers.cmd(grouped)
for cmd, plugins in pairs(grouped) do
---@cast cmd string
local function _load(complete)
local function _load()
vim.api.nvim_del_user_command(cmd)
if complete then
Util.track("cmd-complete: " .. cmd)
else
Util.track("cmd: " .. cmd)
end
Util.track({ cmd = cmd })
Loader.load(plugins, { cmd = cmd })
Util.track()
end
@ -120,7 +116,7 @@ function M.handlers.cmd(grouped)
bang = true,
nargs = "*",
complete = function()
_load(true)
_load()
-- HACK: trick Neovim to show the newly loaded command completion
vim.api.nvim_input("<space><bs><tab>")
end,

View file

@ -22,7 +22,7 @@ function M.init_plugins()
Util.track("plugin_init")
for _, plugin in pairs(Config.plugins) do
if plugin.init then
Util.track(plugin.name)
Util.track({ plugin = plugin.name, start = "init" })
Util.try(plugin.init, "Failed to run `init` for **" .. plugin.name .. "**")
Util.track()
end
@ -58,7 +58,7 @@ function M.load(plugins, reason, opts)
table.insert(M.loading, plugin)
Util.track(plugin.name)
Util.track({ plugin = plugin.name, start = reason.start })
M.packadd(plugin, opts and opts.load_start)
if plugin.requires then

View file

@ -1,16 +1,16 @@
local M = {}
---@alias LazyProfile {name: string, time: number, [number]:LazyProfile}
---@alias LazyProfile {data: string|{[string]:string}, time: number, [number]:LazyProfile}
---@type LazyProfile[]
M._profiles = { { name = "lazy" } }
---@param name string?
---@param data (string|{[string]:string})?
---@param time number?
function M.track(name, time)
if name then
function M.track(data, time)
if data then
local entry = {
name = name,
data = data,
time = time or vim.loop.hrtime(),
}
table.insert(M._profiles[#M._profiles], entry)