summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/trac-inf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/trac-inf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/trac-inf.lua86
1 files changed, 44 insertions, 42 deletions
diff --git a/Master/texmf-dist/tex/context/base/trac-inf.lua b/Master/texmf-dist/tex/context/base/trac-inf.lua
index cbc9d13f880..fdc07d97d39 100644
--- a/Master/texmf-dist/tex/context/base/trac-inf.lua
+++ b/Master/texmf-dist/tex/context/base/trac-inf.lua
@@ -11,18 +11,25 @@ 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
-local write_nl = texio.write_nl
statistics = statistics or { }
local statistics = statistics
statistics.enable = true
-statistics.threshold = 0.05
+statistics.threshold = 0.01
local statusinfo, n, registered, timers = { }, 0, { }, { }
+table.setmetatableindex(timers,function(t,k)
+ local v = { timing = 0, loadtime = 0 }
+ t[k] = v
+ return v
+end)
+
local function hastiming(instance)
return instance and timers[instance]
end
@@ -33,14 +40,7 @@ end
local function starttiming(instance)
local timer = timers[instance or "notimer"]
- if not timer then
- timer = { }
- timers[instance or "notimer"] = timer
- end
- local it = timer.timing
- if not it then
- it = 0
- end
+ local it = timer.timing or 0
if it == 0 then
timer.starttime = clock()
if not timer.loadtime then
@@ -72,19 +72,26 @@ local function stoptiming(instance, report)
return 0
end
+local function elapsed(instance)
+ if type(instance) == "number" then
+ return instance or 0
+ else
+ local timer = timers[instance or "notimer"]
+ return timer and timer.loadtime 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,11 +99,12 @@ statistics.hastiming = hastiming
statistics.resettiming = resettiming
statistics.starttiming = starttiming
statistics.stoptiming = stoptiming
+statistics.elapsed = elapsed
statistics.elapsedtime = elapsedtime
statistics.elapsedindeed = elapsedindeed
statistics.elapsedseconds = elapsedseconds
--- general function
+-- general function .. we might split this module
function statistics.register(tag,fnc)
if statistics.enable and type(fnc) == "function" then
@@ -107,9 +115,10 @@ function statistics.register(tag,fnc)
end
end
-function statistics.show(reporter)
+local report = logs.reporter("mkiv lua stats")
+
+function statistics.show()
if statistics.enable then
- if not reporter then reporter = function(tag,data,n) write_nl(tag .. " " .. data) end end
-- this code will move
local register = statistics.register
register("luatex banner", function()
@@ -122,39 +131,31 @@ function statistics.show(reporter)
local total, indirect = status.callbacks or 0, status.indirect_callbacks or 0
return format("%s direct, %s indirect, %s total", total-indirect, indirect, total)
end)
- collectgarbage("collect")
- register("current memory usage", statistics.memused)
+ if jit then
+ local status = { jit.status() }
+ if status[1] then
+ register("luajit status", function()
+ return concat(status," ",2)
+ end)
+ end
+ end
+ -- so far
+ -- collectgarbage("collect")
+ register("current memory usage",statistics.memused)
register("runtime",statistics.runtime)
+ logs.newline() -- initial newline
for i=1,#statusinfo do
local s = statusinfo[i]
local r = s[2]()
if r then
- reporter(s[1],r,n)
+ report("%s: %s",s[1],r)
end
end
- write_nl("") -- final newline
+ -- logs.newline() -- final newline
statistics.enable = false
end
end
-local template, report_statistics, nn = nil, nil, 0 -- we only calcute it once
-
-function statistics.showjobstat(tag,data,n)
- if not logs then
- -- sorry
- elseif type(data) == "table" then
- for i=1,#data do
- statistics.showjobstat(tag,data[i],n)
- end
- else
- if not template or n > nn then
- template, n = format("%%-%ss - %%s",n), nn
- report_statistics = logs.reporter("mkiv lua stats")
- end
- report_statistics(format(template,tag,data))
- end
-end
-
function statistics.memused() -- no math.round yet -)
local round = math.round or math.floor
return format("%s MB (ctx: %s MB)",round(collectgarbage("count")/1000), round(status.luastate_bytes/1000000))
@@ -171,8 +172,9 @@ function statistics.runtime()
return statistics.formatruntime(elapsedtime(statistics))
end
-function statistics.timed(action,report)
- report = report or logs.reporter("system")
+local report = logs.reporter("system")
+
+function statistics.timed(action)
starttiming("run")
action()
stoptiming("run")