SPH - Performance/Profiler HUD

Here’s my version of a Solar2D profiler in Lua:

Provides two modes, horizontal and vertical. The latter is draggable, but both can be positioned via x/y properties.

Helps keep an eye on the usual stuff (fps, texture binds, shader binds, triangles, draw calls, and memory usage for Lua and textures.)

Could probably use customization at a future time.

To use it just place sph.lua in your project folder and require it.

local sph = require("sph")

Use F2 to show/hide or F3 to toggle mode. These keys can be reassigned using sph.setConfig({}) (see API in the repo)

Happy profiling!

5 Likes

Hi Siu. I tried to use this but I’m getting a runtime error at line 180 with display.enableStatistics(true) (a nil value). I don’t recognise this display function and couldn’t find anything about it on the solar2d pages…?


What version of solar2D are you using?

display.enableStatistics is an API added since v2024.3713; it’s not mentioned in the documentation.

Ah. I’m using a version older than that. I better update!

I’ll be the first to say I’m reluctant to update too regularly, but as 3713 is almost 18 months old now it was probably a good thing that this prompted you to update :grinning_face: .

There’s a few things that have been fixed/updated since then.

Thanks for sharing. Added to awesome-solar2d right away!

Also, thank you @NerdyTurkey for pointing to an undocumented API. I’m now looking into it(and some more) :slight_smile:

2 Likes

Nice, good to use.

1 Like

Just FYI, your CPU and GPU timings are very inaccurate and not representative of actual runtime values. The values returned from display.getStatistics() are not usable for that, you need to use display.getTimings() instead.

You can use plugin.profiler if you want accurate, frame, layout and GPU timings. You can check the source to my plugin to see how the real timings are derived.

Nice work on the vertical/horizontal flip - that’s kinda cool!

2 Likes

@solar_dev, I’ll definitely look into it, much appreciated!

@NerdyTurkey, I’ll add a warning and make note of it in case there are others using older versions, thanks!

I updated to latest version of solar2d and it works fine. Nice tool!

1 Like