Skip to content

Commit

Permalink
refactor(core): Move profiler to where both CLIs and also library mod…
Browse files Browse the repository at this point in the history
…e can use it
  • Loading branch information
alerque committed Apr 27, 2023
1 parent c07e7f6 commit c7d7253
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Expand Up @@ -27,6 +27,7 @@ globals = {
"pl",
"fluent",
"extendSilePath",
"executablePath",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
}
Expand Down
1 change: 1 addition & 0 deletions .luarc.json
Expand Up @@ -8,6 +8,7 @@
"pl",
"fluent",
"extendSilePath",
"executablePath",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
],
Expand Down
3 changes: 1 addition & 2 deletions core/pathsetup.lua.in
Expand Up @@ -69,5 +69,4 @@ else
end

_G.extendSilePath = extendPaths

return executable
_G.executablePath = executable
20 changes: 19 additions & 1 deletion core/sile.lua
Expand Up @@ -29,6 +29,9 @@ fluent = require("fluent")()
-- Includes for _this_ scope
local lfs = require("lfs")

-- Developer tooling profiler
local ProFi

SILE.utilities = require("core.utilities")
SU = SILE.utilities -- regrettable global alias

Expand Down Expand Up @@ -131,6 +134,14 @@ SILE.init = function ()
SILE.outputter = SILE.outputters.dummy()
end
SILE.pagebuilder = SILE.pagebuilders.base()
io.stdout:setvbuf("no")
if SU.debugging("profile") then
ProFi = require("ProFi")
ProFi:start()
end
if SILE.makeDeps then
SILE.makeDeps:add(_G.executablePath)
end
runEvals(SILE.input.evaluates, "evaluate")
end

Expand Down Expand Up @@ -316,7 +327,7 @@ function SILE.processFile (filename, format, options)
SILE.masterDir = SILE.masterFilename:match("(.-)[^%/]+$")
end
if SILE.masterDir and SILE.masterDir:len() >= 1 then
extendSilePath(SILE.masterDir)
_G.extendSilePath(SILE.masterDir)
end
filename = SILE.resolveFile(filename)
if not filename then
Expand Down Expand Up @@ -449,6 +460,13 @@ function SILE.finish ()
if not SILE.quiet then
io.stderr:write("\n")
end
if SU.debugging("profile") then
ProFi:stop()
ProFi:writeReport(SILE.masterFilename..'.profile.txt')
end
if SU.debugging("versions") then
SILE.shaper:debugVersions()
end
end

-- Internal libraries that run core SILE functions on load
Expand Down
32 changes: 4 additions & 28 deletions sile.in
Expand Up @@ -6,46 +6,31 @@ SHARED_LIB_EXT = "@SHARED_LIB_EXT@"

-- At this point at run time we may or may not have anything useful in package.path,
-- so require() isn't something we can rely on.
local status, executable = pcall(dofile, "@SILE_PATH@/core/pathsetup.lua")
local status = pcall(dofile, "@SILE_PATH@/core/pathsetup.lua")
if not status then
executable = dofile("./core/pathsetup.lua")
dofile("./core/pathsetup.lua")
end

-- On FreeBSD, Lua's debug module doesn't give us info above the top of the stack.
-- Since our detection is currently burried in a module it doesn't tell us the executable.
if executable ~= "=[C]" then
executable = debug.getinfo(1, "S").source
if _G.executablePath == "=[C]" then
_G.executablePath = debug.getinfo(1, "S").source
end

-- This global is set here and *also* in the core library, since this
-- effectively passes the same table they are interchangeable (for now).
SILE = require("core.sile")

io.stdout:setvbuf 'no'

SILE.cli:parseArguments()

if not os.getenv 'LUA_REPL_RLWRAP' and not SILE.quiet then
io.stderr:write(SILE.full_version .. '\n')
end

local ProFi
if SU.debugging("profile") then
ProFi = require("ProFi")
end

if SILE.makeDeps then
SILE.makeDeps:add(executable)
end

SILE.init()

if SILE.input.filename and SILE.input.filename:len() > 0 then

if SU.debugging("profile") then
ProFi:start()
end

-- Deprecated, notice given in core.cli when argument used
for _, path in ipairs(SILE.input.includes) do
if not SILE.quiet then
Expand Down Expand Up @@ -78,15 +63,6 @@ if SILE.input.filename and SILE.input.filename:len() > 0 then

SILE.finish()

if SU.debugging("profile") then
ProFi:stop()
ProFi:writeReport(SILE.masterFilename..'.profile.txt')
end

if SU.debugging("versions") then
SILE.shaper:debugVersions()
end

else
SILE.repl:enter()
end
Expand Down

0 comments on commit c7d7253

Please sign in to comment.