summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-context.lua21
-rw-r--r--scripts/context/lua/mtx-profile.lua35
-rw-r--r--scripts/context/lua/mtxrun.lua62
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua62
-rw-r--r--scripts/context/stubs/unix/mtxrun62
5 files changed, 164 insertions, 78 deletions
diff --git a/scripts/context/lua/mtx-context.lua b/scripts/context/lua/mtx-context.lua
index f33363a0d..698a6f142 100644
--- a/scripts/context/lua/mtx-context.lua
+++ b/scripts/context/lua/mtx-context.lua
@@ -518,6 +518,7 @@ function scripts.context.run(ctxdata,filename)
local a_purgeresult = getargument("purgeresult")
local a_global = getargument("global")
local a_timing = getargument("timing")
+ local a_profile = getargument("profile")
local a_batchmode = getargument("batchmode")
local a_nonstopmode = getargument("nonstopmode")
local a_once = getargument("once")
@@ -626,6 +627,22 @@ function scripts.context.run(ctxdata,filename)
report("warning: synctex is enabled") -- can add upto 5% runtime
end
--
+ if not a_timing then
+ -- okay
+ elseif c_flags.usemodule then
+ c_flags.usemodule = format("timing,%s",c_flags.usemodule)
+ else
+ c_flags.usemodule = "timing"
+ end
+ --
+ if not a_profile then
+ -- okay
+ elseif c_flags.directives then
+ c_flags.directives = format("system.profile,%s",c_flags.directives)
+ else
+ c_flags.directives = "system.profile"
+ end
+ --
-- kindofrun: 1:first run, 2:successive run, 3:once, 4:last of maxruns
--
for currentrun=1,maxnofruns do
@@ -1371,10 +1388,6 @@ elseif getargument("runs") then
multipass_nofruns = tonumber(getargument("runs")) or nil
end
-if getargument("profile") then
- os.setenv("MTX_PROFILE_RUN","YES")
-end
-
if getargument("run") then
scripts.context.timed(scripts.context.autoctx)
elseif getargument("make") then
diff --git a/scripts/context/lua/mtx-profile.lua b/scripts/context/lua/mtx-profile.lua
index 74e1d1538..35cf1fc47 100644
--- a/scripts/context/lua/mtx-profile.lua
+++ b/scripts/context/lua/mtx-profile.lua
@@ -41,33 +41,28 @@ function scripts.profiler.analyze(filename)
if f then
local times, counts, calls = { }, { }, { }
local totalruntime, totalcount, totalcalls = 0, 0, 0
- while true do
- local line = f:read()
- if line then
- local stacklevel, filename, functionname, linenumber, currentline, localtime, totaltime = line:match("^(%d+)\t(.-)\t(.-)\t(.-)\t(.-)\t(.-)\t(.-)")
- if not filename then
- -- next
- elseif filename == "=[C]" then
- if not functionname:find("^%(") then
- calls[functionname] = (calls[functionname] or 0) + 1
- end
- else
- local filename = filename:match("^@(.*)$")
- if filename then
- local fi = times[filename]
- if not fi then fi = { } times[filename] = fi end
- fi[functionname] = (fi[functionname] or 0) + tonumber(localtime)
- counts[functionname] = (counts[functionname] or 0) + 1
- end
+ for line in f:lines() do
+ local stacklevel, filename, functionname, linenumber, currentline, localtime, totaltime = line:match("^(%d+)\t(.-)\t(.-)\t(.-)\t(.-)\t(.-)\t(.-)")
+ if not filename then
+ -- next
+ elseif filename == "=[C]" then
+ if not functionname:find("^%(") then
+ calls[functionname] = (calls[functionname] or 0) + 1
end
else
- break
+ local filename = filename:match("^@(.*)$")
+ if filename then
+ local fi = times[filename]
+ if not fi then fi = { } times[filename] = fi end
+ fi[functionname] = (fi[functionname] or 0) + tonumber(localtime)
+ counts[functionname] = (counts[functionname] or 0) + 1
+ end
end
end
f:close()
print("")
local loaded = { }
- sortedtable.sortedkeys(times)
+ local sorted = table.sortedkeys(times)
for i=1,#sorted do
local filename = sorted[i]
local functions = times[filename]
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 403f2ba63..0d977b57e 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -1318,8 +1318,10 @@ patterns.digit = digit
patterns.sign = sign
patterns.cardinal = sign^0 * digit^1
patterns.integer = sign^0 * digit^1
-patterns.float = sign^0 * digit^0 * P('.') * digit^1
-patterns.cfloat = sign^0 * digit^0 * P(',') * digit^1
+patterns.unsigned = digit^0 * P('.') * digit^1
+patterns.float = sign^0 * patterns.unsigned
+patterns.cunsigned = digit^0 * P(',') * digit^1
+patterns.cfloat = sign^0 * patterns.cunsigned
patterns.number = patterns.float + patterns.integer
patterns.cnumber = patterns.cfloat + patterns.integer
patterns.oct = P("0") * R("07")^1
@@ -2345,6 +2347,24 @@ end
if not io.i_limiter then function io.i_limiter() end end -- dummy so we can test safely
if not io.o_limiter then function io.o_limiter() end end -- dummy so we can test safely
+-- This works quite ok:
+--
+-- function io.piped(command,writer)
+-- local pipe = io.popen(command)
+-- -- for line in pipe:lines() do
+-- -- print(line)
+-- -- end
+-- while true do
+-- local line = pipe:read(1)
+-- if not line then
+-- break
+-- elseif line ~= "\n" then
+-- writer(line)
+-- end
+-- end
+-- return pipe:close() -- ok, status, (error)code
+-- end
+
end -- of closure
@@ -4780,6 +4800,7 @@ local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
local type, next, rawset, tonumber, loadstring = type, next, rawset, tonumber, loadstring
local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
+local serialize = table.serialize
-- function tables.definetable(target) -- defines undefined tables
-- local composed, t, n = nil, { }, 0
@@ -4958,7 +4979,7 @@ function tables.encapsulate(core,capsule,protect)
end
end
-local function serialize(t,r,outer) -- no mixes
+local function fastserialize(t,r,outer) -- no mixes
r[#r+1] = "{"
local n = #t
if n > 0 then
@@ -4970,7 +4991,7 @@ local function serialize(t,r,outer) -- no mixes
elseif tv == "number" then
r[#r+1] = format("%s,",v)
elseif tv == "table" then
- serialize(v,r)
+ fastserialize(v,r)
elseif tv == "boolean" then
r[#r+1] = format("%s,",tostring(v))
end
@@ -4984,7 +5005,7 @@ local function serialize(t,r,outer) -- no mixes
r[#r+1] = format("[%q]=%s,",k,v)
elseif tv == "table" then
r[#r+1] = format("[%q]=",k)
- serialize(v,r)
+ fastserialize(v,r)
elseif tv == "boolean" then
r[#r+1] = format("[%q]=%s,",k,tostring(v))
end
@@ -4999,7 +5020,7 @@ local function serialize(t,r,outer) -- no mixes
end
function table.fastserialize(t,prefix) -- so prefix should contain the =
- return concat(serialize(t,{ prefix or "return" },true))
+ return concat(fastserialize(t,{ prefix or "return" },true))
end
function table.deserialize(str)
@@ -5034,6 +5055,10 @@ function table.load(filename)
end
end
+function table.save(filename,t,n,...)
+ io.savedata(filename,serialize(t,n == nil and true or n,...))
+end
+
local function slowdrop(t)
local r = { }
local l = { }
@@ -6338,10 +6363,16 @@ 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
@@ -6352,14 +6383,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
@@ -12152,9 +12176,11 @@ resolvers.settrace(osgetenv("MTX_INPUT_TRACE"))
-- todo:
--- if profiler and osgetenv("MTX_PROFILE_RUN") == "YES" then
--- profiler.start("luatex-profile.log")
--- end
+if profiler then
+ directives.register("system.profile",function()
+ profiler.start("luatex-profile.log")
+ end)
+end
-- a forward definition
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 403f2ba63..0d977b57e 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -1318,8 +1318,10 @@ patterns.digit = digit
patterns.sign = sign
patterns.cardinal = sign^0 * digit^1
patterns.integer = sign^0 * digit^1
-patterns.float = sign^0 * digit^0 * P('.') * digit^1
-patterns.cfloat = sign^0 * digit^0 * P(',') * digit^1
+patterns.unsigned = digit^0 * P('.') * digit^1
+patterns.float = sign^0 * patterns.unsigned
+patterns.cunsigned = digit^0 * P(',') * digit^1
+patterns.cfloat = sign^0 * patterns.cunsigned
patterns.number = patterns.float + patterns.integer
patterns.cnumber = patterns.cfloat + patterns.integer
patterns.oct = P("0") * R("07")^1
@@ -2345,6 +2347,24 @@ end
if not io.i_limiter then function io.i_limiter() end end -- dummy so we can test safely
if not io.o_limiter then function io.o_limiter() end end -- dummy so we can test safely
+-- This works quite ok:
+--
+-- function io.piped(command,writer)
+-- local pipe = io.popen(command)
+-- -- for line in pipe:lines() do
+-- -- print(line)
+-- -- end
+-- while true do
+-- local line = pipe:read(1)
+-- if not line then
+-- break
+-- elseif line ~= "\n" then
+-- writer(line)
+-- end
+-- end
+-- return pipe:close() -- ok, status, (error)code
+-- end
+
end -- of closure
@@ -4780,6 +4800,7 @@ local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
local type, next, rawset, tonumber, loadstring = type, next, rawset, tonumber, loadstring
local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
+local serialize = table.serialize
-- function tables.definetable(target) -- defines undefined tables
-- local composed, t, n = nil, { }, 0
@@ -4958,7 +4979,7 @@ function tables.encapsulate(core,capsule,protect)
end
end
-local function serialize(t,r,outer) -- no mixes
+local function fastserialize(t,r,outer) -- no mixes
r[#r+1] = "{"
local n = #t
if n > 0 then
@@ -4970,7 +4991,7 @@ local function serialize(t,r,outer) -- no mixes
elseif tv == "number" then
r[#r+1] = format("%s,",v)
elseif tv == "table" then
- serialize(v,r)
+ fastserialize(v,r)
elseif tv == "boolean" then
r[#r+1] = format("%s,",tostring(v))
end
@@ -4984,7 +5005,7 @@ local function serialize(t,r,outer) -- no mixes
r[#r+1] = format("[%q]=%s,",k,v)
elseif tv == "table" then
r[#r+1] = format("[%q]=",k)
- serialize(v,r)
+ fastserialize(v,r)
elseif tv == "boolean" then
r[#r+1] = format("[%q]=%s,",k,tostring(v))
end
@@ -4999,7 +5020,7 @@ local function serialize(t,r,outer) -- no mixes
end
function table.fastserialize(t,prefix) -- so prefix should contain the =
- return concat(serialize(t,{ prefix or "return" },true))
+ return concat(fastserialize(t,{ prefix or "return" },true))
end
function table.deserialize(str)
@@ -5034,6 +5055,10 @@ function table.load(filename)
end
end
+function table.save(filename,t,n,...)
+ io.savedata(filename,serialize(t,n == nil and true or n,...))
+end
+
local function slowdrop(t)
local r = { }
local l = { }
@@ -6338,10 +6363,16 @@ 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
@@ -6352,14 +6383,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
@@ -12152,9 +12176,11 @@ resolvers.settrace(osgetenv("MTX_INPUT_TRACE"))
-- todo:
--- if profiler and osgetenv("MTX_PROFILE_RUN") == "YES" then
--- profiler.start("luatex-profile.log")
--- end
+if profiler then
+ directives.register("system.profile",function()
+ profiler.start("luatex-profile.log")
+ end)
+end
-- a forward definition
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 403f2ba63..0d977b57e 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -1318,8 +1318,10 @@ patterns.digit = digit
patterns.sign = sign
patterns.cardinal = sign^0 * digit^1
patterns.integer = sign^0 * digit^1
-patterns.float = sign^0 * digit^0 * P('.') * digit^1
-patterns.cfloat = sign^0 * digit^0 * P(',') * digit^1
+patterns.unsigned = digit^0 * P('.') * digit^1
+patterns.float = sign^0 * patterns.unsigned
+patterns.cunsigned = digit^0 * P(',') * digit^1
+patterns.cfloat = sign^0 * patterns.cunsigned
patterns.number = patterns.float + patterns.integer
patterns.cnumber = patterns.cfloat + patterns.integer
patterns.oct = P("0") * R("07")^1
@@ -2345,6 +2347,24 @@ end
if not io.i_limiter then function io.i_limiter() end end -- dummy so we can test safely
if not io.o_limiter then function io.o_limiter() end end -- dummy so we can test safely
+-- This works quite ok:
+--
+-- function io.piped(command,writer)
+-- local pipe = io.popen(command)
+-- -- for line in pipe:lines() do
+-- -- print(line)
+-- -- end
+-- while true do
+-- local line = pipe:read(1)
+-- if not line then
+-- break
+-- elseif line ~= "\n" then
+-- writer(line)
+-- end
+-- end
+-- return pipe:close() -- ok, status, (error)code
+-- end
+
end -- of closure
@@ -4780,6 +4800,7 @@ local concat, insert, remove = table.concat, table.insert, table.remove
local setmetatable, getmetatable, tonumber, tostring = setmetatable, getmetatable, tonumber, tostring
local type, next, rawset, tonumber, loadstring = type, next, rawset, tonumber, loadstring
local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs
+local serialize = table.serialize
-- function tables.definetable(target) -- defines undefined tables
-- local composed, t, n = nil, { }, 0
@@ -4958,7 +4979,7 @@ function tables.encapsulate(core,capsule,protect)
end
end
-local function serialize(t,r,outer) -- no mixes
+local function fastserialize(t,r,outer) -- no mixes
r[#r+1] = "{"
local n = #t
if n > 0 then
@@ -4970,7 +4991,7 @@ local function serialize(t,r,outer) -- no mixes
elseif tv == "number" then
r[#r+1] = format("%s,",v)
elseif tv == "table" then
- serialize(v,r)
+ fastserialize(v,r)
elseif tv == "boolean" then
r[#r+1] = format("%s,",tostring(v))
end
@@ -4984,7 +5005,7 @@ local function serialize(t,r,outer) -- no mixes
r[#r+1] = format("[%q]=%s,",k,v)
elseif tv == "table" then
r[#r+1] = format("[%q]=",k)
- serialize(v,r)
+ fastserialize(v,r)
elseif tv == "boolean" then
r[#r+1] = format("[%q]=%s,",k,tostring(v))
end
@@ -4999,7 +5020,7 @@ local function serialize(t,r,outer) -- no mixes
end
function table.fastserialize(t,prefix) -- so prefix should contain the =
- return concat(serialize(t,{ prefix or "return" },true))
+ return concat(fastserialize(t,{ prefix or "return" },true))
end
function table.deserialize(str)
@@ -5034,6 +5055,10 @@ function table.load(filename)
end
end
+function table.save(filename,t,n,...)
+ io.savedata(filename,serialize(t,n == nil and true or n,...))
+end
+
local function slowdrop(t)
local r = { }
local l = { }
@@ -6338,10 +6363,16 @@ 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
@@ -6352,14 +6383,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
@@ -12152,9 +12176,11 @@ resolvers.settrace(osgetenv("MTX_INPUT_TRACE"))
-- todo:
--- if profiler and osgetenv("MTX_PROFILE_RUN") == "YES" then
--- profiler.start("luatex-profile.log")
--- end
+if profiler then
+ directives.register("system.profile",function()
+ profiler.start("luatex-profile.log")
+ end)
+end
-- a forward definition