deprecate old profiler in favor of snacks.profiler

Use PROF=1 env variable to enable startup profiling
This commit is contained in:
2025-02-11 20:48:09 -05:00
parent 98ab9da88c
commit 588a46e239
2 changed files with 23 additions and 0 deletions
-56
View File
@@ -1,56 +0,0 @@
--- @module "config.profile"
--- This module configures the profiler for the Neovim configuration.
--- This tool can be used to profile specific modules or all modules.
---
--- The profiler can be toggled with the leader keybinding `d<f1>`
--- or with the `NVIM_PROFILE` environment variable.
---
--- Specific modules can be selected with the `NVIM_PROFILE_MODULE`
--- environment variable.
-- ╭─────────────────────────────────────────────────────────╮
-- │ PROFILER │
-- ╰─────────────────────────────────────────────────────────╯
-- Check if the environment variable is set
local should_profile = os.getenv('NVIM_PROFILE')
local profile_module = os.getenv('NVIM_PROFILE_MODULE') or '*'
-- Start the profiler
if should_profile then
require('profile').instrument_autocmds()
if should_profile:lower():match('^start') then
require('profile').start(profile_module)
else
require('profile').instrument(profile_module)
end
end
-- Function to toggle the profiler
local function toggle_profile()
local prof = require('profile')
if prof.is_recording() then
prof.stop()
vim.ui.input({
prompt = 'Save profile to:',
completion = 'file',
default = 'profile.json',
}, function(filename)
if filename then
prof.export(filename)
vim.notify(string.format('Wrote %s', filename))
end
end)
else
prof.start(profile_module)
end
end
-- Add the keybind to toggle the profiler
require('data').func.add_keymap('<leader>d<f1>', function()
local prof_name = profile_module
if profile_module == '*' then
prof_name = 'all'
end
print('Profiling module: ' .. prof_name)
toggle_profile()
end, 'Toggle Profiler')
+23
View File
@@ -0,0 +1,23 @@
--- @module "config.profiler"
--- This module configures the profiler for the Neovim configuration.
--- This tool can be used to profile specific modules or all modules.
---
--- The profiler can be toggled with the leader keybinding `d<f1>`
--- or with the `PROF` environment variable.
-- ╭─────────────────────────────────────────────────────────╮
-- │ PROFILER │
-- ╰─────────────────────────────────────────────────────────╯
if vim.env.PROF then
-- example for lazy.nvim
-- change this to the correct path for your plugin manager
local snacks = vim.fn.stdpath('data') .. '/lazy/snacks.nvim'
vim.opt.rtp:append(snacks)
require('snacks.profiler').startup({
startup = {
event = 'VimEnter', -- stop profiler on this event. Defaults to `VimEnter`
-- event = "UIEnter",
-- event = "VeryLazy",
},
})
end