Skip to content

Commit

Permalink
feat(profile): add profile plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
konosubakonoakua committed Aug 20, 2024
1 parent cb6d353 commit 8866773
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,31 @@ _G.trace = function(...)
if _G.fei.debug_on then require("util.debug").bt(...) end
end

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)

require("config.lazy")
3 changes: 3 additions & 0 deletions lua/plugins/extras/util/profile.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
"stevearc/profile.nvim",
}

0 comments on commit 8866773

Please sign in to comment.