diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-06-11 13:29:05 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2014-06-11 13:29:05 +0000 |
commit | 7043c30e0e55bbbfacdddf97619b6bae96d20ddb (patch) | |
tree | ece3254350b3ba01ba3135caed2364cc7ca7804c /modules/base/luasrc/debug.lua | |
parent | bbb44cf245c11bc0c1d59e836007c9e8c3bfa209 (diff) |
build: introduce luci-base
Merges libs/core, libs/ipkg, libs/web, libs/sys, libs/sgi-cgi, libs/sgi-uhttpd,
modules/admin-core, themes/base and protcols/core into modules/base and renames
luci-lib-core to luci-base.
Diffstat (limited to 'modules/base/luasrc/debug.lua')
-rw-r--r-- | modules/base/luasrc/debug.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/modules/base/luasrc/debug.lua b/modules/base/luasrc/debug.lua new file mode 100644 index 0000000000..8ff1bb6981 --- /dev/null +++ b/modules/base/luasrc/debug.lua @@ -0,0 +1,37 @@ +local debug = require "debug" +local io = require "io" +local collectgarbage, floor = collectgarbage, math.floor + +module "luci.debug" +__file__ = debug.getinfo(1, 'S').source:sub(2) + +-- Enables the memory tracer with given flags and returns a function to disable the tracer again +function trap_memtrace(flags, dest) + flags = flags or "clr" + local tracefile = io.open(dest or "/tmp/memtrace", "w") + local peak = 0 + + local function trap(what, line) + local info = debug.getinfo(2, "Sn") + local size = floor(collectgarbage("count")) + if size > peak then + peak = size + end + if tracefile then + tracefile:write( + "[", what, "] ", info.source, ":", (line or "?"), "\t", + (info.namewhat or ""), "\t", + (info.name or ""), "\t", + size, " (", peak, ")\n" + ) + end + end + + debug.sethook(trap, flags) + + return function() + debug.sethook() + tracefile:close() + end +end + |