[Mod] LuaJIT Profiler [jitprofiler]

Post Reply
User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

[Mod] LuaJIT Profiler [jitprofiler]

by jwmhjwmh » Post

This mod just lets you use LuaJIT's builtin profiler. You need to add it to the secure.trusted_mods list. This profiler is good for pinpointing expensive parts of the code.

How to Use
  1. Enable the mod.
  2. In-game start the profiler with /jitprofiler_start 1 <filename>. The profiling data will be written to <worldpath>/jitprofiles/<filename>.
  3. Collect data for a while.
  4. Stop profiling with /jitprofiler_stop or by exiting the world.
  5. Download FlameGraph.
  6. Create a flamegraph SVG with ./flamegraph.pl <worldpath>/jitprofiles/<filename> > graph.svg.
  7. Open the SVG in your browser.
  8. The top level of each stack snapshot will be "C", "G", "I", "J", or "N", representing C code, garbage collection, interpreter, JIT compilation, or compiled code, respectively.
Issues
  • Using this with luacontrollers can cause crashes for some reason.
  • Sometimes a lot of C code execution is reported in suspicious places. I think this represents time taken by the Minetest engine, but I don't know why the profiler thinks the code is executed inside a Lua function.
Download

GitHub

ZIP


Required Info

License: MIT

(Optional) dependencies: none
Last edited by jwmhjwmh on Tue Oct 04, 2022 15:03, edited 1 time in total.

wsor4035
Member
Posts: 184
Joined: Sun Aug 11, 2019 21:23
GitHub: wsor4035
IRC: wsor
In-game: wsor

Re: [Mod] LuaJIT Profiler [jitprofiler]

by wsor4035 » Post

if i had to hazard a guess about it not liking luacontrollers, its probably due to it turning jit off for its sandbox (or generally related to the sandbox) https://github.com/minetest-mods/meseco ... #L573-L575
j5uBLfc6NxgersvVj5D5dIsiKDkoQb0o

User avatar
Festus1965
Member
Posts: 4181
Joined: Sun Jan 03, 2016 11:58
GitHub: Festus1965
In-game: Festus1965 Thomas Thailand Explorer
Location: Thailand ChiangMai
Contact:

[Mod] LuaJIT Profiler [jitprofiler] - How to 'read' it ?

by Festus1965 » Post

How to 'read'/use it ?

example:
run about 10 minutes, starting one login to start /jitprofiler end exit, finish log with close terminal

engine 5.5.1 - game 'empty'
* without profiler
** empty.txt.zip
** empty.svg
Image

rest of example moved to discussion thread ... as this here should be only about mod itself.

Yes, I get your following answer about the impact of C itself (at start and so low difference in Watt between empty and mtg), as most work is still done via C,
but that can only be for engine itself, maybe builtin mods,
and I wall look more forward, how more mods will or not also change C base part.

So far, there is a main starting pack, automatic coming with still C code,
but later that should not raise anymore (in absolute time) as mods are all in lua.
Last edited by Festus1965 on Wed May 18, 2022 06:21, edited 24 times in total.
Human has no future (climate change)
If urgend, you find me in Roblox (as CNXThomas)

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: [Mod] LuaJIT Profiler [jitprofiler] - How to 'read' it ?

by jwmhjwmh » Post

Festus1965 wrote:
Wed May 18, 2022 03:29
How to 'read'/use it ?


WAIT with anser ... I ahve to confirm, if no mistake !@


example:
engine 5.5.1 - game 'empty'
run about 10 minutes, starting one login to start /jitprofiler

output file:
* /usr/local/share/minetest/builtin/game/register.lua:415;C 1 (! most)
* /usr/local/share/minetest/builtin/game/register.lua:415;C 8 (1*)
* /usr/local/share/minetest/builtin/game/register.lua:415;I 1 (? 4*)
* /usr/local/share/minetest/builtin/game/register.lua:415;/usr/local/share/minetest/builtin/common/after.lua:5;I 1
*/usr/local/share/minetest/builtin/game/register.lua:415;C 2 (2*)
* /usr/local/share/minetest/builtin/game/register.lua:415;/usr/local/share/minetest/builtin/profiler/sampling.lua:143;N 1
* /usr/local/share/minetest/builtin/game/register.lua:415;N 1

Spoiler
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 2
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;/usr/local/share/minetest/builtin/common/after.lua:5;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 2
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 2
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;/usr/local/share/minetest/builtin/profiler/sampling.lua:143;N 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;I 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;N 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 1
/usr/local/share/minetest/builtin/game/register.lua:415;C 2
Image
This illustrates one of the issues I mentioned. The large "C" part there is probably stuff being done by the Minetest engine itself. When profiling mods, just ignore that. You can click on one of the other subsections to zoom in on it.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] LuaJIT Profiler [jitprofiler]

by loosewheel » Post

This looks interesting. Its handy to be able to see how much load code is producing. Especially when trying to work out which of multiple versions of code run the best.

This is the first time I’ve seen this, so correct me if I’m wrong. The graph shows each stack of code as a proportion of the ‘all’. This could be most useful for testing something like a global step callback for load on the game, but is harder to determine an arbitrary piece of running code.

