Skip to content

Instantly share code, notes, and snippets.

@scottjg
Created April 5, 2013 20:11
Show Gist options
  • Save scottjg/5322250 to your computer and use it in GitHub Desktop.
Save scottjg/5322250 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'date'
require 'pp'
after = DateTime.parse(ARGV[0])
before = DateTime.parse(ARGV[1])
puts after
puts before
action = nil
table = { }
STDIN.each_line do |line|
#Processing BlobController#raw (for 66.8.1.78 at 2013-04-05 06:27:02) [GET]
if line =~ /^Processing /
e = line.split(/ /)
action = e[1]
if e[2] == 'to'
date = e[7]
time = e[8].tr(')', '')
else
date = e[5]
time = e[6].tr(')', '')
end
begin
dt = DateTime.parse("#{date} #{time}")
rescue
puts "skipped weird line: #{line}"
action = nil
next
end
#puts dt
if after > dt
action = nil
next
elsif before < dt
break
end
elsif action != nil
#Completed in 16ms
if line =~ /^Completed in (\d+)ms/
ms = $1.to_i
puts "#{action} #{dt} #{ms}"
entry = table[action]
if entry.nil?
table[action] = {
:hits => 1,
:time => ms,
:avg_time => ms,
}
else
entry[:hits] = entry[:hits] + 1
entry[:time] = entry[:time] + ms
entry[:avg_time] = entry[:time] / entry[:hits]
end
end
end
end
puts "finalizing.."
table.map { |action, data| [action, data] }.sort { |i,j| i[1][:time] <=> j[1][:time] }.reverse.each { |i| puts i }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment