Skip to content

Commit 765fb7f

Browse files
authored
Add compile-time selectable profiling backend with Tracy integration (#3239)
* Profiling: add Tracy 0.13.1 sources * Profiling: integrate Tracy to build system, default to noop * Profiling: add Tracy to 3dparty README.md * Profiling: Tracy compilation flags * Profiling: add Tracy to 3rd-party build flow * Profiling: update cmake template with Tracy * Profiling: track basic Frame * Profiling: move AX_PROFILER_BACKEND cmake variable to the main module * Profiling: remove unnecessary AX_WITH_TRACY logging * Profiling: rename AX_PROFILER_ macroses to be consistent * Profiling: setup basic AX_PROFILER_ macroses across the engine * Profiling: separate AX_PROFILER_ZONE_SCOPED for AudionEngine update * Profiling: apply clang-format fixes * Profiling: fix backend includes * Profiling: fix AX_PROFILER_BACKEND define missing in prebuilt workflow * Profiling: move 3d-party Tracy dependency out of the repo, fetch on build when opt-in
1 parent 060bc18 commit 765fb7f

23 files changed

Lines changed: 170 additions & 0 deletions

1k/build.profiles

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ lz4=v1.10.0
100100
sample-assets=v3.0.0-alpha22
101101
live2d-core=5.5
102102
openxr=release-1.1.61
103+
tracy=v0.13.1
103104
# --- endregion

1k/sources.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
},
4141
"live2d-core": {
4242
"sources": { "origin": "https://github.com/axmolengine/live2d-axmol/releases/download/prebuilt/live2d-core-${ver}.zip" }
43+
},
44+
"tracy": {
45+
"sources": { "origin": "https://github.com/wolfpld/tracy.git" }
4346
}
4447
},
4548
"devtools": {

3rdparty/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ option(AX_WITH_WEBP "Build with internal webp support" ON)
66
option(AX_WITH_CLIPPER2 "Build with internal Clipper2 support" ON)
77
option(AX_WITH_POLY2TRI "Build with internal poly2tri support" ON)
88
option(AX_WITH_FASTLZ "Build with internal fastlz support" ON)
9+
option(AX_WITH_TRACY "Build with internal Tracy support" ON)
910

1011
option(AX_WITH_CURL "Build with internal curl support" ON)
1112
option(AX_WITH_UNZIP "Build with internal unzip support" ON)
@@ -424,6 +425,20 @@ if(WIN32 AND AX_GLES_PROFILE)
424425
endif()
425426
endif()
426427

428+
# tracy
429+
if(AX_PROFILER_BACKEND STREQUAL "TRACY")
430+
set(AX_WITH_TRACY ON CACHE BOOL "" FORCE)
431+
else()
432+
set(AX_WITH_TRACY OFF CACHE BOOL "" FORCE)
433+
endif()
434+
435+
if(AX_WITH_TRACY)
436+
_1kfetch(tracy)
437+
set(TRACY_ENABLE ON CACHE BOOL "" FORCE)
438+
set(TRACY_ON_DEMAND ON CACHE BOOL "" FORCE)
439+
ax_add_3rd(${tracy_SOURCE_DIR} TARGETS TracyClient)
440+
endif()
441+
427442
# yasio
428443
ax_add_3rd(yasio)
429444

3rdparty/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@
249249
- Version: 2.30
250250
- License: MIT
251251

252+
## tracy
253+
- [![Upstream](https://img.shields.io/github/v/release/wolfpld/tracy?label=Upstream)](https://github.com/wolfpld/tracy)
254+
- Version: 0.13.1
255+
- License: BSD-3-Clause
256+
252257
## unzip (minizip-1.2)
253258
- Upstream: https://github.com/simdsoft/mz12
254259
- Version: 1.2, with bugfixs & improvements

axmol/2d/ActionManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ ssize_t ActionManager::getNumberOfRunningActions() const
392392
// main loop
393393
void ActionManager::update(float dt)
394394
{
395+
AX_PROFILER_ZONE_SCOPED;
396+
395397
for (auto actionIt = _targets.begin(); actionIt != _targets.end();)
396398
{
397399
auto elt = &actionIt->second;

axmol/2d/Sprite.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ THE SOFTWARE.
4444
#include "axmol/renderer/Shaders.h"
4545
#include "axmol/rhi/ProgramState.h"
4646
#include "axmol/rhi/GraphicsCore.h"
47+
#include "axmol/base/Profiling.h"
4748

4849
namespace ax
4950
{
@@ -1069,6 +1070,8 @@ void Sprite::updateTransform()
10691070
// draw
10701071
void Sprite::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
10711072
{
1073+
AX_PROFILER_ZONE_SCOPED;
1074+
10721075
if (_texture == nullptr || _texture->getRHITexture() == nullptr)
10731076
return;
10741077

axmol/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ option(AX_UPDATE_BUILD_VERSION "Update build version" ON)
191191
option(AX_DISABLE_GLES2 "Whether disable GLES2 support" OFF)
192192
option(AX_CORE_PROFILE "Whether strip deprecated features" ON)
193193

194+
set(AX_PROFILER_BACKEND "NONE" CACHE STRING "Profiling backend")
195+
set_property(CACHE AX_PROFILER_BACKEND PROPERTY STRINGS NONE TRACY)
196+
194197
# default value for axmol extensions modules to Build
195198
# total supported extensions count: 13
196199
# extensions dependicies: COCOSTUDIO may depend on spine & dragonBones if they are present in buildset
@@ -570,6 +573,10 @@ if(_simdc_defines)
570573
endif()
571574
endif()
572575

576+
# profiling configuration
577+
ax_apply_profiler_backend(${_AX_CORE_LIB} PUBLIC)
578+
message(STATUS "AX_PROFILER_BACKEND=${AX_PROFILER_BACKEND}")
579+
573580
# 3rd libs
574581
add_subdirectory(${_AX_ROOT}/3rdparty ${ENGINE_BINARY_PATH}/3rdparty)
575582
target_link_libraries(${_AX_CORE_LIB} 3rdparty)

axmol/audio/AudioEngineImpl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "axmol/base/Scheduler.h"
3333
#include "axmol/base/Utils.h"
3434
#include "axmol/base/WeakPtr.h"
35+
#include "axmol/base/Profiling.h"
3536

3637
#if AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_MAC
3738
# import <AVFoundation/AVFoundation.h>
@@ -1005,6 +1006,8 @@ void AudioEngineImpl::setFinishCallback(AudioId audioID, const std::function<voi
10051006

10061007
void AudioEngineImpl::update(float /*dt*/)
10071008
{
1009+
AX_PROFILER_ZONE_SCOPED;
1010+
10081011
std::lock_guard<std::recursive_mutex> lck(_threadMutex);
10091012
_updatePlayers(false);
10101013
}

axmol/base/Director.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ THE SOFTWARE.
5555
#include "axmol/base/FPSImages.h"
5656
#include "axmol/base/Scheduler.h"
5757
#include "axmol/base/Macros.h"
58+
#include "axmol/base/Profiling.h"
5859
#include "axmol/base/EventDispatcher.h"
5960
#include "axmol/base/CustomEvent.h"
6061
#include "axmol/base/Logging.h"
@@ -1372,6 +1373,8 @@ void Director::activate(SetIntervalReason reason)
13721373

13731374
_axmol_thread_id = std::this_thread::get_id();
13741375

1376+
AX_PROFILER_THREAD_NAME("MainThread");
1377+
13751378
Application::getInstance()->setAnimationInterval(_animationInterval);
13761379

13771380
// fix issue #3509, skip one fps to avoid incorrect time calculation.
@@ -1443,6 +1446,8 @@ void Director::renderFrame()
14431446
if (!_active) [[unlikely]]
14441447
return;
14451448

1449+
AX_PROFILER_ZONE_SCOPED;
1450+
14461451
const auto canRender = _renderer->beginFrame();
14471452

14481453
// calculate "global" dt
@@ -1534,6 +1539,8 @@ void Director::renderFrame()
15341539
}
15351540

15361541
_poolManager->getCurrentPool()->clear();
1542+
1543+
AX_PROFILER_FRAME_MARK;
15371544
}
15381545

15391546
void Director::renderFrame(float dt)

axmol/base/EventDispatcher.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "axmol/scene/Camera.h"
4848
#include "axmol/scene/Node.h"
4949
#include "axmol/2d/ProtectedNode.h"
50+
#include "axmol/base/Profiling.h"
5051

5152
#define DUMP_LISTENER_ITEM_PRIORITY_INFO 0
5253

@@ -946,6 +947,8 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners,
946947

947948
void EventDispatcher::dispatchEvent(Event* event, bool forced)
948949
{
950+
AX_PROFILER_ZONE_SCOPED;
951+
949952
if (!_isEnabled && !forced)
950953
return;
951954

0 commit comments

Comments
 (0)