NAME

DBIx::Fast::Profiler - Query profiling and statistics for DBIx::Fast

DESCRIPTION

Records and analyzes SQL query execution times, providing detailed statistics, slow query detection, and colored terminal output. Queries are stored in a circular buffer controlled by max_queries.

METHODS

add_query

$profiler->add_query($sql, \@params, $start_time, $end_time);

Records a query execution with its SQL, bind parameters, and timing. Automatically prints the query if auto_print is enabled.

$profiler->print_query(\%query_info);

Prints a single query's details to STDOUT with color-coded duration (green, yellow, or red). Includes a stack trace for slow queries.

Prints a summary of query statistics grouped by query type (SELECT, INSERT, etc.) with count, total time, average, min, and max for each type.

Prints comprehensive query statistics including totals, averages, slow query percentage, queries per second, and a per-type breakdown.

get_stats

my $stats = $profiler->get_stats();

Returns a hashref with aggregate statistics: total_queries, total_time, avg_time, min_time, max_time, slow_queries, slow_query_percentage, queries_per_second, and query_types breakdown.

get_detailed_stats

my $stats = $profiler->get_detailed_stats();

Returns a hashref keyed by query type with count, total_time, avg_time, min_time, and max_time for each type.

get_slow_queries

my $slow = $profiler->get_slow_queries($limit);

Returns an arrayref of the top $limit (default 10) slowest queries, sorted by duration descending.

clear

Clears all recorded queries from the profiler buffer.

AUTHOR

Harun Delgado

LICENSE

This is free software under the Artistic License 2.0.