control profiling with NVIM_PROFILE env variable or F1 key

This commit is contained in:
Alexander Gehrke 2025-05-23 10:02:18 +02:00
parent e317dca789
commit 37309c0edd
6 changed files with 627 additions and 4 deletions

View file

@ -1,9 +1,29 @@
if vim.env["VIRTUAL_ENV"] ~= nil then
vim.g.python3_host_prog = vim.fn.system("which -a python3 | sed -n 2p | tr -d '\n'")
else
vim.g.python3_host_prog = vim.fn.system("which python3 | tr -d '\n'")
local should_profile = os.getenv("NVIM_PROFILE")
if should_profile then
require("profile").instrument_autocmds()
if should_profile:lower():match("^start") then
require("profile").start("*")
else
require("profile").instrument("*")
end
end
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("*")
end
end
vim.keymap.set("", "<f1>", toggle_profile)
-- lazy.nvim bootstrap
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then