class CQL::Performance::QueryProfiler

Overview

Query profiler without event system

Included Modules

Defined in:

performance/query_profiler.cr

Constant Summary

MAX_SLOW_QUERIES = 1000
OTHER_STATEMENTS = "(other)"

Constructors

Instance Method Summary

Instance methods inherited from module CQL::Performance::QueryProfilerInterface

clear : Void clear, issues : Array(Issue) issues, latency_percentiles : LatencyPercentiles latency_percentiles, record_query(sql : String, params : Array(DB::Any), execution_time : Time::Span, rows_affected : Int64 | Nil = nil, error : String | Nil = nil, normalized_sql : String | Nil = nil) : Void record_query, slowest_queries(limit : Int32) : Array(QueryData) slowest_queries, statistics statistics, stats_trackers : Hash(String, StatsTracker) stats_trackers

Instance methods inherited from class CQL::Performance::BasePerformanceComponent

enabled=(enabled : Bool) enabled=, enabled? : Bool enabled?, healthy? : Bool healthy?, reset reset, stats : StatsTracker stats

Instance methods inherited from module CQL::Performance::TimingUtils

categorize_duration(duration : Time::Span, slow_threshold : Time::Span = 100.milliseconds, very_slow_threshold : Time::Span = 1.second) : Symbol categorize_duration, format_duration(duration : Time::Span) : String format_duration, measure_execution(&) measure_execution

Constructor Detail

def self.new(config : Config::Profiling = Config::Profiling.new) #

[View source]

Instance Method Detail

def clear : Void #

Clear all data


[View source]
def issues : Array(Issue) #

Get performance issues


[View source]
def latency_percentiles : LatencyPercentiles #

Latency percentiles over every recorded statement


[View source]
def record_query(sql : String, params : Array(DB::Any), execution_time : Time::Span, rows_affected : Int64 | Nil = nil, error : String | Nil = nil, normalized_sql : String | Nil = nil) : Void #

Direct method call instead of event handling


[View source]
def slowest_queries(limit : Int32 = 10) : Array(QueryData) #

Slowest first. The sort is cached until a slow query is added, and runs outside the lock, so #record_query waits only for a copy.


[View source]
def statistics : Hash(String, NamedTuple(count: Int32, total_ms: Float64, avg_ms: Float64, min_ms: Float64, max_ms: Float64)) #

Get query statistics


[View source]
def stats_trackers : Hash(String, StatsTracker) #

Get stats trackers for report generation


[View source]