ELProfiler - statistical/sampling profiler

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Imagic
Prole
Posts: 45
Joined: Mon Sep 30, 2019 8:20 am
Contact:

ELProfiler - statistical/sampling profiler

Post by Imagic »

Until LÖVE bundles LuaJIT 2.1, which has a built-in profiler, this library can be used as an alternative.

I tried it on Conway's game of life available on the forum by just adding those lines at the top of the main.lua:

Code: Select all

local Profiler = require("ELProfiler")
Profiler.setClock(love.timer.getTime)
Profiler.start()
function love.quit() print(Profiler.format(Profiler.stop())) end
Cell size 4, rate 15.
The result with JIT enabled:
Profile: 60.202698584302s, 6020 samples
90.25% ?
9.72% Lua:world.lua:76:draw
0.03% Lua:world.lua:174:update
The result with JIT disabled:
Profile: 59.742081810862s, 5974 samples
49.23% ?
45.41% Lua:world.lua:174:update
4.00% Lua:world.lua:76:draw
1.36% Lua:world.lua:97:setCellState
The output is not easy to interpret because of the limitations of the debug API, but it may give clues.

Project and documentation: https://github.com/ImagicTheCat/ELProfiler
User avatar
Imagic
Prole
Posts: 45
Joined: Mon Sep 30, 2019 8:20 am
Contact:

Re: ELProfiler - statistical/sampling profiler

Post by Imagic »

Now that LÖVE 11.4 is released and uses LuaJIT 2.1, this library should no longer be used.

Here is the result with the built-in profiler with the same parameters by adding at the top of main.lua:

Code: Select all

require("jit.p").start("lv")
46% world.lua:193
<- 97% Garbage Collector
<- 3% Compiled
10% world.lua:196
<- 97% Compiled
<- 3% Garbage Collector
8% world.lua:194
<- 100% Compiled
7% world.lua:78
<- 70% C code
<- 25% Compiled
<- 5% Interpreted
3% world.lua:90
<- 70% C code
<- 23% Compiled
<- 8% Interpreted
3% world.lua:181
<- 100% Compiled
We can see that almost half of the execution is spent on garbage collection, mostly because of this code:

Code: Select all

			local check = {
					{x = x + 1, y = y},
					{x = x - 1, y = y},
					{x = x, 	y = y + 1},
					{x = x, 	y = y - 1},
					{x = x - 1, y = y + 1},
					{x = x + 1, y = y - 1},
					{x = x + 1, y = y + 1},
					{x = x - 1, y = y - 1}
				}
By replacing it with a nested loop FPS increase from 8 to 40-50, with a new profile without much garbage collection overhead:
36% world.lua:78
<- 67% C code
<- 28% Compiled
<- 5% Interpreted
20% world.lua:90
<- 62% C code
<- 30% Compiled
<- 8% Interpreted
...
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: ELProfiler - statistical/sampling profiler

Post by UnixRoot »

Imagic wrote: Sat Jan 08, 2022 5:13 pm Now that LÖVE 11.4 is released and uses LuaJIT 2.1, this library should no longer be used.

Here is the result with the built-in profiler with the same parameters by adding at the top of main.lua:

Code: Select all

require("jit.p").start("lv")
How to use it? What else do i need? I'm gettig this error.
Error

main.lua:2: module 'jit.p' not found:
no field package.preload['jit.p']
no 'jit/p' in LOVE game directories.
no file 'jit/p' in LOVE paths.
no file '.\jit\p.lua'
no file 'C:\Program Files\LOVE\lua\jit\p.lua'
no file 'C:\Program Files\LOVE\lua\jit\p\init.lua'
no file '.\jit\p.dll'
no file 'C:\Program Files\LOVE\jit\p.dll'
no file 'C:\Program Files\LOVE\loadall.dll'
no file '.\jit.dll'
no file 'C:\Program Files\LOVE\jit.dll'
no file 'C:\Program Files\LOVE\loadall.dll'


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'require'
main.lua:2: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: ELProfiler - statistical/sampling profiler

Post by yetneverdone »

UnixRoot wrote: Sun Jan 09, 2022 8:41 am
Imagic wrote: Sat Jan 08, 2022 5:13 pm Now that LÖVE 11.4 is released and uses LuaJIT 2.1, this library should no longer be used.

Here is the result with the built-in profiler with the same parameters by adding at the top of main.lua:

Code: Select all

require("jit.p").start("lv")
How to use it? What else do i need? I'm gettig this error.
Error

main.lua:2: module 'jit.p' not found:
no field package.preload['jit.p']
no 'jit/p' in LOVE game directories.
no file 'jit/p' in LOVE paths.
no file '.\jit\p.lua'
no file 'C:\Program Files\LOVE\lua\jit\p.lua'
no file 'C:\Program Files\LOVE\lua\jit\p\init.lua'
no file '.\jit\p.dll'
no file 'C:\Program Files\LOVE\jit\p.dll'
no file 'C:\Program Files\LOVE\loadall.dll'
no file '.\jit.dll'
no file 'C:\Program Files\LOVE\jit.dll'
no file 'C:\Program Files\LOVE\loadall.dll'


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'require'
main.lua:2: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
You can download the modules from https://github.com/love2d/love/actions/runs/1654407770 (choose accordingly). Then put that in your project. I suggest the path

Code: Select all

lua/jit
(if different you will setup the package.path). Now you can use

Code: Select all

require("jit.p").start("lv")
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: ELProfiler - statistical/sampling profiler

Post by zorg »

You can also make it one better by putting it in your löve folder instead (still under /lua/jit/) so you don't need to include the files in every project you make.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests