summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/trac-inf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/trac-inf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/trac-inf.lua127
1 files changed, 82 insertions, 45 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/trac-inf.lua b/Master/texmf-dist/tex/context/base/mkiv/trac-inf.lua
index a7823c251b5..40dfe854e15 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/trac-inf.lua
+++ b/Master/texmf-dist/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,48 +39,58 @@ 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
local seconds = function(n) return n or 0 end
--- if FFISUPPORTED and ffi and os.type == "windows" then
---
--- local okay, kernel = pcall(ffi.load,"kernel32")
---
--- if kernel then
---
--- local tonumber = ffi.number or tonumber
---
--- ffi.cdef[[
--- int QueryPerformanceFrequency(int64_t *lpFrequency);
--- int QueryPerformanceCounter(int64_t *lpPerformanceCount);
--- ]]
---
--- local target = ffi.new("__int64[1]")
---
--- ticks = function()
--- if kernel.QueryPerformanceCounter(target) == 1 then
--- return tonumber(target[0])
--- else
--- return 0
--- end
--- end
---
--- local target = ffi.new("__int64[1]")
---
--- seconds = function(ticks)
--- if kernel.QueryPerformanceFrequency(target) == 1 then
--- return ticks / tonumber(target[0])
--- else
--- return 0
--- end
--- end
---
--- end
---
--- end
+if lua.getpreciseticks then
+
+ ticks = lua.getpreciseticks
+ seconds = lua.getpreciseseconds
+
+elseif FFISUPPORTED and ffi and os.type == "windows" then
+
+ local okay, kernel = pcall(ffi.load,"kernel32")
+
+ if kernel then
+
+ local tonumber = ffi.number or tonumber
+
+ ffi.cdef[[
+ int QueryPerformanceFrequency(int64_t *lpFrequency);
+ int QueryPerformanceCounter(int64_t *lpPerformanceCount);
+ ]]
+
+ local target = ffi.new("__int64[1]")
+
+ ticks = function()
+ if kernel.QueryPerformanceCounter(target) == 1 then
+ return tonumber(target[0])
+ else
+ return 0
+ end
+ end
+
+ local target = ffi.new("__int64[1]")
+
+ seconds = function(ticks)
+ if kernel.QueryPerformanceFrequency(target) == 1 then
+ return ticks / tonumber(target[0])
+ else
+ return 0
+ end
+ end
+
+ end
+
+else
+
+ -- excessive timing costs some 1-2 percent runtime
+
+end
+
local function starttiming(instance,reset)
local timer = timers[instance or "notimer"]
@@ -118,12 +128,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 +163,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 +193,7 @@ statistics.elapsed = elapsed
statistics.elapsedtime = elapsedtime
statistics.elapsedindeed = elapsedindeed
statistics.elapsedseconds = elapsedseconds
+statistics.benchmarktimer = benchmarktimer
-- general function .. we might split this module
@@ -193,10 +219,17 @@ function statistics.show()
-- register("luatex banner", function()
-- return lower(status.banner)
-- end)
- register("used engine", function()
- return format("%s version %s with functionality level %s, banner: %s",
- LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, lower(status.banner))
- end)
+ if LUATEXENGINE == "luametatex" then
+ register("used engine", function()
+ return format("%s version %s, functionality level %s, format id %s",
+ LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, LUATEXFORMATID)
+ end)
+ else
+ register("used engine", function()
+ return format("%s version %s with functionality level %s, banner: %s",
+ LUATEXENGINE, LUATEXVERSION, LUATEXFUNCTIONALITY, lower(status.banner))
+ end)
+ end
register("control sequences", function()
return format("%s of %s + %s", status.cs_count, status.hash_size,status.hash_extra)
end)
@@ -239,7 +272,11 @@ 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))
+ return format("%s MB, ctx: %s MB, max: %s MB)",
+ round(collectgarbage("count")/1000),
+ round(status.luastate_bytes/1000000),
+ status.luastate_bytes_max and round(status.luastate_bytes_max/1000000) or "unknown"
+ )
end
starttiming(statistics)