Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several <a href="http://lua-users.org/wiki/ProfilingLuaCode" rel="noreferrer">profilers available</a> that you can check, but most of them target execution time (and are based on debug hook).</p> <p>To track variables, you will need to use <code>debug.getlocal</code> and <code>debug.getupvalue</code> (from your code or from debug hook).</p> <p>To track memory usage you can use <code>collectgarbage(count)</code> (probably after <code>collectgarbage(collect)</code>), but this only tells you total memory in use. To track individual data structures, you may need traverse global and local variables and calculate the amount of space they take. You can check <a href="http://lua-users.org/lists/lua-l/2012-09/msg00122.html" rel="noreferrer">this discussion</a> for some pointers and implementation details.</p> <p>Something like this would be the simplest profiler that tracks function calls/returns (note that you should not trust absolute numbers it generates, only relative ones):</p> <pre><code>local calls, total, this = {}, {}, {} debug.sethook(function(event) local i = debug.getinfo(2, "Sln") if i.what ~= 'Lua' then return end local func = i.name or (i.source..':'..i.linedefined) if event == 'call' then this[func] = os.clock() else local time = os.clock() - this[func] total[func] = (total[func] or 0) + time calls[func] = (calls[func] or 0) + 1 end end, "cr") -- the code to debug starts here local function DoSomethingMore(x) x = x / 2 end local function DoSomething(x) x = x + 1 if x % 2 then DoSomethingMore(x) end end for outer=1,100 do for inner=1,1000 do DoSomething(inner) end end -- the code to debug ends here; reset the hook debug.sethook() -- print the results for f,time in pairs(total) do print(("Function %s took %.3f seconds after %d calls"):format(f, time, calls[f])) end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload