libs/core: record peak values in luci.debug
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 18 Jul 2009 18:26:44 +0000 (18:26 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 18 Jul 2009 18:26:44 +0000 (18:26 +0000)
libs/core/luasrc/debug.lua

index d64700e0e17179267f85046c8aabbadb80001734..3969254a95369a098392256aec3cdaf214616e81 100644 (file)
@@ -9,15 +9,19 @@ __file__ = debug.getinfo(1, 'S').source:sub(2)
 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")
+               if collectgarbage("count") > peak then
+                       peak = collectgarbage("count")
+               end
                if tracefile then
                        tracefile:write(
                                "[", what, "] ", info.source, ":", (line or "?"), "\t",
                                (info.namewhat or ""), "\t",
                                (info.name or ""), "\t",
-                               collectgarbage("count"), "\n"
+                               collectgarbage("count"), " (", peak, ")\n"
                        )
                end
        end