1 local debug = require "debug"
2 local io = require "io"
3 local collectgarbage = collectgarbage
6 __file__ = debug.getinfo(1, 'S').source:sub(2)
8 -- Enables the memory tracer with given flags and returns a function to disable the tracer again
9 function trap_memtrace(flags, dest)
10 flags = flags or "clr"
11 local tracefile = io.open(dest or "/tmp/memtrace", "w")
13 local function trap(what, line)
14 local info = debug.getinfo(2, "Sn")
17 "[", what, "] ", info.source, ":", (line or "?"), "\t",
18 (info.namewhat or ""), "\t",
19 (info.name or ""), "\t",
20 collectgarbage("count"), "\n"
25 debug.sethook(trap, flags)