F = {
data1={}, data2={}, N1 = 300, N2 = 300, X = 10, previous_sample=0, nsamples=0, }
function update_footprint()
if Current_time-F.previous_sample < 1 then
return
end
F.previous_sample = Current_time
assert(#F.data1 <= F.N1)
if #F.data1 == F.N1 then
table.remove(F.data1, 1)
end
table.insert(F.data1, collectgarbage('count'))
F.nsamples = F.nsamples+1
if F.nsamples < F.X then
return
end
assert(#F.data2 <= F.N2)
if #F.data2 == F.N2 then
table.remove(F.data2, 1)
end
table.insert(F.data2, mean(F.data1, #F.data1-F.X+1, #F.data1))
F.nsamples = 0
end
function draw_debug()
if not Display_settings.show_debug then return end
App.color{r=1,g=1,b=1}
love.graphics.rectangle('fill', App.screen.width-900,App.screen.height-460, 900,460)
App.color{r=0.6,g=0.6,b=0.6}
love.graphics.rectangle('line', App.screen.width-895,App.screen.height-455, 890,450)
App.color{r=0,g=0,b=0}
draw_graph(F.data1, 'fast', App.screen.width-820,App.screen.height-445, 800,200, F.N1)
draw_graph(F.data2, 'slow', App.screen.width-820,App.screen.height-235, 800,200, F.N2)
end
function draw_graph(data, title, x,y, w,h, n)
love.graphics.line(x,y, x,y+h)
love.graphics.line(x,y+h, x+w,y+h)
love.graphics.print(title, x+w/2,y+h+5)
if #data == 0 then return end
local dx = w/n
local maxy = max(data)
maxy = math.floor(maxy*1.1/100)*100
love.graphics.print(tostring(maxy), x-70, y)
for i,val in ipairs(data) do
local xx = x + (i-1)*dx
local yy = y + (1 - val/maxy)*h
love.graphics.circle('fill', xx,yy, 2)
end
end
function sum(arr, lo, hi)
local result = 0
for i=lo,hi do
result = result + arr[i]
end
return result
end
function mean(arr, lo, hi)
return sum(arr, lo, hi)/(hi-lo+1)
end
function max(arr)
if #arr == 0 then return end
local result = arr[1]
for _,v in ipairs(arr) do
if v > result then
result = v
end
end
assert(result)
return result
end