Performance debugging command is now a lot more useful and clientsided
This commit is contained in:
parent
8f4f63bfaa
commit
696ade6b3e
2 changed files with 105 additions and 15 deletions
45
cl_lsft.txt
45
cl_lsft.txt
|
@ -56,14 +56,55 @@ net.receive("LSFT-Loaded", function()
|
||||||
dodir("lsft/modules/client")
|
dodir("lsft/modules/client")
|
||||||
dodir("lsft/modules/shared")
|
dodir("lsft/modules/shared")
|
||||||
|
|
||||||
--[[
|
|
||||||
if player() == owner() then
|
if player() == owner() then
|
||||||
|
--[[
|
||||||
net.start("LSFT-Get-Config")
|
net.start("LSFT-Get-Config")
|
||||||
net.writeString("LSFT-Get-Config-Resp-Test")
|
net.writeString("LSFT-Get-Config-Resp-Test")
|
||||||
net.writeTable({"core","command_prefix"})
|
net.writeTable({"core","command_prefix"})
|
||||||
net.writeTable({"spectate","controls","forward"})
|
net.writeTable({"spectate","controls","forward"})
|
||||||
net.writeTable({})
|
net.writeTable({})
|
||||||
net.send()
|
net.send()
|
||||||
|
--]]
|
||||||
end
|
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)
|
end)
|
73
sv_lsft.txt
73
sv_lsft.txt
|
@ -28,13 +28,62 @@ core = {}
|
||||||
|
|
||||||
do
|
do
|
||||||
local function stats()
|
local function stats()
|
||||||
-- For debugging purposes mostly
|
net.start("LSFT-StatsRequest")
|
||||||
core:log(log.TEXT, "---------------------------")
|
net.send()
|
||||||
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()).."%)")
|
local peakClientCPUTime = 0
|
||||||
core:log(log.INFO, "Max RAM: ", core.colors.text, math.round(core.maxRAM).."kB ("..math.round(core.maxRAM*100/ramMax()).."%)")
|
local peakClientCPUPercent = 0
|
||||||
core:log(log.INFO, "Min Net: ", core.colors.text, core.minNet.." bytes")
|
|
||||||
core:log(log.TEXT, "---------------------------")
|
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
|
end
|
||||||
|
|
||||||
local function hud()
|
local function hud()
|
||||||
|
@ -342,15 +391,15 @@ net.receive("LSFT-Get-Config", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
timer.create("CPUCheck", 1, 0, function()
|
timer.create("CPUCheck", 0.5, 0, function()
|
||||||
if quotaAverage() > core.maxCPU then
|
if quotaAverage() > core.maxCPU then
|
||||||
core.maxCPU = quotaAverage()
|
core.maxCPU = quotaAverage()
|
||||||
end
|
end
|
||||||
|
|
||||||
if quotaAverage() > quotaMax() * 0.5 then
|
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
|
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("CPUCheck")
|
||||||
timer.pause("NetCheck")
|
timer.pause("NetCheck")
|
||||||
timer.pause("RAMCheck")
|
timer.pause("RAMCheck")
|
||||||
|
@ -358,7 +407,7 @@ timer.create("CPUCheck", 1, 0, function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
timer.create("NetCheck", 1, 0, function()
|
timer.create("NetCheck", 0.5, 0, function()
|
||||||
if net.getBytesLeft() < core.minNet then
|
if net.getBytesLeft() < core.minNet then
|
||||||
core.minNet = net.getBytesLeft()
|
core.minNet = net.getBytesLeft()
|
||||||
end
|
end
|
||||||
|
@ -370,7 +419,7 @@ timer.create("NetCheck", 1, 0, function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
timer.create("RAMCheck", 1, 0, function()
|
timer.create("RAMCheck", 0.5, 0, function()
|
||||||
if ramUsed() > core.maxRAM then
|
if ramUsed() > core.maxRAM then
|
||||||
core.maxRAM = ramUsed()
|
core.maxRAM = ramUsed()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue