yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::PerformanceProfiler Class Reference

Unified performance profiler for all YAZE operations. More...

#include <performance_profiler.h>

Classes

struct  TimingStats
 Get timing statistics for an operation. More...
 

Public Member Functions

void StartTimer (const std::string &operation_name)
 Start timing an operation.
 
void EndTimer (const std::string &operation_name)
 End timing an operation.
 
TimingStats GetStats (const std::string &operation_name) const
 
std::string GenerateReport (bool log_to_sdl=true) const
 Generate a comprehensive performance report.
 
void Clear ()
 Clear all timing data.
 
void ClearOperation (const std::string &operation_name)
 Clear timing data for a specific operation.
 
std::vector< std::string > GetOperationNames () const
 Get list of all tracked operations.
 
bool IsTiming (const std::string &operation_name) const
 Check if an operation is currently being timed.
 
double GetAverageTime (const std::string &operation_name) const
 Get the average time for an operation in milliseconds.
 
double GetTotalTime (const std::string &operation_name) const
 Get the total time for an operation in milliseconds.
 
int GetOperationCount (const std::string &operation_name) const
 Get the number of times an operation was measured.
 
void PrintSummary () const
 Print a summary of all operations to console.
 

Static Public Member Functions

static PerformanceProfilerGet ()
 
static void SetEnabled (bool enabled)
 Enable or disable performance monitoring.
 
static bool IsEnabled ()
 Check if performance monitoring is enabled.
 
static bool IsValid ()
 Check if the profiler is in a valid state (not shutting down) This prevents crashes during static destruction order issues.
 

Private Types

using TimePoint = std::chrono::high_resolution_clock::time_point
 
using Duration = std::chrono::microseconds
 

Private Member Functions

 PerformanceProfiler ()
 

Static Private Member Functions

static double CalculateMedian (std::vector< double > values)
 Calculate median value from a sorted vector.
 

Private Attributes

std::unordered_map< std::string, TimePointactive_timers_
 
std::unordered_map< std::string, std::vector< double > > operation_times_
 
std::unordered_map< std::string, double > operation_totals_
 
std::unordered_map< std::string, int > operation_counts_
 
bool enabled_ = true
 
bool is_shutting_down_ = false
 

Detailed Description

Unified performance profiler for all YAZE operations.

The PerformanceProfiler class provides comprehensive timing and performance measurement capabilities for the entire YAZE application. It tracks operation times, calculates statistics, provides detailed performance reports, and integrates with the memory pool for efficient data storage.

Key Features:

  • High-resolution timing for microsecond precision
  • Automatic statistics calculation (min, max, average, median)
  • Operation grouping and categorization
  • Memory usage tracking with MemoryPool integration
  • Performance regression detection
  • Enable/disable functionality for zero-overhead when disabled
  • Unified interface for both core and graphics operations

Performance Optimizations:

  • Memory pool allocation for reduced fragmentation
  • Minimal overhead timing measurements
  • Efficient data structures for fast lookups
  • Configurable sampling rates
  • Automatic cleanup of old measurements

Usage Examples:

  • Measure ROM loading performance
  • Track graphics operation efficiency
  • Monitor memory usage patterns
  • Detect performance regressions

Definition at line 44 of file performance_profiler.h.

Member Typedef Documentation

◆ TimePoint

using yaze::gfx::PerformanceProfiler::TimePoint = std::chrono::high_resolution_clock::time_point
private

Definition at line 163 of file performance_profiler.h.

◆ Duration

using yaze::gfx::PerformanceProfiler::Duration = std::chrono::microseconds
private

Definition at line 164 of file performance_profiler.h.

Constructor & Destructor Documentation

◆ PerformanceProfiler()

yaze::gfx::PerformanceProfiler::PerformanceProfiler ( )
private

Definition at line 20 of file performance_profiler.cc.

References active_timers_, Get(), is_shutting_down_, operation_counts_, operation_times_, and operation_totals_.

Here is the call graph for this function:

Member Function Documentation

◆ Get()

◆ SetEnabled()

static void yaze::gfx::PerformanceProfiler::SetEnabled ( bool  enabled)
inlinestatic

Enable or disable performance monitoring.

When disabled, ScopedTimer operations become no-ops for better performance in production builds or when monitoring is not needed.

Definition at line 54 of file performance_profiler.h.

References enabled_, and Get().

Referenced by yaze::gfx::PerformanceDashboard::RenderRecommendations().

Here is the call graph for this function:

◆ IsEnabled()

static bool yaze::gfx::PerformanceProfiler::IsEnabled ( )
inlinestatic

Check if performance monitoring is enabled.

Definition at line 61 of file performance_profiler.h.

References enabled_, and Get().

Referenced by yaze::gfx::PerformanceDashboard::RenderRecommendations(), yaze::gfx::ScopedTimer::ScopedTimer(), and yaze::gfx::ScopedTimer::~ScopedTimer().

Here is the call graph for this function:

◆ IsValid()

static bool yaze::gfx::PerformanceProfiler::IsValid ( )
inlinestatic

Check if the profiler is in a valid state (not shutting down) This prevents crashes during static destruction order issues.

Definition at line 69 of file performance_profiler.h.

References Get(), and is_shutting_down_.

