From 392fa62daefd2ee3de3a5ff700a7afd13f561922 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 24 Jul 2025 18:39:52 -0700 Subject: [PATCH] Profiler: Decouple profile stats from the profiler option This option is free and only enabled if the config option is set. Enable it always at build time so that users can pick it up without enabling the full gpuviz/tracy paths. --- FEXCore/include/FEXCore/Utils/Profiler.h | 58 +++++++++++------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/FEXCore/include/FEXCore/Utils/Profiler.h b/FEXCore/include/FEXCore/Utils/Profiler.h index 68514d5b1..1e51ae499 100644 --- a/FEXCore/include/FEXCore/Utils/Profiler.h +++ b/FEXCore/include/FEXCore/Utils/Profiler.h @@ -52,8 +52,6 @@ struct ThreadStats { uint64_t AccumulatedFloatFallbackCount; }; -#ifdef ENABLE_FEXCORE_PROFILER - #ifdef _M_ARM_64 /** * @brief Get the raw cycle counter with synchronizing isb. @@ -77,6 +75,11 @@ static inline uint64_t GetCycleCounter() { } #endif +#define UniqueScopeName2(name, line) name##line +#define UniqueScopeName(name, line) UniqueScopeName2(name, line) + +#ifdef ENABLE_FEXCORE_PROFILER + FEX_DEFAULT_VISIBILITY void Init(std::string_view ProgramName, std::string_view ProgramPath); FEX_DEFAULT_VISIBILITY void PostForkAction(bool IsChild); FEX_DEFAULT_VISIBILITY bool IsActive(); @@ -84,9 +87,6 @@ FEX_DEFAULT_VISIBILITY void Shutdown(); FEX_DEFAULT_VISIBILITY void TraceObject(const std::string_view Format); FEX_DEFAULT_VISIBILITY void TraceObject(const std::string_view Format, uint64_t Duration); -#define UniqueScopeName2(name, line) name##line -#define UniqueScopeName(name, line) UniqueScopeName2(name, line) - // Declare an instantaneous profiler event. #define FEXCORE_PROFILE_INSTANT(name) FEXCore::Profiler::TraceObject(name) @@ -110,6 +110,27 @@ private: #define FEXCORE_PROFILE_SCOPED(name) FEXCore::Profiler::ProfilerBlock UniqueScopeName(ScopedBlock_, __LINE__)(name) #endif +#else +[[maybe_unused]] +static void Init(std::string_view ProgramName, std::string_view ProgramPath) {} +[[maybe_unused]] +static void PostForkAction(bool IsChild) {} +[[maybe_unused]] +static void Shutdown() {} +[[maybe_unused]] +static void TraceObject(const std::string_view Format) {} +[[maybe_unused]] +static void TraceObject(const std::string_view, uint64_t) {} + +#define FEXCORE_PROFILE_INSTANT(...) \ + do { \ + } while (0) +#define FEXCORE_PROFILE_SCOPED(...) \ + do { \ + } while (0) + +#endif + template class AccumulationBlock final { public: @@ -139,31 +160,4 @@ private: ThreadState->ThreadStats->Stat += value; \ } \ } while (0) - -#else -[[maybe_unused]] -static void Init(std::string_view ProgramName, std::string_view ProgramPath) {} -[[maybe_unused]] -static void PostForkAction(bool IsChild) {} -[[maybe_unused]] -static void Shutdown() {} -[[maybe_unused]] -static void TraceObject(const std::string_view Format) {} -[[maybe_unused]] -static void TraceObject(const std::string_view, uint64_t) {} - -#define FEXCORE_PROFILE_INSTANT(...) \ - do { \ - } while (0) -#define FEXCORE_PROFILE_SCOPED(...) \ - do { \ - } while (0) -#define FEXCORE_PROFILE_ACCUMULATION(...) \ - do { \ - } while (0) -#define FEXCORE_PROFILE_INSTANT_INCREMENT(...) \ - do { \ - } while (0) - -#endif } // namespace FEXCore::Profiler