feat: Enhance PerformanceProfiler to handle shutdown state and prevent crashes during destruction

This commit is contained in:
scawful
2025-10-01 19:50:44 -04:00
parent 0b62bcbda0
commit 12dc71c444
4 changed files with 45 additions and 21 deletions

View File

@@ -62,6 +62,14 @@ class PerformanceProfiler {
return Get().enabled_;
}
/**
* @brief Check if the profiler is in a valid state (not shutting down)
* This prevents crashes during static destruction order issues
*/
static bool IsValid() {
return !Get().is_shutting_down_;
}
/**
* @brief Start timing an operation
* @param operation_name Name of the operation to time
@@ -161,6 +169,7 @@ class PerformanceProfiler {
std::unordered_map<std::string, int> operation_counts_; // Count per operation
bool enabled_ = true; // Performance monitoring enabled by default
bool is_shutting_down_ = false; // Flag to prevent operations during destruction
/**
* @brief Calculate median value from a sorted vector