diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/luat-sto.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/luat-sto.lua | 114 |
1 files changed, 65 insertions, 49 deletions
diff --git a/Master/texmf-dist/tex/context/base/luat-sto.lua b/Master/texmf-dist/tex/context/base/luat-sto.lua index 30bb7d5bb9b..7a11b7f5e68 100644 --- a/Master/texmf-dist/tex/context/base/luat-sto.lua +++ b/Master/texmf-dist/tex/context/base/luat-sto.lua @@ -9,10 +9,12 @@ if not modules then modules = { } end modules ['luat-sto'] = { -- we could nil some function in the productionrun local type, next, setmetatable, getmetatable, collectgarbage = type, next, setmetatable, getmetatable, collectgarbage -local gmatch, format, write_nl = string.gmatch, string.format, texio.write_nl +local gmatch, format = string.gmatch, string.format local serialize, concat, sortedhash = table.serialize, table.concat, table.sortedhash local bytecode = lua.bytecode +local strippedloadstring = utilities.lua.strippedloadstring +local trace_storage = false local report_storage = logs.reporter("system","storage") storage = storage or { } @@ -21,9 +23,6 @@ local storage = storage local data = { } storage.data = data -local evaluators = { } -storage.evaluators = evaluators - storage.min = 0 -- 500 storage.max = storage.min - 1 storage.noftables = storage.noftables or 0 @@ -32,6 +31,9 @@ storage.nofmodules = storage.nofmodules or 0 storage.mark = utilities.storage.mark storage.allocate = utilities.storage.allocate storage.marked = utilities.storage.marked +storage.strip = false + +directives.register("system.compile.strip", function(v) storage.strip = v end) function storage.register(...) local t = { ... } @@ -39,19 +41,21 @@ function storage.register(...) if d then storage.mark(d) else - report_storage("fatal error: invalid storage '%s'",t[1]) + report_storage("fatal error: invalid storage %a",t[1]) os.exit() end data[#data+1] = t return t end +local n = 0 local function dump() local max = storage.max for i=1,#data do local d = data[i] local message, original, target = d[1], d[2] ,d[3] local c, code, name = 0, { }, nil + -- we have a nice definer for this for str in gmatch(target,"([^%.]+)") do if name then name = name .. "." .. str @@ -62,11 +66,14 @@ local function dump() end max = max + 1 if trace_storage then - report_storage('saving %s in slot %s',message,max) - c = c + 1 ; code[c] = format("report_storage('restoring %s from slot %s')",message,max) + c = c + 1 ; code[c] = format("print('restoring %s from slot %s')",message,max) end c = c + 1 ; code[c] = serialize(original,name) - bytecode[max] = loadstring(concat(code,"\n")) + if trace_storage then + report_storage('saving %a in slot %a, size %s',message,max,#code[c]) + end + -- we don't need tracing in such tables + bytecode[max] = strippedloadstring(concat(code,"\n"),storage.strip,format("slot %s (%s)",max,name)) collectgarbage("step") end storage.max = max @@ -90,58 +97,67 @@ function lua.collectgarbage(threshold) end end --- we also need to count at generation time (nicer for message) - ---~ if lua.bytecode then -- from 0 upwards ---~ local i, b = storage.min, lua.bytecode ---~ while b[i] do ---~ storage.noftables = i ---~ b[i]() ---~ b[i] = nil ---~ i = i + 1 ---~ end ---~ end +-- -- we also need to count at generation time (nicer for message) +-- +-- if lua.bytecode then -- from 0 upwards +-- local i, b = storage.min, lua.bytecode +-- while b[i] do +-- storage.noftables = i +-- b[i]() +-- b[i] = nil +-- i = i + 1 +-- end +-- end statistics.register("stored bytecode data", function() - local modules = (storage.nofmodules > 0 and storage.nofmodules) or (status.luabytecodes - lua.firstbytecode - 1) - local dumps = (storage.noftables > 0 and storage.noftables) or storage.max-storage.min + 1 - return format("%s modules, %s tables, %s chunks",modules,dumps,modules+dumps) + local nofmodules = (storage.nofmodules > 0 and storage.nofmodules) or (status.luabytecodes - lua.firstbytecode - 1) + local nofdumps = (storage.noftables > 0 and storage.noftables ) or storage.max-storage.min + 1 + local tofmodules = storage.tofmodules or 0 + local tofdumps = storage.toftables or 0 + if environment.initex then + local luautilities = utilities.lua + local nofstrippedbytes = luautilities.nofstrippedbytes + local nofstrippedchunks = luautilities.nofstrippedchunks + if nofstrippedbytes > 0 then + return format("%s modules, %s tables, %s chunks, %s chunks stripped (%s bytes)", + nofmodules, + nofdumps, + nofmodules + nofdumps, + nofstrippedchunks, + nofstrippedbytes + ) + elseif nofstrippedchunks > 0 then + return format("%s modules, %s tables, %s chunks, %s chunks stripped", + nofmodules, + nofdumps, + nofmodules + nofdumps, + nofstrippedchunks + ) + else + return format("%s modules, %s tables, %s chunks", + nofmodules, + nofdumps, + nofmodules + nofdumps + ) + end + else + return format("%s modules (%0.3f sec), %s tables (%0.3f sec), %s chunks (%0.3f sec)", + nofmodules, tofmodules, + nofdumps, tofdumps, + nofmodules + nofdumps, tofmodules + tofdumps + ) + end end) if lua.bytedata then storage.register("lua/bytedata",lua.bytedata,"lua.bytedata") end -function statistics.reportstorage(whereto) - whereto = whereto or "term and log" - write_nl(whereto," ","stored tables:"," ") - for k,v in sortedhash(storage.data) do - write_nl(whereto,format("%03i %s",k,v[1])) - end - write_nl(whereto," ","stored modules:"," ") - for k,v in sortedhash(lua.bytedata) do - write_nl(whereto,format("%03i %s %s",k,v[2],v[1])) - end - write_nl(whereto," ","stored attributes:"," ") - for k,v in sortedhash(attributes.names) do - write_nl(whereto,format("%03i %s",k,v)) - end - write_nl(whereto," ","stored catcodetables:"," ") - for k,v in sortedhash(catcodes.names) do - write_nl(whereto,format("%03i %s",k,concat(v," "))) - end - write_nl(whereto," ","used corenamespaces:"," ") - for k,v in sortedhash(interfaces.corenamespaces) do - write_nl(whereto,format("%03i %s",k,v)) - end - write_nl(whereto," ") -end - -storage.shared = storage.shared or { } - -- Because the storage mechanism assumes tables, we define a table for storing -- (non table) values. +storage.shared = storage.shared or { } + storage.register("storage/shared", storage.shared, "storage.shared") local mark = storage.mark |