From c49d2942bae7074f3bd4c04b6ee895cee1697ca3 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 29 Apr 2019 09:43:01 +0200 Subject: 2019-04-29 09:01:00 --- tex/context/base/mkiv/trac-inf.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'tex/context/base/mkiv/trac-inf.lua') diff --git a/tex/context/base/mkiv/trac-inf.lua b/tex/context/base/mkiv/trac-inf.lua index a7823c251..71c65a3f4 100644 --- a/tex/context/base/mkiv/trac-inf.lua +++ b/tex/context/base/mkiv/trac-inf.lua @@ -29,7 +29,7 @@ statistics.threshold = 0.01 local statusinfo, n, registered, timers = { }, 0, { }, { } setmetatableindex(timers,function(t,k) - local v = { timing = 0, loadtime = 0 } + local v = { timing = 0, loadtime = 0, offset = 0 } t[k] = v return v end) @@ -39,7 +39,7 @@ local function hastiming(instance) end local function resettiming(instance) - timers[instance or "notimer"] = { timing = 0, loadtime = 0 } + timers[instance or "notimer"] = { timing = 0, loadtime = 0, offset = 0 } end local ticks = clock @@ -118,12 +118,27 @@ local function stoptiming(instance) return 0 end +local function benchmarktimer(instance) + local timer = timers[instance or "notimer"] + local it = timer.timing + if it > 1 then + timer.timing = it - 1 + else + local starttime = timer.starttime + if starttime and starttime > 0 then + timer.offset = ticks() - starttime + else + timer.offset = 0 + end + end +end + local function elapsed(instance) if type(instance) == "number" then return instance else local timer = timers[instance or "notimer"] - return timer and seconds(timer.loadtime) or 0 + return timer and seconds(timer.loadtime - 2*(timer.offset or 0)) or 0 end end @@ -138,7 +153,7 @@ local function currenttime(instance) else local starttime = timer.starttime if starttime and starttime > 0 then - return seconds(timer.loadtime + ticks() - starttime) + return seconds(timer.loadtime + ticks() - starttime - 2*(timer.offset or 0)) end end return 0 @@ -168,6 +183,7 @@ statistics.elapsed = elapsed statistics.elapsedtime = elapsedtime statistics.elapsedindeed = elapsedindeed statistics.elapsedseconds = elapsedseconds +statistics.benchmarktimer = benchmarktimer -- general function .. we might split this module -- cgit v1.2.3