From cc88843db7083908a7bc2e70a0f02742a96c8e60 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Wed, 28 Jan 2026 19:24:09 +0100 Subject: [PATCH] core: set thread name for tracy (#4076) --- CMakeLists.txt | 1 + bazel/core.bzl | 1 + include/mbgl/util/instrumentation.hpp | 6 ++++++ include/mbgl/util/thread.hpp | 5 +++-- src/mbgl/util/instrumentation.cpp | 11 +++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/mbgl/util/instrumentation.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index be1225318..d99865e32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -917,6 +917,7 @@ list(APPEND SRC_FILES ${PROJECT_SOURCE_DIR}/src/mbgl/util/i18n.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/i18n.hpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/identity.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/util/instrumentation.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/interpolate.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/intersection_tests.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/util/intersection_tests.hpp diff --git a/bazel/core.bzl b/bazel/core.bzl index 75b3cedfa..6ff3334cd 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -549,6 +549,7 @@ MLN_CORE_SOURCE = [ "src/mbgl/util/i18n.cpp", "src/mbgl/util/i18n.hpp", "src/mbgl/util/identity.cpp", + "src/mbgl/util/instrumentation.cpp", "src/mbgl/util/interpolate.cpp", "src/mbgl/util/intersection_tests.cpp", "src/mbgl/util/intersection_tests.hpp", diff --git a/include/mbgl/util/instrumentation.hpp b/include/mbgl/util/instrumentation.hpp index e3882a31f..dfe1f198c 100644 --- a/include/mbgl/util/instrumentation.hpp +++ b/include/mbgl/util/instrumentation.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #ifdef MLN_TRACY_ENABLE #include @@ -128,3 +130,7 @@ constexpr const char* tracyConstMemoryLabel = "Constant Buffer Memory"; #define MLN_TRACE_ZONE(label) ((void)0) #endif // MLN_TRACY_ENABLE + +namespace mbgl::instrumentation { +void setThreadName(const std::string& name); +}; diff --git a/include/mbgl/util/thread.hpp b/include/mbgl/util/thread.hpp index a2a339bad..8e691dd95 100644 --- a/include/mbgl/util/thread.hpp +++ b/include/mbgl/util/thread.hpp @@ -7,12 +7,11 @@ #include #include #include +#include #include #include #include -#include -#include #include #include #include @@ -51,6 +50,8 @@ public: runningPromise = std::move(running_), prioritySetter = std::move(prioritySetter_)]() mutable { platform::setCurrentThreadName(name); + instrumentation::setThreadName(name); + if (prioritySetter) prioritySetter(); platform::attachThread(); diff --git a/src/mbgl/util/instrumentation.cpp b/src/mbgl/util/instrumentation.cpp new file mode 100644 index 000000000..3a360c7d6 --- /dev/null +++ b/src/mbgl/util/instrumentation.cpp @@ -0,0 +1,11 @@ +#include + +namespace mbgl::instrumentation { + +void setThreadName([[maybe_unused]] const std::string &name) { +#ifdef MLN_TRACY_ENABLE + tracy::SetThreadName(name.c_str()); +#endif +} + +}; // namespace mbgl::instrumentation