Add performance monitoring feature toggle and integration

- Introduced a new feature flag for performance monitoring in the FeatureFlags class, allowing users to enable or disable monitoring.
- Updated the ScopedTimer class to respect the performance monitoring flag, ensuring that timing operations are no-ops when monitoring is disabled.
- Enhanced the PerformanceMonitor class with methods to set and check the enabled state of performance monitoring, improving flexibility for production builds.
This commit is contained in:
scawful
2025-09-28 22:42:19 -04:00
parent b911256687
commit b82751f9ea
3 changed files with 32 additions and 3 deletions

View File

@@ -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);

View File

@@ -3,6 +3,8 @@
#include <iostream>
#include <iomanip>
#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

View File

@@ -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<std::string, OperationData> operations_;
bool enabled_ = true; // Performance monitoring enabled by default
};
/**
@@ -91,6 +109,7 @@ class ScopedTimer {
private:
std::string operation_name_;
bool enabled_;
};
} // namespace core