summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/trac-inf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/trac-inf.lua')
-rw-r--r--tex/context/base/mkiv/trac-inf.lua24
1 files changed, 20 insertions, 4 deletions
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