diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/util-deb.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/util-deb.lua | 83 |
1 files changed, 22 insertions, 61 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/util-deb.lua b/Master/texmf-dist/tex/context/base/mkiv/util-deb.lua index 6932e8804d3..b8db0c58345 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/util-deb.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/util-deb.lua @@ -10,6 +10,9 @@ if not modules then modules = { } end modules ['util-deb'] = { -- bound to a variable, like node.new, node.copy etc (contrary to for instance -- node.has_attribute which is bound to a has_attribute local variable in mkiv) +local debug = require "debug" + +local getinfo, sethook = debug.getinfo, debug.sethook local type, next, tostring, tonumber = type, next, tostring, tonumber local format, find, sub, gsub = string.format, string.find, string.sub, string.gsub local insert, remove, sort = table.insert, table.remove, table.sort @@ -95,7 +98,7 @@ end setmetatableindex(names,function(t,name) local v = setmetatableindex(function(t,source) local v = setmetatableindex(function(t,line) - local v = { total = 0, count = 0, nesting = 0 } + local v = { total = 0, count = 0 } t[line] = v return v end) @@ -106,9 +109,6 @@ setmetatableindex(names,function(t,name) return v end) -local getinfo = nil -local sethook = nil - local function hook(where) local f = getinfo(2,"nSl") if f then @@ -128,24 +128,12 @@ local function hook(where) end local data = names[name][source][line] if where == "call" then - local nesting = data.nesting - if nesting == 0 then - data.count = data.count + 1 - insert(data,ticks()) - data.nesting = 1 - else - data.nesting = nesting + 1 - end + data.count = data.count + 1 + insert(data,ticks()) elseif where == "return" then - local nesting = data.nesting - if nesting == 1 then - local t = remove(data) - if t then - data.total = data.total + ticks() - t - end - data.nesting = 0 - else - data.nesting = nesting - 1 + local t = remove(data) + if t then + data.total = data.total + ticks() - t end end end @@ -240,27 +228,6 @@ function debugger.showstats(printer,threshold) -- table.save("luatex-profile.lua",names) end -local function getdebug() - if sethook and getinfo then - return - end - if not debug then - local okay - okay, debug = pcall(require,"debug") - end - if type(debug) ~= "table" then - return - end - getinfo = debug.getinfo - sethook = debug.sethook - if type(getinfo) ~= "function" then - getinfo = nil - end - if type(sethook) ~= "function" then - sethook = nil - end -end - function debugger.savestats(filename,threshold) local f = io.open(filename,'w') if f then @@ -270,8 +237,7 @@ function debugger.savestats(filename,threshold) end function debugger.enable() - getdebug() - if sethook and getinfo and nesting == 0 then + if nesting == 0 then running = true if initialize then initialize() @@ -293,7 +259,7 @@ function debugger.disable() if nesting > 0 then nesting = nesting - 1 end - if sethook and getinfo and nesting == 0 then + if nesting == 0 then sethook() end end @@ -316,25 +282,20 @@ end -- from the lua book: local function showtraceback(rep) -- from lua site / adapted - getdebug() - if getinfo then - local level = 2 -- we don't want this function to be reported - local reporter = rep or report - while true do - local info = getinfo(level, "Sl") - if not info then - break - elseif info.what == "C" then - reporter("%2i : %s",level-1,"C function") - else - reporter("%2i : %s : %s",level-1,info.short_src,info.currentline) - end - level = level + 1 + local level = 2 -- we don't want this function to be reported + local reporter = rep or report + while true do + local info = getinfo(level, "Sl") + if not info then + break + elseif info.what == "C" then + reporter("%2i : %s",level-1,"C function") + else + reporter("%2i : %s : %s",level-1,info.short_src,info.currentline) end + level = level + 1 end end debugger.showtraceback = showtraceback -- debug.showtraceback = showtraceback - --- showtraceback() |