Created
May 17, 2012 03:43
-
-
Save happyrobots/2716082 to your computer and use it in GitHub Desktop.
Stuff from HAR
This file contains 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
#!/usr/bin/env ruby | |
require 'json' | |
def group_time_by_hosts(raw) | |
result = {} | |
raw["log"]["entries"].each do |entry| | |
url = entry["request"]["url"] | |
addr = url.split('/')[2] | |
addr = addr.split('.')[-2..-1] if addr | |
host = addr ? addr.join('.') : url | |
result[host] ||= {} | |
result[host]["call_count"] ||= 0 | |
result[host]["call_count"] += 1 | |
result[host]["total_time"] ||= 0 | |
result[host]["total_time"] += entry["time"].to_i | |
end | |
result | |
end | |
def group_time_by_hosts_and_response_types(raw) | |
result = {} | |
raw["log"]["entries"].each do |entry| | |
url = entry["request"]["url"] | |
addr = url.split('/')[2] | |
addr = addr.split('.')[-2..-1] if addr | |
host = addr ? addr.join('.') : url | |
mime_type = entry["response"]["content"]["mimeType"] | |
key = [mime_type, host].join("\t") | |
result[key] ||= {} | |
result[key]["call_count"] ||= 0 | |
result[key]["call_count"] += 1 | |
result[key]["total_time"] ||= 0 | |
result[key]["total_time"] += entry["time"].to_i | |
end | |
result | |
end | |
ARGV.each do |filename| | |
puts filename | |
puts '====================' | |
3.times { puts } | |
puts %w{Host TotalTime CallCount}.join("\t") | |
result = group_time_by_hosts JSON.parse(File.read(filename)) | |
result.sort_by { |host, time| -time["total_time"] }.each do |host, time| | |
puts([host, | |
(time["total_time"]/1000.0), | |
time["call_count"]].join("\t")) | |
end | |
3.times { puts } | |
puts %w{ContentType Host TotalTime CallCount}.join("\t") | |
result = group_time_by_hosts_and_response_types JSON.parse(File.read(filename)) | |
result.sort_by { |host, time| -time["total_time"] }.each do |host, time| | |
puts([host, | |
(time["total_time"]/1000.0), | |
time["call_count"]].join("\t")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment