diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/trac-tim.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/trac-tim.lua | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/Master/texmf-dist/tex/context/base/trac-tim.lua b/Master/texmf-dist/tex/context/base/trac-tim.lua index 82c03f4c7a2..a8725bb5c11 100644 --- a/Master/texmf-dist/tex/context/base/trac-tim.lua +++ b/Master/texmf-dist/tex/context/base/trac-tim.lua @@ -6,10 +6,14 @@ if not modules then modules = { } end modules ['trac-tim'] = { license = "see context related readme files" } -goodies = goodies or { } -goodies.progress = goodies.progress or { } +local format, gsub = string.format, string.gsub +local concat, sort = table.concat, table.sort +local next, tonumber = next, tonumber -local progress = goodies.progress +plugins = plugins or { } +plugins.progress = plugins.progress or { } + +local progress = plugins.progress progress = progress or { } @@ -26,7 +30,7 @@ local params = { "pdf_mem_ptr", "pdf_mem_size", "pdf_os_cntr", - "pool_ptr", +-- "pool_ptr", -- obsolete "str_ptr", } @@ -36,12 +40,8 @@ local last = os.clock() local data = { } function progress.save() - local f = io.open((name or progress.defaultfilename) .. ".lut","w") - if f then - f:write(table.serialize(data,true)) - f:close() - data = { } - end + io.savedata((name or progress.defaultfilename) .. ".lut",table.serialize(data,true)) + data = { } end function progress.store() @@ -50,7 +50,7 @@ function progress.store() elapsed_time = c - last, node_memory = nodes.usage(), } - for k, v in pairs(params) do + for k, v in next, params do if status[v] then t[v] = status[v] end end data[#data+1] = t @@ -61,32 +61,7 @@ end local processed = { } -function progress.bot(name,tag) - local d = progress.convert(name) - return d.bot[tag] or 0 -end -function progress.top(name,tag) - local d = progress.convert(name) - return d.top[tag] or 0 -end -function progress.pages(name,tag) - local d = progress.convert(name) - return d.pages or 0 -end -function progress.path(name,tag) - local d = progress.convert(name) - return d.paths[tag] or "origin" -end -function progress.nodes(name) - local d = progress.convert(name) - return d.names or { } -end -function progress.parameters(name) - local d = progress.convert(name) - return params -- shared -end - -function progress.convert(name) +local function convert(name) name = ((name ~= "") and name) or progress.defaultfilename if not processed[name] then local names, top, bot, pages, paths, keys = { }, { }, { }, 0, { }, { } @@ -97,21 +72,22 @@ function progress.convert(name) pages = #data if pages > 1 then local factor = 100 - for k,v in ipairs(data) do - for k,v in pairs(v.node_memory) do + for k=1,#data do + for k, v in next, data[k].node_memory do keys[k] = true end end - for k,v in ipairs(data) do - local m = v.node_memory - for k, _ in pairs(keys) do + for k=1,#data do + local m = data[k].node_memory + for k, v in next, keys do if not m[k] then m[k] = 0 end end end local function path(tag,subtag) local b, t, s = nil, nil, { } - for k,v in ipairs(data) do - local v = (subtag and v[tag][subtag]) or v[tag] + for k=1,#data do + local v = data[k][tag] + v = v and (subtag and v[subtag]) or v if v then v = tonumber(v) if b then @@ -127,30 +103,30 @@ function progress.convert(name) end end local tagname = subtag or tag - top[tagname] = (string.format("%.3f",t)):gsub("%.000$","") - bot[tagname] = (string.format("%.3f",b)):gsub("%.000$","") + top[tagname] = gsub(format("%.3f",t),"%.000$","") + bot[tagname] = gsub(format("%.3f",b),"%.000$","") local delta = t-b if delta == 0 then delta = 1 else delta = factor/delta end - for k, v in ipairs(s) do - s[k] = "(" .. k .. "," .. (v-b)*delta .. ")" + for k=1,#s do + s[k] = "(" .. k .. "," .. (s[k]-b)*delta .. ")" end - paths[tagname] = table.concat(s,"--") + paths[tagname] = concat(s,"--") end - for _, tag in pairs(params) do + for _, tag in next, params do path(tag) end - for tag, _ in pairs(keys) do + for tag, _ in next, keys do path("node_memory",tag) names[#names+1] = tag end pages = pages - 1 end end - table.sort(names) + sort(names) processed[name] = { names = names, top = top, @@ -161,3 +137,24 @@ function progress.convert(name) end return processed[name] end + +progress.convert = convert + +function progress.bot(name,tag) + return convert(name).bot[tag] or 0 +end +function progress.top(name,tag) + return convert(name).top[tag] or 0 +end +function progress.pages(name,tag) + return convert(name).pages or 0 +end +function progress.path(name,tag) + return convert(name).paths[tag] or "origin" +end +function progress.nodes(name) + return convert(name).names or { } +end +function progress.parameters(name) + return params -- shared +end |