local profile = require("profile") profile.start() -- execute code that will be profiled profile.stop() -- report for the top 10 functions, sorted by execution time print(profile.report(10))
-- setup function love.load() love.profiler = require('profile') love.profiler.start() end
-- 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
+-----+----------------------------------+----------+--------------------------+----------------------------------+ | # | Function | Calls | Time | Code | +-----+----------------------------------+----------+--------------------------+----------------------------------+ | 1 | update | 1 | 9.0023296745494 | main.lua:23 | | 2 | f | 1 | 9.0022503120126 | main.lua:12 | | 3 | g | 8 | 8.0016986143455 | main.lua:5 | | 4 | [string "boot.lua"]:185 | 3 | 2.4960798327811e-005 | [string "boot.lua"]:185 | | 5 | [string "boot.lua"]:134 | 2 | 1.7920567188412e-005 | [string "boot.lua"]:134 | | 6 | [string "boot.lua"]:188 | 1 | 1.6000514733605e-005 | [string "boot.lua"]:188 | | 7 | [string "boot.lua"]:182 | 1 | 1.2160395272076e-005 | [string "boot.lua"]:182 | | 8 | [string "boot.lua"]:131 | 1 | 1.0240328265354e-005 | [string "boot.lua"]:131 | | 9 | load | 0 | 0 | main.lua:17 | +-----+----------------------------------+----------+--------------------------+----------------------------------+
print('Position,Function name,Number of calls,Time,Source,') for t in ipairs(profiler.query(10)) do print(table.concat(t, ",")..",") end
profile.comp(a, b) |
profile.hooker(event, line, info) |
profile.query(limit) |
profile.report(limit) |
profile.reset() |
profile.setclock(func) |
profile.start() |
profile.stop() |
Arguments | |
---|---|
function | a First function |
function | b Second function |
Returns | |
boolean | True if "a" should rank higher than "b" |
Arguments | |
---|---|
string | event Event type |
number | line Line number |
table | info (optional) Debug info table |
Arguments | |
---|---|
number | limit (optional) Maximum number of rows |
Returns | |
table | Table of rows |
Arguments | |
---|---|
number | limit (optional) Maximum number of rows |
Returns | |
string | Text-based profiling report |
Arguments | |
---|---|
function | func Clock function that returns a number |