Added memmory usage to debug menu and logging

This commit is contained in:
bizcochito 2022-01-31 15:03:14 +01:00
parent ed3d8a90ec
commit b4311064f6
2 changed files with 85 additions and 26 deletions

View File

@ -1,7 +1,5 @@
function DebugUI() function DebugUI()
local mouse_x, mouse_y = love.mouse.getPosition() local mouse_x, mouse_y = love.mouse.getPosition()
for _, light in pairs(Lights) do for _, light in pairs(Lights) do
love.graphics.print(light.pos.x,light.pos.x,light.pos.y) love.graphics.print(light.pos.x,light.pos.x,light.pos.y)
love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20) love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20)
@ -9,6 +7,7 @@ for _, light in pairs(Lights) do
end end
love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale) love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale)
love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale)
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
-- lots of variables -- lots of variables
@ -45,3 +44,46 @@ function DebugEntities()
enty:Debug() enty:Debug()
end end
end end
--[[CPUUsage = {}
function checkCPUTime(action, name)
if name then
if action == "start" then
if CPUUsage.name == nil then CPUUsage.name = {} end
CPUUsage.name.start = os.clock()
elseif action == "fin" then
CPUUsage.name.fin = os.clock()
CPUUsage.name.use = CPUUsage.name.fin - CPUUsage.name.start
if CPUUsage.name.total == nil then CPUUsage.name.total = 0 end
CPUUsage.name.total = CPUUsage.name.total + CPUUsage.name.use
print(CPUUsage.name.fin.." : "..CPUUsage.name.use.." : "..CPUUsage.name.total)
elseif action == "get" then
return CPUUsage.name.use
elseif action == "total" then
return CPUUsage.name.total
else
return CPUUsage.name.use
end
-- Totals
else
if action == "get" then
local currentTotalCPU = 0
for _, timings in ipairs(CPUUsage) do
currentTotalCPU = currentTotalCPU + CPUUsage.timings.use
end
return currentTotalCPU
elseif action == "total" then
local currentTotalCPU = 0
for _, timings in ipairs(CPUUsage) do
currentTotalCPU = currentTotalCPU + CPUUsage.timings.total
end
return currentTotalCPU
else
local currentTotalCPU = 0
for _, timings in ipairs(CPUUsage) do
currentTotalCPU = currentTotalCPU + CPUUsage.timings.use
end
return currentTotalCPU
end
end
end]]

View File

@ -1,4 +1,6 @@
function love.load() function love.load()
--logging = true
if logging then print("love: "..collectgarbage("count").." kB") end
arrow = 0 arrow = 0
do_pause = false do_pause = false
@ -54,6 +56,9 @@ function love.load()
--CursedBook:New(180,68) --CursedBook:New(180,68)
gravity = 0.2 gravity = 0.2
-- Debug and log stuff
memoryUsage, dtcount = 0, 0
if logging then print("mothback: "..collectgarbage("count").." kB, Loading time: "..os.clock().." seconds") end
end end
function love.update(dt) function love.update(dt)
@ -68,6 +73,18 @@ function love.update(dt)
fps_count = fps_count + 1 fps_count = fps_count + 1
current_dt = dt current_dt = dt
-- things per second
dtcount = dtcount + dt
if dtcount >= 1 then
if secs == nil then secs = 0 end
secs = secs + 1
dtcount = dtcount - 1
if debug or logging then
memoryUsage = math.floor(collectgarbage("count"))
end
if logging then print("Second "..secs..": "..memoryUsage.." kB") end
end
--keypressed --keypressed
if Keybind:HasPressed(Keybind.menu.pause) then if Keybind:HasPressed(Keybind.menu.pause) then
if do_pause then if do_pause then