Tracy profiler integration for Urho3D


I’m integrating Tracy profiler ( into Urho3D. If it’s only the client side integration, things should be neat. Tracy profiler should be a good plus to the engine.

It’s working great on Windows -

but, I find a compiling issue for Android:

D:\AndroidDev\AndroidSDK\ndk\22.0.7026061\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi18 --gcc-toolchain=D:/AndroidDev/AndroidSDK/ndk/22.0.7026061/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidDev/AndroidSDK/ndk/22.0.7026061/toolchains/llvm/prebuilt/windows-x86_64/sysroot  -DNOMINMAX=1 -DTRACY_ENABLE=1 -DURHO3D_ANGELSCRIPT -DURHO3D_FILEWATCHER -DURHO3D_IK -DURHO3D_LOGGING -DURHO3D_LUA -DURHO3D_NAVIGATION -DURHO3D_NETWORK -DURHO3D_PHYSICS -DURHO3D_PROFILING -DURHO3D_STATIC_DEFINE -DURHO3D_THREADING -DURHO3D_URHO2D -DURHO3D_WEBP -DWIN32_LEAN_AND_MEAN -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE -D_USE_MATH_DEFINES  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -std=c++11 -Wno-invalid-offsetof -Qunused-arguments -fcolor-diagnostics -Wno-argument-outside-range -O0 -fno-limit-debug-info  -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracySysTrace.cpp.o -MF Source\ThirdParty\Tracy\CMakeFiles\Tracy.dir\client\TracySysTrace.cpp.o.d -o Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracySysTrace.cpp.o -c ../../../../../../Source/ThirdParty/Tracy/client/TracySysTrace.cpp
../../../../../../Source/ThirdParty/Tracy/client/TracySysTrace.cpp:638:21: error: use of undeclared identifier '__NR_perf_event_open'
    return syscall( __NR_perf_event_open, hw_event, pid, cpu, group_fd, flags );
1 error generated.
[18/945] Building CXX object Source/ThirdParty/Tracy/CMakeFiles/Tracy.dir/client/TracyProfiler.cpp.o
ninja: build stopped: subcommand failed.

NDK 21.0.6113669 and 22.0.7026061 have been tried.

Any ideas?


1 Like

Fortunatelly, we have an expert in integrating Tracy into Urho. @rku?

Disable context switch profiling on android i think

According to Tracy’s document -

Context switch should be supported on Android and if there is no direct fixing, I have to disable TRACY_HAS_SYSTEM_TRACING completely to make it work on Android.

I have submitted an issue on Tracy -

1 Like

The compiling issue has been solved by adding #include <sys/syscall.h> to the source, but now there is a linking issue -

  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  [13/104] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\
  FAILED: ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/
  cmd.exe /C "cd . && D:\AndroidDev\AndroidSDK\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi18 --gcc-toolchain=D:/AndroidDev/AndroidSDK/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidDev/AndroidSDK/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -std=c++11 -Wno-invalid-offsetof -Qunused-arguments -fcolor-diagnostics -Wno-argument-outside-range -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname, -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\ Samples/01_HelloWorld/CMakeFiles/01_HelloWorld.dir/HelloWorld.cpp.o  D:/code/man/Urho3D/android/urho3d-lib/build/tree/Debug/armeabi-v7a/lib/libUrho3D.a -ldl -llog -landroid -lGLESv1_CM -lGLESv2 -latomic -lm && cd ."
  ../../../../../../Source/ThirdParty/Tracy/client/TracyProfiler.cpp:123: error: undefined reference to 'tracy::rpmalloc_initialize()'

function tracy::rpmalloc_initialize() in source code -

object generated -

Interesting situation…

Maybe remove the extern from the function definition?

Thank you! However, the link issue still exists :thinking:

Try using STATIC lib type instead of SHARED. If the “Urho3DPlayer” target is successfully built after that then the issue was with your shared lib already eliminating unused symbols.

And, if you were already using STATIC lib type then it means the symbol was not in the libUrho3D.a despite what you have setup. You can verify that using “nm”.


Thank you @weitjong!

I think you are right.

I’m using the STATIC lib of Urho3D, and lib Tracy is supposed to live inside of lib Urho3D. However, since Tracy is used everywhere in the Samples by including headers and inserting macros but some of the symbols are just elimiated.

It seems we have three choices -

  • Export all missed functions of Tracy, just like this commit ( is doing. But I don’t know the full list in which we include all necessary functions.
  • Add lib Tracy to applications’ dependencis instead of just linking lib Urho3D. It seems not the way we handle third-party libraries in Urho but still practical.
  • I wonder if there is way to ask the build toolchain to keep the symbols of Tracy and not optimize them in the Urho3D, instead delay the optimization till the application building phase?

All remides me to do a testing for the release version, which may lead more such potential issues.

You misunderstood me a little bit. Only the SHARED lib type needs special consideration (what get exported) in order to avoid undesired symbol elimination while building the shared library itself. On the other hand the STATIC lib type does not suffer from this kind of elimination issue. It is basically just a collection or archive of all the objects there are in the said library target. Assuming you only interested in using the STATIC lib type then you can either:

  1. Rely on the existing “librarian” logic that Urho3D library has. If you add a new third-party lib with Urho3D provided macro (i.e not using the vanila CMake command) then it should automatically set thing up for you. The librarian will merge all the objects from the new lib (Tracy) into the libUrho3D.a while the Urho3D target is being built.

  2. Set it up as you have mentioned in your second bullet point. Add a new third-party lib with the vanila CMake command to do so. It should then just build libTracy.a or what have you, which should contain all the objects from this new target. Note that I said, “it should” here as I don’t know anything about this profiling library. In the app then you have to explicitly tell CMake that the app depends on this new library.

Yes, I’m using the approach you explained in your first bullet point. Tracy is added just like other 3rd-party libraries of Urho.

I just don’t understand why these symbols got removed. Maybe it’s an issue of Tracy.

It is easy to debug. Each 3rd-party lib is built and the *.a is generated first before it get merged into the final libUrho3D.a. You can quickly verify if your libTracy.a has all the objects you need.

Thank you @weitjong

Android platform is now working with Tracy. However, there are some issues I need to solve to make the integration more solid.

After some polishing work and testing on maybe Linux, I think I’d make a PR and ask the community to check it.

1 Like

Tracy integration in rbfx broke MinGW support, so if you care about continuing support for that platform you might need to do a little work.

Hi @JTippetts1,

Can you describe the issue with more details?
I’d like to have a try after fixing my Hello World issues on Linux.

Currrent, Android and Windows should be good with some minor changes on the integration and and fixings for Tracy.

I’m not sure if I can make my old MacBook Pro run again. I’d try to have the integration work on MACOS and IOS if I have some spare time for this side work.

As for rbfx, I have checked the work there. The Tracy profiler tool has been integrated into the Editor, which is very impressive. However, I think in Urho, we can keep thing simple by just integrating the client, and use standard Tracy tool avoid the introduction of other dependencies.

AFAIK, the Tracy support for other platforms in rbfx is limited, no Android (yet?) and I must have missed the Release configurations in Visual Studio solution cmake generated?

Ideally, people could have brought Tracy integration into Urho3D from rbfx in a non disrupted community, so my work can be just fixing some issues for it. Anyway, I don’t really think this is a big issue in this case.

Not exactly correct. MinGW builds work fine as long as you do not enable Tracy. Actually problem is quite minor too. MinGW is :poop: so even latest SDK does not provide all windows APIs, some of which Tracy uses. What we have to do is load those APIs using LoadLibrary+GetProcAddress.

By default Tracy uses glfw for platform window creation. At very least client would have to be reworked to use SDL, or even Urho3D. That is not a big deal, but an annoyance when it comes to updating Tracy.

My primary reason for integrating Tracy was that Urho3D profiler is unusable on mobiles. Profiling phones over the network works just fine.

Finally have some vacation and can finish this.

This is the pull request! -

Integration Decision

In the current integration, only client side code is integrated into Urho3D, so we don’t have to introduce a whole family of Tracy dependencies into Urho3D, instead, we use standard Tracy tools. Current version of Tracy in our ThirdParty folder is the latest release 0.7.6 (Release Tracy Profiler 0.7.6 · wolfpld/tracy · GitHub). An issue on Android virtual device App fails on Android AVD when calling SetupHwTimer · Issue #173 · wolfpld/tracy · GitHub really takes me sometime to figure out and it is one of the reasons why this PR is delayed.

Build Option

URHO3D_TRACY_PROFILING build option toggles this feature, meaning it is optional and can be used when we need the extra profiling ability and the target platform is supported by Tracy. The original profiling related macros and their references are reused and extended.

Edit: (updated due to changes in recent commit)
Pseudo code of build control:

    // Tracy used
    // Default Urho3D profiling used.
    // Profiling off.

Platforms ([x] means the support is validated)

  • [x] Windows
  • [x] MinGW
  • [x] Linux
  • [x] Android (Physical/Virtual)
  • [?] macOS
  • [?] iOS
  • [?] ??


1. Enable Tracy integration
Edit: (updated due to changes in recent commit)
Build Urho3D and its Samples with extra build option -D URHO3D_TRACY_PROFILING=1.
URHO3D_PROFILING will be automatically turned off when URHO3D_TRACY_PROFILING is on. This is achieved in UrhoCommon.cmake script.

    set (URHO3D_PROFILING 0)
endif ()

2. Download or build the Tracy server

3. Run a sample

Enjoy Urho3D!