From 6d96109217e1755fb2f83c8d6a52966aed7aec57 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 4 Jul 2023 18:25:11 +1000 Subject: [PATCH] misc accounting features --- build.sh | 2 +- lib/shutil.lua | 5 +++-- module/sched.lua | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 10eef3c..e06047c 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ $LUA build.lua module/init.lua target/init.lua echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)\" > target/version.lua cat target/version.lua target/init.lua > target/tinit.lua mv target/tinit.lua target/init.lua -cp -r service/ lib/ cfg/ target/ +cp -r service/ lib/ cfg/ exec/ target/ rm target/version.lua rm -r doc/ &>/dev/null $LUA finddesc.lua doc/ $(find lib/ module/ -type f|sort) diff --git a/lib/shutil.lua b/lib/shutil.lua index 1e185b4..5742dae 100644 --- a/lib/shutil.lua +++ b/lib/shutil.lua @@ -152,8 +152,9 @@ return setmetatable({}, {__index = function(t,k) if path then local fn, e = loadfile(path) if not fn then error(string.format("\n - %s",e)) end - return function() - local pid = os.spawn(fn,path) + return function(...) + local tA = {...} + local pid = os.spawn(function() return fn(table.unpack(tA)) end,path) local ret = {require("event").pull("process_finished",pid)} if not ret[3] then error(string.format("\n - %s",ret[4])) diff --git a/module/sched.lua b/module/sched.lua index c6f8955..bcdb9ec 100644 --- a/module/sched.lua +++ b/module/sched.lua @@ -12,6 +12,8 @@ function os.spawn(f,n) -- function string -- number -- creates a process from fu n=n, -- process name p=nPid, -- process PID P=cPid, -- parent PID + t=0, -- CPU time + T=0, -- total uptime e={} -- environment variables } if tTasks[cPid] then @@ -38,7 +40,7 @@ end function os.taskInfo(pid) -- number -- table -- returns info on process *pid* as a table with name and parent values pid = pid or os.pid() if not tTasks[pid] then return false end - return {name=tTasks[pid].n,parent=tTasks[pid].P} + return {name=tTasks[pid].n,parent=tTasks[pid].P,cputime=tTasks[pid].t,iotime=tTasks[pid].T} end function os.sched() -- the actual scheduler function os.sched = nil @@ -47,7 +49,9 @@ function os.sched() -- the actual scheduler function for k,v in pairs(tTasks) do if coroutine.status(v.c) ~= "dead" then cPid = k + local sT, sC = os.clock(), computer.uptime() coroutine.resume(v.c,table.unpack(tEv)) + v.t, v.T = v.t + os.clock() - sT, v.T + computer.uptime() - sC else tTasks[k] = nil end