You don't have to modify any of your existing code to use this tool.
Basically, you require the profiler and tell it when to start/stop collecting data.
It's good to reset the profiler every 100 frames so you can look for bottlenecks in real-time.
Example:
Code: Select all
-- setup
function love.load()
love.profiler = require('profile')
love.profiler.start()
end
-- usage (generates a report every 100 frames)
love.frame = 0
function love.update(dt)
love.frame = love.frame + 1
if love.frame%100 == 0 then
love.report = love.profiler.report(20)
love.profiler.reset()
end
end
-- prints the report
function love.draw()
love.graphics.print(love.report or "Please wait...")
end
Code: Select all
--- Starts collecting data.
function profile.start()
--- Resets all collected data.
function profile.reset()
--- Stops collecting data.
function profile.stop()
--- Generates a report from the collected data.
-- @param s Type of sorting, could be by "call" (number of calls) or "time" (execution time)
-- @return Report string
function profile.report(n)
Dependencies: pure Lua, uses the "debug" module
Memory: uses a lot of memory so make sure your GC is not disabled
CPU: calling functions is slower while profiling so make sure to disable it in production code
Limitations: hooking C functions is not very useful but you don't really need to profile those anyways