I added a chat command jitprofiler_benchmark <integer>. This command concatenates a string one character at a time to <length>. This provides a fixed load (assuming the length is the same) as a comparative across test.

Code: Select all

local function benchmark (length)
	local s = ""
	for a = 1, length, 1 do
		s = s.."a"
	end
end

minetest.register_chatcommand("jitprofiler_benchmark", {
	description = "Benchmark LuaJIT's profiler",
	params = "<length>",
	privs = {server = true},
	func = function(_name, param)
		if not outfile then
			return false, "Profiler not running"
		end

		local length = tonumber (param)
		if type (length) ~= "number" or length < 1 then
			return false, "Invalid benchmark size"
		end

		benchmark (length)

		return true, "Profiler benchmark "..tostring (length).." complete"
	end,
})
The load is in a separate function so it shows in the profile.

In the following the stack on the left is the fixed load, and the stack on the right is the code being tested.
test.png
test.png (42.66 KiB) Viewed 3256 times
In the tests the first runs some in-game code in a computer, and the second runs the same code about five times. While the fixed load is proportionately different it is the same benchmark command length. This is a useless test but its only for demonstration.

This doesn’t provide an empirical measure of load, but provides a good comparative. I think its easier to guesstimate how much demand a piece of code is producing, and easier to determine which of two code versions makes less demand.
wsor4035 wrote:
Wed May 18, 2022 02:49
if i had to hazard a guess about it not liking luacontrollers, its probably due to it turning jit off for its sandbox (or generally related to the sandbox) https://github.com/minetest-mods/meseco ... #L573-L575
I tried this with lwcomputers, which turn jit off for sandboxing, and it ran OK. I don’t know if this means anything with regards to luacontrollers.

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: [Mod] LuaJIT Profiler [jitprofiler]

by jwmhjwmh » Post

loosewheel wrote:
Wed May 18, 2022 08:44
I added a chat command jitprofiler_benchmark <integer>. This command concatenates a string one character at a time to <length>. This provides a fixed load (assuming the length is the same) as a comparative across test.
Good idea. Maybe you could make the fixed load be a tight loop waiting for minetest.get_us_time() to reach a certain value, giving you a fairly precise duration.
loosewheel wrote:
Wed May 18, 2022 08:44
wsor4035 wrote:
Wed May 18, 2022 02:49
if i had to hazard a guess about it not liking luacontrollers, its probably due to it turning jit off for its sandbox (or generally related to the sandbox) https://github.com/minetest-mods/meseco ... #L573-L575
I tried this with lwcomputers, which turn jit off for sandboxing, and it ran OK. I don’t know if this means anything with regards to luacontrollers.
The error only shows up occasionally. This is the backtrace I got:

Code: Select all

ServerError: AsyncErr: Lua: Runtime error from mod '??' in callback environment_Step(): .../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:574: bad action while in __gc metamethod
stack traceback:
	[C]: in function 'off'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:574: in function 'create_sandbox'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:634: in function 'run_inner'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:690: in function 'run'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:719: in function <.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:715>
	...newjude/.minetest/mods/mesecons/mesecons/actionqueue.lua:137: in function 'execute'
	...newjude/.minetest/mods/mesecons/mesecons/actionqueue.lua:111: in function <...newjude/.minetest/mods/mesecons/mesecons/actionqueue.lua:73>
	...wjude/projects/minetest/bin/../builtin/game/register.lua:429: in function <...wjude/projects/minetest/bin/../builtin/game/register.lua:415>

User avatar
Festus1965
Member
Posts: 4181
Joined: Sun Jan 03, 2016 11:58
GitHub: Festus1965
In-game: Festus1965 Thomas Thailand Explorer
Location: Thailand ChiangMai
Contact:

Re: [Mod] LuaJIT Profiler [jitprofiler]

by Festus1965 » Post

So far from yesterday,
yes the time in % is always from the sum
and I recalculated back with my test top20 profiler mods from AsiaThailand
and also there pipeworks leads up with recalculated to only mods are 100% with 24.39 %, followed by stats ...

One thing:
That C code is triggered is if you call ... builtin C code ?


/status : what depends on the inner engine C code to answer, (max_lagEstimated)

or every mod that uses kind of serialization or file save from the engine ?

or even call dtime ?
Human has no future (climate change)
If urgend, you find me in Roblox (as CNXThomas)

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: [Mod] LuaJIT Profiler [jitprofiler]

by jwmhjwmh » Post

Festus1965 wrote:
Thu May 19, 2022 01:56

One thing:
That C code is triggered is if you call ... builtin C code ?
I think "C" is recorded either when a builtin C function is called or when Minetest's main loop (written in C++) is executing. If you see C code inside a function which was not called directly from the engine itself, that C code represents the execution of builtin C functions.

User avatar
Festus1965
Member
Posts: 4181
Joined: Sun Jan 03, 2016 11:58
GitHub: Festus1965
In-game: Festus1965 Thomas Thailand Explorer
Location: Thailand ChiangMai
Contact:

Re: [Mod] LuaJIT Profiler [jitprofiler]

by Festus1965 » Post

jwmhjwmh wrote:
Thu May 19, 2022 02:03
I think "C" is recorded either when a builtin C function is called or when Minetest's main loop (written in C++) is executing. If you see C code inside a function which was not called directly from the engine itself, that C code represents the execution of builtin C functions.
oh careful :
either the separated C OVER a named (svg view) mod like I see at pipeworks IS called and run as of mod pipeworks or any other mod shown under as main part,

or the hole measurement is worthless then either, when the profiler can't clear point a call to normal or mod belonging.

Image
AsiaThailand-T20.svg

For me, when I click part mod pipeworks, there opens more lines over,
* move entity globalstep part 1 : main part with again parts over,
** with more then 50% C, and rest G I N
and
* move ... part 2 with only I

so if at this clock and enlarge open the C in the mod (pipeworks) is NOT called as of this mod, then the result would be useless.
Human has no future (climate change)
If urgend, you find me in Roblox (as CNXThomas)

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: [Mod] LuaJIT Profiler [jitprofiler]

by jwmhjwmh » Post

Festus1965 wrote:
Thu May 19, 2022 03:16
jwmhjwmh wrote:
Thu May 19, 2022 02:03
I think "C" is recorded either when a builtin C function is called or when Minetest's main loop (written in C++) is executing. If you see C code inside a function which was not called directly from the engine itself, that C code represents the execution of builtin C functions.
oh careful :
either the separated C OVER a named (svg view) mod like I see at pipeworks IS called and run as of mod pipeworks or any other mod shown under as main part,

or the hole measurement is worthless then either, when the profiler can't clear point a call to normal or mod belonging.

Image
AsiaThailand-T20.svg

For me, when I click part mod pipeworks, there opens more lines over,
* move entity globalstep part 1 : main part with again parts over,
** with more then 50% C, and rest G I N
and
* move ... part 2 with only I

so if at this clock and enlarge open the C in the mod (pipeworks) is NOT called as of this mod, then the result would be useless.
Just ignore the big "C" part directly inside register.lua:415. The C code inside move_entities_globalstep_part1 is probably from Settings:get, minetest.get_connected_players, and ObjectRef:get_pos

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] LuaJIT Profiler [jitprofiler]

by loosewheel » Post

jwmhjwmh wrote:
Wed May 18, 2022 14:23
loosewheel wrote:
Wed May 18, 2022 08:44
I added a chat command jitprofiler_benchmark <integer>. This command concatenates a string one character at a time to <length>. This provides a fixed load (assuming the length is the same) as a comparative across test.
Good idea. Maybe you could make the fixed load be a tight loop waiting for minetest.get_us_time() to reach a certain value, giving you a fairly precise duration.
That does work better. jitprofiler_benchmark <seconds>

Code: Select all

local function benchmark (secs)
	local now = minetest.get_us_time ()

	while ((minetest.get_us_time () - now) / 1000000) < secs do end
end

minetest.register_chatcommand("jitprofiler_benchmark", {
	description = "Benchmark LuaJIT's profiler",
	params = "<seconds>",
	privs = {server = true},
	func = function(_name, param)
		if not outfile then
			return false, "Profiler not running"
		end

		local secs = tonumber (param)
		if type (secs) ~= "number" or secs <= 0 then
			return false, "Invalid benchmark time"
		end

		benchmark (secs)

		return true, "Profiler benchmark "..tostring (secs).." complete"
	end,
})
jwmhjwmh wrote:
Wed May 18, 2022 14:23
loosewheel wrote:
Wed May 18, 2022 08:44
wsor4035 wrote:
Wed May 18, 2022 02:49
if i had to hazard a guess about it not liking luacontrollers, its probably due to it turning jit off for its sandbox (or generally related to the sandbox) https://github.com/minetest-mods/meseco ... #L573-L575
I tried this with lwcomputers, which turn jit off for sandboxing, and it ran OK. I don’t know if this means anything with regards to luacontrollers.
The error only shows up occasionally. This is the backtrace I got:

Code: Select all

ServerError: AsyncErr: Lua: Runtime error from mod '??' in callback environment_Step(): .../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:574: bad action while in __gc metamethod
stack traceback:
	[C]: in function 'off'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:574: in function 'create_sandbox'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:634: in function 'run_inner'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:690: in function 'run'
	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:719: in function <.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:715>
	...newjude/.minetest/mods/mesecons/mesecons/actionqueue.lua:137: in function 'execute'
	...newjude/.minetest/mods/mesecons/mesecons/actionqueue.lua:111: in function <...newjude/.minetest/mods/mesecons/mesecons/actionqueue.lua:73>
	...wjude/projects/minetest/bin/../builtin/game/register.lua:429: in function <...wjude/projects/minetest/bin/../builtin/game/register.lua:415>
This seems to be crashing when the profiler takes a sample while inside the jit.off function itself. The tests to produce the graphs above wouldn't cause this. But I did several tests before that which could, suspecting it would crash for the same reason as luacontrollers. I must have just been lucky.

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: [Mod] LuaJIT Profiler [jitprofiler]

by jwmhjwmh » Post

I have finally put this on GitHub.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 2 guests