uranium-core/stdlib/profiler.lua

56 lines
1.2 KiB
Lua
Raw Normal View History

2022-09-23 17:07:09 +02:00
PROFILER_ENABLED = true
profilerShowing = 'update'
local easable = require('stdlib.easable')
local text = BitmapText()
local quad = Quad()
oat.useProfiler = true
if PROFILER_ENABLED then
local max = easable(0)
local function draw()
if not profilerInfo[profilerShowing] then return end
2022-09-24 11:25:40 +02:00
quad:diffuse(0.2, 1, 0.2, 0.8)
2022-09-23 17:07:09 +02:00
quad:align(0, 0)
text:align(0, 0)
text:shadowlength(0)
table.sort(profilerInfo[profilerShowing], function(a, b) return a.t > b.t end)
local maxt = 0
for i, e in ipairs(profilerInfo[profilerShowing]) do
maxt = math.max(maxt, e.t)
quad:zoomto(e.t / max.a * sw * 0.4, 24)
quad:xy(0, i * 24)
quad:Draw()
text:settext((math.floor(e.t * 100000) / 100) .. 'ms')
2022-09-24 11:25:40 +02:00
text:xy(0, i * 24 - 3)
text:zoom(0.4)
2022-09-23 17:07:09 +02:00
text:diffuse(0.2, 0.2, 0.2, 0.9)
text:Draw()
text:settext(e.src)
2022-09-24 11:25:40 +02:00
text:xy(0, i * 24 + 8)
text:zoom(0.4)
2022-09-23 17:07:09 +02:00
text:diffuse(0.1, 0.1, 0.1, 0.9)
text:Draw()
end
max:set(maxt)
text:diffuse(1, 1, 1, 1)
text:xy(0, 0)
text:zoom(0.5)
text:shadowlength(3)
text:settext('Profiler - ' .. profilerShowing)
text:Draw()
end
2022-09-24 11:25:40 +02:00
function uranium.postUpdate(dt)
2022-09-23 17:07:09 +02:00
max(dt * 12)
draw()
end
end