diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2008-06-12 10:42:53 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2008-06-12 10:42:53 +0000 |
commit | 0d01365d53c456d246da0ca1f0b3cd9868f02b35 (patch) | |
tree | 01a655c8028e17cfb371456b299c1848fe08c05b /Master/texmf-dist/tex/context/base/luat-tra.lua | |
parent | 44f3714442da07fdfc36a7f2a8dcd5d4294c5d26 (diff) |
ConTeXt release 2008.05.21
git-svn-id: svn://tug.org/texlive/trunk@8691 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/luat-tra.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/luat-tra.lua | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/luat-tra.lua b/Master/texmf-dist/tex/context/base/luat-tra.lua new file mode 100644 index 00000000000..7fc97319563 --- /dev/null +++ b/Master/texmf-dist/tex/context/base/luat-tra.lua @@ -0,0 +1,108 @@ +-- filename : luat-tra.lua +-- comment : companion to luat-lib.tex +-- author : Hans Hagen, PRAGMA-ADE, Hasselt NL +-- copyright: PRAGMA ADE / ConTeXt Development Team +-- license : see context related readme files + +if not versions then versions = { } end versions['luat-tra'] = 1.001 + +debugger = { } + +do + + local counters = { } + local names = { } + local getinfo = debug.getinfo + + local function hook() + local f = getinfo(2,"f").func + if f then + if counters[f] == nil then + counters[f] = 1 +--~ names[f] = debug.getinfo(2,"Sn") + names[f] = debug.getinfo(2,"n") +--~ names[f] = debug.getinfo(f) + else + counters[f] = counters[f] + 1 + end + end + end + + local function getname(func) + local n = names[func] + if n then + if n.what == "C" then + return n.name or '<luacall>' + else + -- source short_src linedefined what name namewhat nups func + local name = n.name or n.namewhat or n.what + if not name or name == "" then name = "?" end + return string.format("%s : %s : %s", n.short_src or "unknown source", n.linedefined or "--", name) + end + else + return "unknown" + end + end + + function debugger.showstats(printer,threshold) + printer = printer or texio.write or print + threshold = threshold or 0 + local total, grandtotal, functions = 0, 0, 0 + printer("\n") -- ugly but ok + for func, count in pairs(counters) do + if count > threshold then + local name = getname(func) + if name ~= "(for generator)" then + printer(string.format("%8i %s\n", count, getname(func))) + total = total + count + end + end + grandtotal = grandtotal + count + functions = functions + 1 + end + printer(string.format("functions: %s, total: %s, grand total: %s, threshold: %s\n", functions, total, grandtotal, threshold)) + end + + function debugger.savestats(filename,threshold) + local f = io.open(filename,'w') + if f then + debugger.showstats(function(str) f:write(str) end,threshold) + f:close() + end + end + + function debugger.enable() + debug.sethook(hook,"c") + end + + function debugger.disable() + debug.sethook() + --~ counters[debug.getinfo(2,"f").func] = nil + end + + function debugger.tracing() + local n = tonumber(os.env['MTX.TRACE.CALLS']) or tonumber(os.env['MTX_TRACE_CALLS']) or 0 + if n > 0 then + function debugger.tracing() return true end ; return true + else + function debugger.tracing() return false end ; return false + end + end + +end + +--~ debugger.enable() + +--~ print(math.sin(1*.5)) +--~ print(math.sin(1*.5)) +--~ print(math.sin(1*.5)) +--~ print(math.sin(1*.5)) +--~ print(math.sin(1*.5)) + +--~ debugger.disable() + +--~ print("") +--~ debugger.showstats() +--~ print("") +--~ debugger.showstats(print,3) + |