module
CQL::Performance
Overview
Example usage:
# Quick setup
CQL::Performance.enable_development_mode!
# Or custom configuration
CQL::Performance.configure do |config|
config.monitoring.enabled = true
config.profiling.slow_query_threshold = 50.milliseconds
config.detection.threshold = 3
config.logging.colorize = true
end
# Every query execution is monitored once monitoring is enabled
users = AcmeDB.query.from(:users).where(active: true).all(User)
# Track with context for better insights
CQL::Performance.with_context("UserController#index") do
users = AcmeDB.query.from(:users)
.where(active: true)
.order(created_at: :desc)
.limit(20)
.all(User)
end
# Manual tracking for SQL that CQL does not run itself
name = CQL::Performance.track("SELECT name FROM users WHERE id = ?", [1] of DB::Any) do
AcmeDB.with_connection { |connection| connection.query_one("SELECT name FROM users WHERE id = ?", 1, as: String) }
end
# Generate performance report
puts CQL::Performance.report("console")
Defined in:
performance.crperformance/config.cr
performance/interfaces.cr
performance/monitor.cr
performance/n_plus_one_detector.cr
performance/performance_metrics.cr
performance/query_profiler.cr
performance/sql_formatter.cr
performance/unified_report_generator.cr
performance/utilities.cr
Class Method Summary
- .configure(&)
- .create_detector(config : Config::Detection = Config::Detection.new)
-
.create_profiler(config : Config::Profiling = Config::Profiling.new)
Make concrete implementations available as shortcuts
- .critical_issues : Array(Issue)
-
.development_config : Config
Export config presets for easy use
- .disable!
- .disable_sql_logging
-
.enable_development_mode!
Quick setup methods
-
.enable_monitoring
Monitoring is opt-in; this turns on the global monitor.
- .enable_production_mode!
-
.enable_sql_logging(colorize : Bool = true, pretty : Bool = true)
SQL logging convenience.
- .end_relation_loading
- .export_metrics_as_json : String
-
.flush(timeout : Time::Span | Nil = nil) : Bool
Waits until the monitor has recorded every statement handed to it; false on timeout.
- .healthy? : Bool
- .high_priority_issues : Array(Issue)
- .is_healthy? : Bool
-
.metrics : PerformanceMetrics
Performance Metrics convenience methods
- .metrics_summary : Hash(String, String | Int64 | Float64)
- .minimal_config : Config
- .monitor : Monitor
-
.monitor=(monitor : Monitor)
Replacing the global monitor closes the old one, whose later statements are recorded inline.
- .production_config : Config
- .report(format : String | Nil = nil) : String
- .sql_formatter : SQLFormatter
- .sql_formatter=(formatter : SQLFormatter)
- .start_relation_loading(relation : String, model : String)
- .test_config : Config
-
.track(sql : String, params : Array(DB::Any) = [] of DB::Any, &)
Convenience methods
- .with_context(context : String, &)
Class Method Detail
Make concrete implementations available as shortcuts
SQL logging convenience. SQL is logged by the monitor, so this enables monitoring too.
Waits until the monitor has recorded every statement handed to it; false on timeout. Pass a timeout at shutdown.
Replacing the global monitor closes the old one, whose later statements are recorded inline.
Convenience methods