$ luarocks install lua-mtrace
The module returns a single function that takes a single file name as
argument. When called, it replaces the Lua memory allocation function
with one that logs what it does to the file. It returns a function that
restores the original allocator.
undo = require "mtrace" "/tmp/mtrace.log"