#!/usr/bin/env ruby -w # argv: logfile, [only tops] # Collects all the URIs mentioned in the JS stacks, computes how many times # each appears, and ranks them. If the only-tops arg is present, this only # looks at the top of each stack. filename = ARGV.shift onlyTops = ARGV.shift uris = {} open(filename, 'r') do |file| file.each do |line| next if onlyTops && /^0/ !~ line # e.g., ["chrome://browser/content/tabbrowser.xml":2445] match = /\["(.+?)"/.match(line) if match uri = match[1] uris[uri] ||= 0 uris[uri] += 1 end end end uris = uris.to_a.sort_by { |uri, cnt| -cnt } maxCntLen = uris[0][1].to_s.size uris.each { |uri, cnt| puts "%*d %s" % [maxCntLen, cnt, uri] }