Generates summary of time consumed by database queries. Helpful to pinpoint where to focus optimization efforts.
- Add and initialize active_record_query_trace gem.
- Add
gem 'query-trace-summary', group: :developmentto your Gemfile - Remove previous logs
- Run the problematic code
- Pipe summary
rake query_trace_summary:csv <log-file>...into a file - Open the file with your favorite spreadsheet program
- Optimize away
Brief summary of top 10 most time intensive queries can also be generated with
rake query_trace_summary:top10 command
If you're using Rails >= 5.2, ActiveRecord::Base.verbose_query_logs = true
setting is sufficient to gather query statistics.
The active-record-query-trace gem can still be helpful when figuring out
what is causing the queries.
It assumes project file names do not contain spaces or any special characters.
Rake tasks cannot be chained
Released under the MIT License.