Implement profiler

This commit is contained in:
2026-06-20 14:21:26 +03:00
parent 45a09284c2
commit ab48b57e1b
10 changed files with 294 additions and 17 deletions
+5 -4
View File
@@ -11,6 +11,7 @@ gpu.bind(screenAddress)
gpu.setResolution(gpu.maxResolution())
local log = assert(loadfile("/lib/log.lua")(loadfile))
_G.profiler = assert(loadfile("/lib/profiler.lua")())
log.kernel.info("Bound GPU to screen " .. tostring(screenAddress))
@@ -67,10 +68,10 @@ require("/halyde/kernel/datatools.lua") -- If this is not imported BEFORE modloa
log.kernel.info("Loading modules")
require("/halyde/kernel/modload.lua")
package.preload("component")
package.preload("computer")
package.preload("log")
package.preload("event")
local toPreload = { "component", "computer", "log", "event" }
for _, p in pairs(toPreload) do
profiler.profile("pre-loading " .. p, package.preload, p)
end
local computer = require("computer")
function wait(seconds)
+8
View File
@@ -19,8 +19,10 @@ local moduleTypes = {}
local modulesLoaded = {}
local function loadModule(modName)
local stop = profiler.start("loadModule(" .. tostring(modName) .. ")")
if table.find(modulesLoaded, modName) then
log.kernel.warn(string.format("[modload: %s] Module was already loaded - skipping", modName))
stop()
return true
end
@@ -28,6 +30,7 @@ local function loadModule(modName)
if not moduleData then
log.kernel.warn(string.format("[modload: %s] Could not find module data.", modName))
table.remove(moduleList, table.find(moduleList, modName))
stop()
return true
end
local ready = false
@@ -42,6 +45,7 @@ local function loadModule(modName)
end
if not ready then
log.kernel.info(string.format("[modload: %s] Module not ready - skipping", modName))
stop()
return false
end
if type(moduleData.dependencies) == "table" then
@@ -74,16 +78,19 @@ local function loadModule(modName)
tostring(err or "unknown error")
)
)
stop()
return false
else
table.insert(modulesLoaded, modName)
table.remove(moduleList, table.find(moduleList, modName))
end
end
stop()
return true
end
for _, modName in pairs(moduleList) do -- Get all the module types
local stop = profiler.start("getting module " .. modName .. ")")
log.kernel.info(string.format("[modload: %s] Getting data from module", modName))
local moduleData
local status, err = pcall(function()
@@ -123,6 +130,7 @@ for _, modName in pairs(moduleList) do -- Get all the module types
moduleTypes[modName] = moduleData.type -- Not the other way around because there can be multiple modules of the same type, but there can't be multiple entries with the same key
end
::continue::
stop()
end
local function loadAllModules() -- attempt at loading all modules, unless if they're not ready
+1 -1
View File
@@ -1,6 +1,6 @@
local module = {}
module.dependencies = { "terminal" }
module.dependencies = { "io" }
function module.check()
return true -- This module should always be loaded
+3 -7
View File
@@ -17,9 +17,8 @@ function module.init()
local event = require("event")
local component = require("component")
local computer = require("computer")
local gpu = component.gpu
_G._PUBLIC.terminal = {}
_G._PUBLIC.io = {}
local readHistory = {}
function _PUBLIC.terminal.getHistory(id)
@@ -145,9 +144,6 @@ function module.init()
local ANSIColorPalette = getColorPalette(gpu.maxDepth())
local expecting_unicode_bytes = 0
local unicode_bytes_left = 0
local unicode_codepoint = 0
local cursor = { x = 1, y = 1, X = nil, Y = nil } -- X and Y are managed by ESC s and ESC u
local printState = 0 -- 0:none 1:in ESC 2:in CSI
local color = {
@@ -566,7 +562,7 @@ function module.init()
local args = {...}
local stringArgs = {}
for _, arg in pairs(args) do
if type(arg)=="table" then
if type(arg) == "table" then
table.insert(stringArgs, serialize(arg))
elseif tostring(arg) then
table.insert(stringArgs, tostring(arg))
@@ -815,7 +811,7 @@ function module.init()
end
function module.exit()
_G._PUBLIC.terminal = nil
_G._PUBLIC.io = nil
end
return module