summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua98
1 files changed, 81 insertions, 17 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
index 12a4f646ff4..51893d585fe 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-trac-inf.lua
@@ -42,11 +42,51 @@ local function resettiming(instance)
timers[instance or "notimer"] = { timing = 0, loadtime = 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
+
local function starttiming(instance)
local timer = timers[instance or "notimer"]
- local it = timer.timing or 0
+ local it = timer.timing
if it == 0 then
- timer.starttime = clock()
+ timer.starttime = ticks()
if not timer.loadtime then
timer.loadtime = 0
end
@@ -62,7 +102,7 @@ local function stoptiming(instance)
else
local starttime = timer.starttime
if starttime and starttime > 0 then
- local stoptime = clock()
+ local stoptime = ticks()
local loadtime = stoptime - starttime
timer.stoptime = stoptime
timer.loadtime = timer.loadtime + loadtime
@@ -76,10 +116,28 @@ end
local function elapsed(instance)
if type(instance) == "number" then
- return instance or 0
+ return instance
+ else
+ local timer = timers[instance or "notimer"]
+ return timer and seconds(timer.loadtime) or 0
+ end
+end
+
+local function currenttime(instance)
+ if type(instance) == "number" then
+ return instance
else
local timer = timers[instance or "notimer"]
- return timer and timer.loadtime or 0
+ local it = timer.timing
+ if it > 1 then
+ -- whatever
+ else
+ local starttime = timer.starttime
+ if starttime and starttime > 0 then
+ return seconds(timer.loadtime + ticks() - starttime)
+ end
+ end
+ return 0
end
end
@@ -101,6 +159,7 @@ statistics.hastiming = hastiming
statistics.resettiming = resettiming
statistics.starttiming = starttiming
statistics.stoptiming = stoptiming
+statistics.currenttime = currenttime
statistics.elapsed = elapsed
statistics.elapsedtime = elapsedtime
statistics.elapsedindeed = elapsedindeed
@@ -127,20 +186,24 @@ function statistics.show()
return format("%s, type: %s, binary subtree: %s",
os.platform or "unknown",os.type or "unknown", environment.texos or "unknown")
end)
- register("luatex banner", function()
- return lower(status.banner)
+ -- 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)
register("control sequences", function()
return format("%s of %s + %s", status.cs_count, status.hash_size,status.hash_extra)
end)
- register("callbacks", function()
- 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)
- if jit then
- local jitstatus = { jit.status() }
- if jitstatus[1] then
- register("luajit options", concat(jitstatus," ",2))
+ register("callbacks", statistics.callbacks)
+ if TEXENGINE == "luajittex" and JITSUPPORTED then
+ local jitstatus = jit.status
+ if jitstatus then
+ local jitstatus = { jitstatus() }
+ if jitstatus[1] then
+ register("luajit options", concat(jitstatus," ",2))
+ end
end
end
-- so far
@@ -149,8 +212,9 @@ function statistics.show()
local hashchar = tonumber(status.luatex_hashchars)
local hashtype = status.luatex_hashtype
local mask = lua.mask or "ascii"
- return format("engine: %s, used memory: %s, hash type: %s, hash chars: min(%s,40), symbol mask: %s (%s)",
+ return format("engine: %s %s, used memory: %s, hash type: %s, hash chars: min(%i,40), symbol mask: %s (%s)",
jit and "luajit" or "lua",
+ LUAVERSION,
statistics.memused(),
hashtype or "default",
hashchar and 2^hashchar or "unknown",
@@ -184,7 +248,7 @@ end
function statistics.runtime()
stoptiming(statistics)
- -- stoptiming(statistics) -- somehow we can start the timer twice, but where
+ -- stoptiming(statistics) -- somehow we can start the timer twice, but where
return statistics.formatruntime(elapsedtime(statistics))
end