feat(profiling): added options to enable additional profiling

This commit is contained in:
Folke Lemaitre 2023-10-09 12:38:43 +02:00
parent ce3e8523de
commit 423a152e94
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
6 changed files with 102 additions and 60 deletions

View File

@ -355,6 +355,7 @@ return {
not_loaded = "○", not_loaded = "○",
plugin = " ", plugin = " ",
runtime = " ", runtime = " ",
require = "󰢱 ",
source = " ", source = " ",
start = "", start = "",
task = "✔ ", task = "✔ ",
@ -448,6 +449,15 @@ return {
-- executed. In this case, a warning message will be shown. -- executed. In this case, a warning message will be shown.
warn_on_override = true, warn_on_override = true,
}, },
-- Enable profiling of lazy.nvim. This will add some overhead,
-- so only enable this when you are debugging lazy.nvim
profiling = {
-- Enables extra stats on the debug tab related to the loader cache.
-- Additionally gathers stats about all package.loaders
loader = false,
-- Track each new require in the Lazy profiling tab
require = false,
},
} }
``` ```
@ -496,7 +506,7 @@ Any operation can be started from the UI, with a sub command or an API function:
<!-- commands:start --> <!-- commands:start -->
| Command | Lua | Description | | Command | Lua | Description |
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | --- | --- | --- | --- |
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin | | `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) | | `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed | | `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
@ -764,38 +774,39 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori
<!-- colors:start --> <!-- colors:start -->
| Highlight Group | Default Group | Description | | Highlight Group | Default Group | Description |
| --------------------- | -------------------------- | --------------------------------------------------- | | --- | --- | --- |
| **LazyButton** | **_CursorLine_** | | | **LazyButton** | ***CursorLine*** | |
| **LazyButtonActive** | **_Visual_** | | | **LazyButtonActive** | ***Visual*** | |
| **LazyComment** | **_Comment_** | | | **LazyComment** | ***Comment*** | |
| **LazyCommit** | **_@variable.builtin_** | commit ref | | **LazyCommit** | ***@variable.builtin*** | commit ref |
| **LazyCommitIssue** | **_Number_** | | | **LazyCommitIssue** | ***Number*** | |
| **LazyCommitScope** | **_Italic_** | conventional commit scope | | **LazyCommitScope** | ***Italic*** | conventional commit scope |
| **LazyCommitType** | **_Title_** | conventional commit type | | **LazyCommitType** | ***Title*** | conventional commit type |
| **LazyDimmed** | **_Conceal_** | property | | **LazyDimmed** | ***Conceal*** | property |
| **LazyDir** | **_@text.reference_** | directory | | **LazyDir** | ***@text.reference*** | directory |
| **LazyH1** | **_IncSearch_** | home button | | **LazyH1** | ***IncSearch*** | home button |
| **LazyH2** | **_Bold_** | titles | | **LazyH2** | ***Bold*** | titles |
| **LazyLocal** | **_Constant_** | | | **LazyLocal** | ***Constant*** | |
| **LazyNoCond** | **_DiagnosticWarn_** | unloaded icon for a plugin where `cond()` was false | | **LazyNoCond** | ***DiagnosticWarn*** | unloaded icon for a plugin where `cond()` was false |
| **LazyNormal** | **_NormalFloat_** | | | **LazyNormal** | ***NormalFloat*** | |
| **LazyProgressDone** | **_Constant_** | progress bar done | | **LazyProgressDone** | ***Constant*** | progress bar done |
| **LazyProgressTodo** | **_LineNr_** | progress bar todo | | **LazyProgressTodo** | ***LineNr*** | progress bar todo |
| **LazyProp** | **_Conceal_** | property | | **LazyProp** | ***Conceal*** | property |
| **LazyReasonCmd** | **_Operator_** | | | **LazyReasonCmd** | ***Operator*** | |
| **LazyReasonEvent** | **_Constant_** | | | **LazyReasonEvent** | ***Constant*** | |
| **LazyReasonFt** | **_Character_** | | | **LazyReasonFt** | ***Character*** | |
| **LazyReasonImport** | **_Identifier_** | | | **LazyReasonImport** | ***Identifier*** | |
| **LazyReasonKeys** | **_Statement_** | | | **LazyReasonKeys** | ***Statement*** | |
| **LazyReasonPlugin** | **_Special_** | | | **LazyReasonPlugin** | ***Special*** | |
| **LazyReasonRuntime** | **_@macro_** | | | **LazyReasonRequire** | ***@parameter*** | |
| **LazyReasonSource** | **_Character_** | | | **LazyReasonRuntime** | ***@macro*** | |
| **LazyReasonStart** | **_@field_** | | | **LazyReasonSource** | ***Character*** | |
| **LazySpecial** | **_@punctuation.special_** | | | **LazyReasonStart** | ***@field*** | |
| **LazyTaskError** | **_ErrorMsg_** | task errors | | **LazySpecial** | ***@punctuation.special*** | |
| **LazyTaskOutput** | **_MsgArea_** | task output | | **LazyTaskError** | ***ErrorMsg*** | task errors |
| **LazyUrl** | **_@text.reference_** | url | | **LazyTaskOutput** | ***MsgArea*** | task output |
| **LazyValue** | **_@string_** | value of a property | | **LazyUrl** | ***@text.reference*** | url |
| **LazyValue** | ***@string*** | value of a property |
<!-- colors:end --> <!-- colors:end -->

View File

@ -65,6 +65,7 @@ M.defaults = {
not_loaded = "", not_loaded = "",
plugin = "", plugin = "",
runtime = "", runtime = "",
require = "󰢱 ",
source = "", source = "",
start = "", start = "",
task = "", task = "",
@ -158,6 +159,15 @@ M.defaults = {
-- executed. In this case, a warning message will be shown. -- executed. In this case, a warning message will be shown.
warn_on_override = true, warn_on_override = true,
}, },
-- Enable profiling of lazy.nvim. This will add some overhead,
-- so only enable this when you are debugging lazy.nvim
profiling = {
-- Enables extra stats on the debug tab related to the loader cache.
-- Additionally gathers stats about all package.loaders
loader = false,
-- Track each new require in the Lazy profiling tab
require = false,
},
debug = false, debug = false,
} }

View File

@ -118,7 +118,7 @@ function M.get_source()
if not info then if not info then
break break
end end
if info.what ~= "C" and not info.source:find("lazy.nvim", 1, true) then if info.what ~= "C" and not info.source:find("lazy.nvim", 1, true) and info.source ~= "@vim/loader.lua" then
return info.source:sub(2) return info.source:sub(2)
end end
f = f + 1 f = f + 1

View File

@ -2,6 +2,23 @@
local M = {} local M = {}
M._start = 0 M._start = 0
local function profile_require()
local done = {} ---@type table<string, true>
local r = require
_G.require = function(modname)
local Util = package.loaded["lazy.core.util"]
if Util and not done[modname] then
done[modname] = true
Util.track({ require = modname })
local ret = vim.F.pack_len(r(modname))
Util.track()
return vim.F.unpack_len(ret)
else
return r(modname)
end
end
end
---@overload fun(opts: LazyConfig) ---@overload fun(opts: LazyConfig)
---@overload fun(spec:LazySpec, opts: LazyConfig) ---@overload fun(spec:LazySpec, opts: LazyConfig)
function M.setup(spec, opts) function M.setup(spec, opts)
@ -40,17 +57,16 @@ function M.setup(spec, opts)
local Cache = require("lazy.core.cache") local Cache = require("lazy.core.cache")
local enable_cache = not ( local enable_cache = vim.tbl_get(opts, "performance", "cache", "enabled") ~= false
opts
and opts.performance
and opts.performance.cache
and opts.performance.cache.enabled == false
)
-- load module cache before anything else -- load module cache before anything else
if enable_cache then if enable_cache then
Cache.enable() Cache.enable()
end end
if vim.tbl_get(opts, "profiling", "require") then
profile_require()
end
require("lazy.stats").track("LazyStart") require("lazy.stats").track("LazyStart")
local Util = require("lazy.core.util") local Util = require("lazy.core.util")
@ -59,8 +75,12 @@ function M.setup(spec, opts)
table.insert(package.loaders, 3, Loader.loader) table.insert(package.loaders, 3, Loader.loader)
if vim.g.profile_loaders then if vim.tbl_get(opts, "profiling", "loader") then
Cache.profile_loaders() if vim.loader then
vim.loader._profile({ loaders = true })
else
Cache._profile_loaders()
end
end end
Util.track({ plugin = "lazy.nvim" }) -- setup start Util.track({ plugin = "lazy.nvim" }) -- setup start

View File

@ -26,6 +26,7 @@ M.colors = {
ReasonFt = "Character", ReasonFt = "Character",
ReasonCmd = "Operator", ReasonCmd = "Operator",
ReasonImport = "Identifier", ReasonImport = "Identifier",
ReasonRequire = "@parameter",
Button = "CursorLine", Button = "CursorLine",
ButtonActive = "Visual", ButtonActive = "Visual",
TaskOutput = "MsgArea", -- task output TaskOutput = "MsgArea", -- task output

View File

@ -320,7 +320,7 @@ function M:reason(reason, opts)
for _, key in ipairs(keys) do for _, key in ipairs(keys) do
local value = reason[key] local value = reason[key]
if type(key) == "number" then if type(key) == "number" then
elseif key == "require" then -- elseif key == "require" then
elseif key ~= "time" then elseif key ~= "time" then
if first then if first then
first = false first = false