summaryrefslogtreecommitdiff
path: root/tex/context/base/trac-inf.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-01-17 19:40:22 +0200
committerMarius <mariausol@gmail.com>2013-01-17 19:40:22 +0200
commit3346c745a354c0726c1ec68fb1f2d04e5bc85a9b (patch)
tree3f08d6fdf3111495759842f46bce62e159d4b9bf /tex/context/base/trac-inf.lua
parentfe55ae49d8deddeb8f02557e3902c847804b0086 (diff)
downloadcontext-3346c745a354c0726c1ec68fb1f2d04e5bc85a9b.tar.gz
beta 2013.01.17 18:16
Diffstat (limited to 'tex/context/base/trac-inf.lua')
-rw-r--r--tex/context/base/trac-inf.lua19
1 files changed, 14 insertions, 5 deletions
diff --git a/tex/context/base/trac-inf.lua b/tex/context/base/trac-inf.lua
index 5575639eb..826271169 100644
--- a/tex/context/base/trac-inf.lua
+++ b/tex/context/base/trac-inf.lua
@@ -11,6 +11,7 @@ if not modules then modules = { } end modules ['trac-inf'] = {
-- get warnings about assignments. This is more efficient than using rawset
-- and rawget.
+local type, tonumber = type, tonumber
local format, lower = string.format, string.lower
local concat = table.concat
local clock = os.gettimeofday or os.clock -- should go in environment
@@ -72,19 +73,26 @@ local function stoptiming(instance, report)
return 0
end
+local function elapsed(instance)
+ if type(instance) == "table" then
+ local timer = timers[instance or "notimer"]
+ return timer and timer.loadtime or 0
+ else
+ return tonumber(instance) or 0
+ end
+end
+
local function elapsedtime(instance)
- local timer = timers[instance or "notimer"]
- return format("%0.3f",timer and timer.loadtime or 0)
+ return format("%0.3f",elapsed(instance))
end
local function elapsedindeed(instance)
- local timer = timers[instance or "notimer"]
- return (timer and timer.loadtime or 0) > statistics.threshold
+ return elapsed(instance) > statistics.threshold
end
local function elapsedseconds(instance,rest) -- returns nil if 0 seconds
if elapsedindeed(instance) then
- return format("%s seconds %s", elapsedtime(instance),rest or "")
+ return format("%0.3f seconds %s", elapsed(instance),rest or "")
end
end
@@ -92,6 +100,7 @@ statistics.hastiming = hastiming
statistics.resettiming = resettiming
statistics.starttiming = starttiming
statistics.stoptiming = stoptiming
+statistics.elapsed = elapsed
statistics.elapsedtime = elapsedtime
statistics.elapsedindeed = elapsedindeed
statistics.elapsedseconds = elapsedseconds