Merge pull request #104851 from Ivorforce/tracy

Add `profiler` option to `SCons` builds, with support for `tracy` and `perfetto`.
This commit is contained in:
Thaddeus Crews 2025-11-12 11:24:15 -06:00
commit 04bc282ae7
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
25 changed files with 375 additions and 1 deletions

View file

@ -49,6 +49,7 @@
#include "core/config/project_settings.h"
#include "core/input/input.h"
#include "core/os/main_loop.h"
#include "core/profiling/profiling.h"
#include "main/main.h"
#include "servers/rendering/rendering_server.h"
@ -151,6 +152,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHei
}
JNIEXPORT jboolean JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject p_godot_instance, jobject p_asset_manager, jobject p_godot_io, jobject p_net_utils, jobject p_directory_access_handler, jobject p_file_access_handler, jboolean p_use_apk_expansion) {
godot_init_profiler();
JavaVM *jvm;
env->GetJavaVM(&jvm);

View file

@ -42,6 +42,7 @@
#include "core/extension/gdextension_manager.h"
#include "core/io/xml_parser.h"
#include "core/os/main_loop.h"
#include "core/profiling/profiling.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#ifdef TOOLS_ENABLED
@ -364,6 +365,8 @@ void OS_Android::main_loop_begin() {
}
bool OS_Android::main_loop_iterate(bool *r_should_swap_buffers) {
GodotProfileFrameMark;
GodotProfileZone("OS_Android::main_loop_iterate");
if (!main_loop) {
return false;
}

View file

@ -30,6 +30,7 @@
#import "os_ios.h"
#include "core/profiling/profiling.h"
#import "drivers/apple_embedded/godot_app_delegate.h"
#import "drivers/apple_embedded/main_utilities.h"
#include "main/main.h"
@ -55,6 +56,8 @@ int apple_embedded_main(int argc, char **argv) {
char *fargv[64];
argc = process_args(argc, argv, fargv);
godot_init_profiler();
Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false);
if (err != OK) {

View file

@ -30,6 +30,7 @@
#include "os_linuxbsd.h"
#include "core/profiling/profiling.h"
#include "main/main.h"
#include <unistd.h>
@ -93,6 +94,8 @@ int main(int argc, char *argv[]) {
setrlimit(RLIMIT_STACK, &stack_lim);
#endif
godot_init_profiler();
OS_LinuxBSD os;
setlocale(LC_CTYPE, "");

View file

@ -37,6 +37,7 @@
#ifdef SDL_ENABLED
#include "drivers/sdl/joypad_sdl.h"
#endif
#include "core/profiling/profiling.h"
#include "main/main.h"
#include "servers/display/display_server.h"
#include "servers/rendering/rendering_server.h"
@ -970,6 +971,8 @@ String OS_LinuxBSD::get_system_dir(SystemDir p_dir, bool p_shared_storage) const
}
void OS_LinuxBSD::run() {
GodotProfileFrameMark;
GodotProfileZone("OS_LinuxBSD::run");
if (!main_loop) {
return;
}

View file

@ -34,6 +34,7 @@
#import "godot_window.h"
#import "key_mapping_macos.h"
#include "core/profiling/profiling.h"
#include "main/main.h"
@implementation GodotContentLayerDelegate
@ -56,6 +57,9 @@
- (void)displayLayer:(CALayer *)layer {
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
if (OS::get_singleton()->get_main_loop() && ds->get_is_resizing() && need_redraw) {
GodotProfileFrameMark;
GodotProfileZone("[GodotContentLayerDelegate displayLayer]");
Main::force_redraw();
if (!Main::is_iterating()) { // Avoid cyclic loop.
Main::iteration();

View file

@ -32,6 +32,7 @@
#import "godot_application.h"
#include "core/profiling/profiling.h"
#include "main/main.h"
#if defined(SANITIZERS_ENABLED)
@ -39,6 +40,8 @@
#endif
int main(int argc, char **argv) {
godot_init_profiler();
#if defined(VULKAN_ENABLED)
setenv("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE", "1", 1); // MoltenVK - enable full component swizzling support.
setenv("MVK_CONFIG_SWAPCHAIN_MIN_MAG_FILTER_USE_NEAREST", "0", 1); // MoltenVK - use linear surface scaling. TODO: remove when full DPI scaling is implemented.

View file

@ -41,6 +41,7 @@
#include "core/crypto/crypto_core.h"
#include "core/io/file_access.h"
#include "core/os/main_loop.h"
#include "core/profiling/profiling.h"
#include "core/version_generated.gen.h"
#include "drivers/apple/os_log_logger.h"
#include "main/main.h"
@ -1080,6 +1081,8 @@ static void handle_interrupt(int sig) {
}
void OS_MacOS_NSApp::start_main() {
godot_init_profiler();
Error err;
@autoreleasepool {
err = Main::setup(execpath, argc, argv);
@ -1103,6 +1106,9 @@ void OS_MacOS_NSApp::start_main() {
pre_wait_observer = CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
@autoreleasepool {
@try {
GodotProfileFrameMark;
GodotProfileZone("macOS main loop");
if (ds_mac) {
ds_mac->_process_events(false);
} else if (ds) {
@ -1276,6 +1282,9 @@ void OS_MacOS_Embedded::run() {
while (true) {
@autoreleasepool {
@try {
GodotProfileFrameMark;
GodotProfileZone("macOS embedded main loop");
ds->process_events();
#ifdef SDL_ENABLED

View file

@ -30,6 +30,7 @@
#import "os_visionos.h"
#include "core/profiling/profiling.h"
#import "drivers/apple_embedded/godot_app_delegate.h"
#import "drivers/apple_embedded/main_utilities.h"
#include "main/main.h"
@ -50,6 +51,8 @@ int apple_embedded_main(int argc, char **argv) {
char *fargv[64];
argc = process_args(argc, argv, fargv);
godot_init_profiler();
Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false);
if (err != OK) {

View file

@ -40,6 +40,7 @@
#include "core/debugger/engine_debugger.h"
#include "core/io/file_access.h"
#include "core/os/main_loop.h"
#include "core/profiling/profiling.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
@ -79,6 +80,8 @@ void OS_Web::fs_sync_callback() {
}
bool OS_Web::main_loop_iterate() {
GodotProfileFrameMark;
GodotProfileZone("OS_Web::main_loop_iterate");
if (is_userfs_persistent() && idb_needs_sync && !idb_is_syncing) {
idb_is_syncing = true;
idb_needs_sync = false;

View file

@ -35,6 +35,7 @@
#include "core/config/engine.h"
#include "core/io/file_access.h"
#include "core/io/resource_loader.h"
#include "core/profiling/profiling.h"
#include "main/main.h"
#include "scene/main/scene_tree.h"
#include "scene/main/window.h" // SceneTree only forward declares it.
@ -126,6 +127,8 @@ void print_web_header() {
/// When calling main, it is assumed FS is setup and synced.
extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
godot_init_profiler();
os = new OS_Web();
#ifdef TOOLS_ENABLED

View file

@ -30,6 +30,7 @@
#include "os_windows.h"
#include "core/profiling/profiling.h"
#include "main/main.h"
#include <clocale>
@ -66,6 +67,8 @@ char *wc_to_utf8(const wchar_t *wc) {
}
int widechar_main(int argc, wchar_t **argv) {
godot_init_profiler();
OS_Windows os(nullptr);
setlocale(LC_CTYPE, "");

View file

@ -39,6 +39,7 @@
#include "core/debugger/script_debugger.h"
#include "core/io/marshalls.h"
#include "core/os/main_loop.h"
#include "core/profiling/profiling.h"
#include "core/version_generated.gen.h"
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
@ -2329,6 +2330,8 @@ void OS_Windows::run() {
main_loop->initialize();
while (true) {
GodotProfileFrameMark;
GodotProfileZone("OS_Windows::run");
DisplayServer::get_singleton()->process_events(); // get rid of pending events
if (Main::iteration()) {
break;