Class QueryPerformanceTracker
- Namespace
- FishMMO.Database.Npgsql.Monitoring.Diagnostics
- Assembly
- FishMMO-DB.dll
Tracks query-level performance metrics for individual database operations. Thread-safe implementation with configurable tracking levels and overhead control. Complements DatabaseMetricsTracker with operation-specific insights.
public sealed class QueryPerformanceTracker : IDisposable
- Inheritance
-
QueryPerformanceTracker
- Implements
- Inherited Members
Constructors
QueryPerformanceTracker(QueryPerformanceConfiguration)
Initializes a new instance of QueryPerformanceTracker.
public QueryPerformanceTracker(QueryPerformanceConfiguration configuration = null)
Parameters
configurationQueryPerformanceConfigurationConfiguration for tracking behavior. If null, uses default configuration.
Properties
Configuration
Gets the configuration for this tracker.
public QueryPerformanceConfiguration Configuration { get; }
Property Value
IsEnabled
Gets or sets whether tracking is enabled. Can be toggled at runtime.
public bool IsEnabled { get; set; }
Property Value
Level
Gets or sets the current tracking level. Can be changed at runtime.
public TrackingLevel Level { get; set; }
Property Value
Methods
Clear()
Clears all tracked operations.
public void Clear()
Dispose()
Disposes the tracker and releases all resources. Clears all recorded metrics and disables tracking.
public void Dispose()
GetAllMetrics()
Gets all tracked operation metrics.
public IReadOnlyCollection<QueryMetrics> GetAllMetrics()
Returns
- IReadOnlyCollection<QueryMetrics>
Collection of all operation metrics.
GetMetrics(string)
Gets metrics for a specific operation. Updates last access time for LRU tracking.
public QueryMetrics? GetMetrics(string operationName)
Parameters
operationNamestringThe operation name.
Returns
- QueryMetrics
The metrics or null if not found.
GetMostSlowQueries(int)
Gets operations with the most slow query occurrences.
public IReadOnlyCollection<QueryMetrics> GetMostSlowQueries(int count)
Parameters
countintNumber of operations to return.
Returns
- IReadOnlyCollection<QueryMetrics>
Collection of operations with most slow queries.
GetSlowestOperations(int)
Gets the N slowest operations by average execution time.
public IReadOnlyCollection<QueryMetrics> GetSlowestOperations(int count)
Parameters
countintNumber of operations to return.
Returns
- IReadOnlyCollection<QueryMetrics>
Collection of slowest operations.
RecordQuery(string, TimeSpan, bool)
Records a query execution with automatic tracking level handling. Zero overhead when disabled or level is None.
public void RecordQuery(string operationName, TimeSpan duration, bool success)
Parameters
operationNamestringThe name of the database operation (e.g., "CharacterService.FetchAsync").
durationTimeSpanThe execution duration.
successboolWhether the execution succeeded.
ResetAll()
Resets all metrics.
public void ResetAll()
StartTracking()
Starts a stopwatch for tracking query execution time. Returns null if tracking is disabled to avoid overhead.
public Stopwatch? StartTracking()
Returns
- Stopwatch
A started Stopwatch or null if tracking is disabled.
Events
SlowQueryDetected
Event raised when a slow query is detected.
public event EventHandler<SlowQueryEventArgs> SlowQueryDetected