diff --git a/src/app/core/features.h b/src/app/core/features.h index 263ce672..9dcb6b9b 100644 --- a/src/app/core/features.h +++ b/src/app/core/features.h @@ -38,6 +38,9 @@ class FeatureFlags { // Log to the console. bool kLogToConsole = false; + // Enable performance monitoring and timing. + bool kEnablePerformanceMonitoring = true; + // Use NFD (Native File Dialog) instead of bespoke file dialog implementation. #if defined(YAZE_ENABLE_NFD) && YAZE_ENABLE_NFD bool kUseNativeFileDialog = true; @@ -164,6 +167,7 @@ struct FlagsMenu { void DrawSystemFlags() { Checkbox("Enable Console Logging", &FeatureFlags::get().kLogToConsole); + Checkbox("Enable Performance Monitoring", &FeatureFlags::get().kEnablePerformanceMonitoring); Checkbox("Log Instructions to Emulator Debugger", &FeatureFlags::get().kLogInstructions); Checkbox("Use Native File Dialog (NFD)", &FeatureFlags::get().kUseNativeFileDialog); diff --git a/src/app/core/performance_monitor.cc b/src/app/core/performance_monitor.cc index b8ecb06a..bd24f178 100644 --- a/src/app/core/performance_monitor.cc +++ b/src/app/core/performance_monitor.cc @@ -3,6 +3,8 @@ #include #include +#include "app/core/features.h" + namespace yaze { namespace core { @@ -85,12 +87,16 @@ void PerformanceMonitor::PrintSummary() const { } ScopedTimer::ScopedTimer(const std::string& operation_name) - : operation_name_(operation_name) { - PerformanceMonitor::Get().StartTimer(operation_name_); + : operation_name_(operation_name), enabled_(core::FeatureFlags::get().kEnablePerformanceMonitoring) { + if (enabled_) { + PerformanceMonitor::Get().StartTimer(operation_name_); + } } ScopedTimer::~ScopedTimer() { - PerformanceMonitor::Get().EndTimer(operation_name_); + if (enabled_) { + PerformanceMonitor::Get().EndTimer(operation_name_); + } } } // namespace core diff --git a/src/app/core/performance_monitor.h b/src/app/core/performance_monitor.h index 0e61c24f..ca3d3cdd 100644 --- a/src/app/core/performance_monitor.h +++ b/src/app/core/performance_monitor.h @@ -22,6 +22,23 @@ class PerformanceMonitor { static PerformanceMonitor instance; return instance; } + + /** + * @brief Enable or disable performance monitoring + * + * When disabled, ScopedTimer operations become no-ops for better performance + * in production builds or when monitoring is not needed. + */ + static void SetEnabled(bool enabled) { + Get().enabled_ = enabled; + } + + /** + * @brief Check if performance monitoring is enabled + */ + static bool IsEnabled() { + return Get().enabled_; + } /** * @brief Start timing an operation @@ -72,6 +89,7 @@ class PerformanceMonitor { }; std::unordered_map operations_; + bool enabled_ = true; // Performance monitoring enabled by default }; /** @@ -91,6 +109,7 @@ class ScopedTimer { private: std::string operation_name_; + bool enabled_; }; } // namespace core