Add compile-time selectable profiling backend with Tracy integration#3239
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Thanks for your contribution and the PR! For optional features that are disabled by default, we recommend downloading their third-party library dependencies dynamically during the CMake configuration stage, rather than bundling them directly or downloading them unconditionally. Please refer to the following implementation and a previous PR for reference:
Could you please update the PR to follow this approach? Thank you! |
Sure, it totally makes sense, will rework. Thank you! |
|
lgtm |
Summary
This PR introduces compile-time selectable profiling backends for Axmol and provides an initial integration with the Tracy profiler.
The implementation preserves Tracy's zero-runtime-abstraction design by resolving the backend entirely at compile time. The existing built-in Axmol profiler remains unchanged and continues to work independently.
Currently supported backends:
NONE(no-op)TRACYThe design allows additional profiling backends to be integrated without changing engine code.
Motivation
While Axmol includes its own built-in profiler, it currently lacks integration with modern external profiling tools.
The goals of this implementation were:
Design
The profiling backend is selected entirely at compile time.
Engine code depends only on the profiling facade.
When
NONEis selected, profiling macros expand to no-op and generate no runtime code.The existing built-in Axmol profiler is unaffected by this change.
CMake
New cache option:
Supported values:
NONETRACYExample (included in the default template AXGameEngineOptions.cmake):
Public API
Introduces backend-independent profiling macros:
The engine itself never references Tracy directly outside the backend implementation.
Tracy integration
This PR includes:
Validation
Tested with:
AX_PROFILER_BACKEND=NONE, default): confirmed via CMake cache, build log, and binary inspection ofaxmol.libthat no Tracy symbols or strings are present, confirming zero overhead when profiling is disabled.Release with
AX_PROFILER_BACKEND=TRACYhas not yet been validated end-to-end and is left for a follow-up.Screenshot
Notes
This PR intentionally does not replace or modify the existing built-in Axmol profiler.
The built-in profiler and the new compile-time backend infrastructure coexist independently.
The current instrumentation intentionally focuses on the primary CPU frame flow and the major engine subsystems. More fine-grained zones can be added incrementally without changing the profiling infrastructure.
Prebuilt workflow fix
An issue was found where projects built via the "compile engine once, link
prebuilt" workflow (
-DAX_PREBUILT_DIR=...) failed with:Root cause: in prebuilt mode, the consumer project links against an
already-built
axmollibrary rather than compiling it from source, so theengine's own CMakeLists.txt (including the block that applies
AX_PROFILER_BACKEND_* as a compile definition) never runs for the consumer
project. The consumer's own translation units still include Profiling.h,
but never receive the backend macro.
Fix: extracted the backend-selection logic into a shared macro,
ax_apply_profiler_backend(target scope), inAXBuildHelpers.cmake—following the existing precedent of
ax_config_pred, which is applied bothin the engine's own CMakeLists.txt and in
AXLinkHelpers.cmake'sax_link_cxx_prebuiltfor the same reason (compile definitions don'tpropagate to prebuilt consumers). This avoids duplicating the same
if/elseif logic in two places.
Note:
ax_config_preditself was not reused directly, since it is designedfor boolean on/off options (
if(${pred})), while AX_PROFILER_BACKEND is astring enum (
NONE/TRACY) — passing it throughax_config_predwouldalways evaluate truthy regardless of value, which is not the desired
behavior.
This also adds an explicit
message(FATAL_ERROR ...)for unrecognizedAX_PROFILER_BACKEND values, which was previously silently ignored.