Created
May 16, 2012 16:10
-
-
Save ferblape/2711712 to your computer and use it in GitHub Desktop.
Filter slow queries from Rails log file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# cat <environment>.log | grep Load | grep SELECT | ruby filter.rb | |
MAX_TIME = 30.0 | |
h = {} | |
STDIN.read.split("\n").each do |line| | |
list = line.split(' ') | |
time = list[2].match(/\d+\.\d+/)[0].to_f | |
query = ([list[3],"SQL_NO_CACHE"] + list[4..-1]).join(" ") + ';' | |
h[query] = time | |
end | |
h.sort_by{ |query, time| time }.reverse.select{ |query, time| time > MAX_TIME }.each do |query, time| | |
puts "#{time} - #{query}" | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment