This is something I just stumbled upon. And here's what I did to it.
Rails’ ActiveRecord logger writes log files like:
Post Load (735.8ms) SELECT
postswhere post.title = 'rkship'
You may want to know the longest SQL queries for performance optimsation purposes, and general troubleshooting(my case). To list recent queries in order of duration, with longest queries shown last, I used this:
head -10000 development.log | grep '([0-9.]+ms)' | sed 's/.(([[:digit:].]+)ms./\1ms &/g' | sort -n
(The sed expression was a little more work than I’d bargained for as sed regular expressions are always lazy; even with GNU/Posix extensions, non-lazy just doesn’t exist.)