Difference between revisions of "profile"

(Documentation and sourcecode)
(profile.lua)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
== profile.lua ==
 
== profile.lua ==
profile.lua is a real-time, non-intrusive tool for finding bottlenecks in your game. You don't have to modify any of your existing code to use this tool. 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.
+
profile.lua is a small module used for finding bottlenecks in your Lua code. To use the profiler, you need to require the profile.lua file and specify when to start or stop collecting data. Once you are done profiling, a report is generated, describing:
 +
 
 +
* which functions were called most frequently and
 +
* how much time was spent executing each function
 +
 
 +
== Example ==
 +
<source lang="lua">
 +
-- 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
 +
</source>
  
 
== Documentation and source code ==
 
== Documentation and source code ==
Line 9: Line 36:
 
{{#set:LOVE Version=Any}}
 
{{#set:LOVE Version=Any}}
 
{{#set:Description=A real-time profiler for finding bottlenecks in your game}}
 
{{#set:Description=A real-time profiler for finding bottlenecks in your game}}
{{#set:Keyword=Profiling}}
+
{{#set:Keyword=Debug}}
 
[[Category:Libraries]]
 
[[Category:Libraries]]
  
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|profile}}
 
{{i18n|profile}}

Latest revision as of 09:10, 9 October 2024

profile.lua

profile.lua is a small module used for finding bottlenecks in your Lua code. To use the profiler, you need to require the profile.lua file and specify when to start or stop collecting data. Once you are done profiling, a report is generated, describing:

  • which functions were called most frequently and
  • how much time was spent executing each function

Example

-- 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

Documentation and source code

https://github.com/2dengine/profile.lua

https://2dengine.com/doc/profile.html

Other Languages