Path: blob/main/src/resources/pandoc/datadir/profiler.lua
12926 views
--[[1A low-overhead minimal lua profiler.23It requires cooperation from the lua interpreter itself, which we patch, and then4compile a custom pandoc binary.56In other words, this is not meant to be used by regular quarto users.7]]89local getTime = os.clock10local category = "unknown"11local module = {}12local outputfile13local stack_count = 01415-- don't colect coverage for this module16-- luacov: disable17local onDebugHook = function(hookType, line)18if hookType ~= "alarm" then19print("Internal Error - Unexpected hook type in debug hook: " .. hookType)20print("For Quarto profiling to work, you need to run a patched version of Pandoc.")21print("This feature is currently only meant to be used by Quarto developers.")22os.exit(1)23end24local no = 225local information = debug.getinfo(no, "nS")26local now = os.clock()27while information ~= nil do28local source = information.source or "unknown"29local name = information.name or "anon"30if source:sub(1, 1) == "@" then31outputfile:write(name, " ", source, " ", information.linedefined, "\n")32else33outputfile:write(name, " ", "<inline>", " ", 0, "\n")34end35no = no + 136information = debug.getinfo(no, "nS")37end38outputfile:write(stack_count, " ", now, " ", category, " ", line, "\n")39stack_count = stack_count + 140end4142function module.setcategory(c)43category = c44end4546function module.start(filename, ms)47outputfile = io.open(filename, "a")48if outputfile == nil then49error("Could not open " .. filename .. " for writing")50return51end52debug.sethook(onDebugHook, "t", ms or 5) -- NB: "t" debugging only exists in our patched Lua interpreter/pandoc binary!53end5455function module.stop()56debug.sethook()57outputfile:close()58end59-- luacov: enable6061return module626364