Referenced by yaze::gfx::ScopedTimer::ScopedTimer(), and yaze::gfx::ScopedTimer::~ScopedTimer().

Here is the call graph for this function:

◆ StartTimer()

void yaze::gfx::PerformanceProfiler::StartTimer ( const std::string &  operation_name)

Start timing an operation.

Parameters
operation_nameName of the operation to time
Note
Multiple operations can be timed simultaneously

Definition at line 34 of file performance_profiler.cc.

References active_timers_, enabled_, and is_shutting_down_.

Referenced by yaze::gfx::ScopedTimer::ScopedTimer().

◆ EndTimer()

void yaze::gfx::PerformanceProfiler::EndTimer ( const std::string &  operation_name)

End timing an operation.

Parameters
operation_nameName of the operation to end timing
Note
Must match a previously started timer

Definition at line 40 of file performance_profiler.cc.

References active_timers_, enabled_, is_shutting_down_, operation_counts_, operation_times_, and operation_totals_.

Referenced by yaze::gfx::ScopedTimer::~ScopedTimer().

◆ GetStats()

◆ GenerateReport()

std::string yaze::gfx::PerformanceProfiler::GenerateReport ( bool  log_to_sdl = true) const

Generate a comprehensive performance report.

Parameters
log_to_sdlWhether to log results to SDL_Log
Returns
Formatted performance report string

Definition at line 95 of file performance_profiler.cc.

References enabled_, yaze::gfx::MemoryPool::Get(), yaze::gfx::MemoryPool::GetMemoryStats(), GetStats(), and operation_times_.

Referenced by yaze::gfx::PerformanceDashboard::RenderRecommendations().

Here is the call graph for this function:

◆ Clear()

◆ ClearOperation()

void yaze::gfx::PerformanceProfiler::ClearOperation ( const std::string &  operation_name)

Clear timing data for a specific operation.

Parameters
operation_nameName of the operation to clear

Definition at line 186 of file performance_profiler.cc.

References active_timers_, operation_counts_, operation_times_, and operation_totals_.

◆ GetOperationNames()

std::vector< std::string > yaze::gfx::PerformanceProfiler::GetOperationNames ( ) const

Get list of all tracked operations.

Returns
Vector of operation names

Definition at line 193 of file performance_profiler.cc.

References operation_times_.

◆ IsTiming()

bool yaze::gfx::PerformanceProfiler::IsTiming ( const std::string &  operation_name) const

Check if an operation is currently being timed.

Parameters
operation_nameName of the operation to check
Returns
True if operation is being timed

Definition at line 202 of file performance_profiler.cc.

References active_timers_.

◆ GetAverageTime()

double yaze::gfx::PerformanceProfiler::GetAverageTime ( const std::string &  operation_name) const

Get the average time for an operation in milliseconds.

Parameters
operation_nameName of the operation
Returns
Average time in milliseconds

Definition at line 206 of file performance_profiler.cc.

References operation_counts_, and operation_totals_.

◆ GetTotalTime()

double yaze::gfx::PerformanceProfiler::GetTotalTime ( const std::string &  operation_name) const

Get the total time for an operation in milliseconds.

Parameters
operation_nameName of the operation
Returns
Total time in milliseconds

Definition at line 218 of file performance_profiler.cc.

References operation_totals_.

◆ GetOperationCount()

int yaze::gfx::PerformanceProfiler::GetOperationCount ( const std::string &  operation_name) const

Get the number of times an operation was measured.

Parameters
operation_nameName of the operation
Returns
Number of measurements

Definition at line 223 of file performance_profiler.cc.

References operation_counts_.

◆ PrintSummary()

void yaze::gfx::PerformanceProfiler::PrintSummary ( ) const

Print a summary of all operations to console.

Definition at line 228 of file performance_profiler.cc.

References operation_counts_, operation_times_, and operation_totals_.

Referenced by yaze::editor::EditorManager::LoadAssets().

◆ CalculateMedian()

double yaze::gfx::PerformanceProfiler::CalculateMedian ( std::vector< double >  values)
staticprivate

Calculate median value from a sorted vector.

Parameters
valuesSorted vector of values
Returns
Median value

Definition at line 257 of file performance_profiler.cc.

Referenced by GetStats().

Member Data Documentation

◆ active_timers_

std::unordered_map<std::string, TimePoint> yaze::gfx::PerformanceProfiler::active_timers_
private

◆ operation_times_

std::unordered_map<std::string, std::vector<double> > yaze::gfx::PerformanceProfiler::operation_times_
private

◆ operation_totals_

std::unordered_map<std::string, double> yaze::gfx::PerformanceProfiler::operation_totals_
private

◆ operation_counts_

std::unordered_map<std::string, int> yaze::gfx::PerformanceProfiler::operation_counts_
private

◆ enabled_

bool yaze::gfx::PerformanceProfiler::enabled_ = true
private

Definition at line 171 of file performance_profiler.h.

Referenced by EndTimer(), GenerateReport(), IsEnabled(), SetEnabled(), and StartTimer().

◆ is_shutting_down_

bool yaze::gfx::PerformanceProfiler::is_shutting_down_ = false
private

Definition at line 172 of file performance_profiler.h.

Referenced by EndTimer(), IsValid(), PerformanceProfiler(), and StartTimer().


The documentation for this class was generated from the following files: