Performance debugging command is now a lot more useful and clientsided

This commit is contained in:
Logan G 2022-03-25 23:46:47 -06:00
parent 8f4f63bfaa
commit 696ade6b3e
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 105 additions and 15 deletions

View file

@ -56,14 +56,55 @@ net.receive("LSFT-Loaded", function()
dodir("lsft/modules/client")
dodir("lsft/modules/shared")
--[[
if player() == owner() then
--[[
net.start("LSFT-Get-Config")
net.writeString("LSFT-Get-Config-Resp-Test")
net.writeTable({"core","command_prefix"})
net.writeTable({"spectate","controls","forward"})
net.writeTable({})
net.send()
--]]
end
--]]
local maxCPU = 0
timer.create("CPUCheck", 0.5, 0, function()
if quotaAverage() > maxCPU then
maxCPU = quotaAverage()
end
if quotaAverage() > quotaMax() * 0.9 then
timer.pause("CPUCheck")
timer.pause("NetCheck")
timer.pause("RAMCheck")
timer.simple(10, function() timer.unpause("CPUCheck") timer.unpause("NetCheck") timer.unpause("RAMCheck") end)
end
end)
local minNet = 2^31
timer.create("NetCheck", 0.5, 0, function()
if net.getBytesLeft() < minNet then
minNet = net.getBytesLeft()
end
end)
local maxRAM = 0
timer.create("RAMCheck", 0.5, 0, function()
if ramUsed() > maxRAM then
maxRAM = ramUsed()
end
end)
net.receive("LSFT-StatsRequest", function(len, ply)
net.start("LSFT-StatsResponse")
net.writeFloat(maxCPU)
net.writeFloat(quotaMax())
net.writeFloat(maxRAM)
net.writeFloat(ramMax())
net.writeFloat(minNet)
net.send()
end)
end)

View file

@ -28,13 +28,62 @@ core = {}
do
local function stats()
-- For debugging purposes mostly
core:log(log.TEXT, "---------------------------")
core:log(log.TEXT, "Server Stats:")
core:log(log.INFO, "Max CPU: ", core.colors.text, math.round(core.maxCPU*1000000).."us ("..math.round(core.maxCPU*100/quotaMax()).."%)")
core:log(log.INFO, "Max RAM: ", core.colors.text, math.round(core.maxRAM).."kB ("..math.round(core.maxRAM*100/ramMax()).."%)")
core:log(log.INFO, "Min Net: ", core.colors.text, core.minNet.." bytes")
core:log(log.TEXT, "---------------------------")
net.start("LSFT-StatsRequest")
net.send()
local peakClientCPUTime = 0
local peakClientCPUPercent = 0
local peakClientRAM = 0
local peakClientRAMPercent = 0
local minClientNet = 2^31
local plys = 0
local function displayStats()
core:log(log.TEXT, "---------------------------")
core:log(log.TEXT, "Server Stats:")
core:log(log.INFO, "Max CPU: ", core.colors.text, math.round(core.maxCPU*1000000).."us ("..math.round(core.maxCPU*100/quotaMax()).."%)")
core:log(log.INFO, "Max RAM: ", core.colors.text, math.round(core.maxRAM).."kB ("..math.round(core.maxRAM*100/ramMax()).."%)")
core:log(log.INFO, "Min Net: ", core.colors.text, core.minNet.." bytes")
core:log(log.TEXT, "Client Stats:")
core:log(log.INFO, "Max CPU: ", core.colors.text, math.round(peakClientCPUTime*1000000).."us")
core:log(log.INFO, "Max CPU %: ", core.colors.text, math.round(peakClientCPUPercent*100, 2).."%")
core:log(log.INFO, "Max RAM: ", core.colors.text, math.round(peakClientRAM).."kB")
core:log(log.INFO, "Max RAM %: ", core.colors.text, math.round(peakClientRAMPercent*100, 2).."%")
core:log(log.INFO, "Min Net: ", core.colors.text, minClientNet.." bytes")
core:log(log.TEXT, "---------------------------")
end
timer.create("displaystats", 5, 1, displayStats)
net.receive("LSFT-StatsResponse", function()
plys = plys + 1
local clientCPUTime = net.readFloat()
local clientCPUPercent = clientCPUTime/net.readFloat()
local clientRAM = net.readFloat()
local clientRAMPercent = clientRAM/net.readFloat()
local clientNet = net.readFloat()
-- Comparison
if clientCPUTime > peakClientCPUTime then peakClientCPUTime = clientCPUTime end
if clientCPUPercent > peakClientCPUPercent then peakClientCPUPercent = clientCPUPercent end
if clientRAM > peakClientRAM then peakClientRAM = clientRAM end
if clientRAMPercent > peakClientRAMPercent then peakClientRAMPercent = clientRAMPercent end
if clientNet < minClientNet then minClientNet = clientNet end
-- If we have gotten a response from everyone, fuck the timer
-- There is a function that tells us when players are ready to receive stuff, but idk where it is and I'm too lazy to make one
if plys == #find.allPlayers() then timer.remove("displaystats") displayStats() end
end)
core.log(log.INFO, "Collecting data, please wait.")
end
local function hud()
@ -342,15 +391,15 @@ net.receive("LSFT-Get-Config", function()
end)
timer.create("CPUCheck", 1, 0, function()
timer.create("CPUCheck", 0.5, 0, function()
if quotaAverage() > core.maxCPU then
core.maxCPU = quotaAverage()
end
if quotaAverage() > quotaMax() * 0.5 then
core:log(log.WARNING, "CPU quota is low! ("..math.round(100-(quotaAverage()*100/quotaMax())).."% remaining)")
core:log(log.WARNING, "CPU usage is high! ("..math.round(quotaAverage()*100/quotaMax()).."% remaining)")
elseif quotaAverage() > quotaMax() * 0.9 then
core:log(log.ERROR, "CPU quota is critically low! ("..math.round(100-(quotaAverage()*100/quotaMax())).."% remaining)")
core:log(log.ERROR, "CPU usage is critically high! ("..math.round(quotaAverage()*100/quotaMax()).."% remaining)")
timer.pause("CPUCheck")
timer.pause("NetCheck")
timer.pause("RAMCheck")
@ -358,7 +407,7 @@ timer.create("CPUCheck", 1, 0, function()
end
end)
timer.create("NetCheck", 1, 0, function()
timer.create("NetCheck", 0.5, 0, function()
if net.getBytesLeft() < core.minNet then
core.minNet = net.getBytesLeft()
end
@ -370,7 +419,7 @@ timer.create("NetCheck", 1, 0, function()
end
end)
timer.create("RAMCheck", 1, 0, function()
timer.create("RAMCheck", 0.5, 0, function()
if ramUsed() > core.maxRAM then
core.maxRAM = ramUsed()
end