Created
October 18, 2011 19:22
-
-
Save oogali/1296414 to your computer and use it in GitHub Desktop.
parse HAR files quickly
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 'rubygems' | |
require 'addressable/uri' | |
require 'json' | |
require 'yaml' | |
if ARGV.length != 1 | |
puts "#{__FILE__} /path/to/archive.har" | |
exit 1 | |
end | |
archive = nil | |
begin | |
archive = JSON.parse File.read(ARGV.shift) | |
rescue => err | |
puts "could not pase archive file: #{err.to_s}" | |
exit 1 | |
end | |
entries = archive['log']['entries'] | |
## get hosts from archive | |
hosts = entries.map do |entry| | |
Addressable::URI.parse(entry['request']['url']).host | |
end | |
## loop through each host, pulling out respective urls | |
output = hosts.uniq.map do |host| | |
urls = entries.map do |entry| | |
## build a hash of url->timing info | |
if entry['request']['url'].match("http://#{host}/") | |
{ | |
entry['request']['url'] => entry['timings'] | |
} | |
end | |
end | |
## toss out null entries | |
urls.reject! { |url| url.nil? } | |
## build a resulting hash of host->array of urls | |
{ host => urls } | |
end | |
puts output.to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oo, you crazy.