Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Lua Profiling using Tracy

Leo Göttlicher edited this page Sep 6, 2023 · 3 revisions

Setup

  1. Get the tracy profiler from https://github.com/wolfpld/tracy
  2. Markup your lua code (See Lua Markup)
  3. Run Tracy.exe
  4. Run the game
  5. Hit connect in the profiler

Notes: The tracy profiler can use a lot of Memory, so you might only want to connect the profiler once you know the script is running

Lua Markup (Instrumentation)

For basic profiling you can simply add tracy.ZoneBegin() at the start of your lua functions and tracy.ZoneEnd() before every return and at the end of the function or region you want to profile.

Those marked Zones should now show up in the Statistics window under Instrumentation.

By default Zones are named only by the script file name and line number, so for easier organization you may create named zones by using tracy.ZoneBeginN("NAME") instead.

Messages

Tracy also has a message system, where you can attach messages to your marked zones. So if you want additional info you may use

tracy.Message("Your message here")

to print additional information that might help you understand what your code is actually doing in specific frames (this can of course be dynamic strings).

Comparing profiling runs

The point of profiling is of course to see how your code improves with changes. Tracy can help you by providing a comparison mode in which you can load a saved tracy file to compare against. However this only provides useful data if you captured the same thing both times. To load a trace to compare simply use the compare button and follow directions.

Tracy Documentation

For much more (possibly too much) information and a lesson on profiling read the tracy manual Documentation (lua documentation is on page 41-42)

Troubleshooting

Marked up zones are just one giant blob

You missed some return paths or you have errors in your code causing your marked up region to exit early. Check the console for errors (first) and check that all return paths have a ZoneEnd before them.

There's a billion layers of other stuff I don't need to see

Go to Options and uncheck Draw ghost zones.

Nothing is showing up

Check that the code you're profiling is actually runngning.