#!/usr/bin/env ruby -w # argv: logfile # Like file-offenders.rb, but collects function-filename pairs instead of # filenames. filename = ARGV.shift onlyTops = ARGV.shift funcs = {} open(filename, 'r') do |file| file.each("\n\n") do |para| paraFuncs = para.split("\n").inject([]) do |memo, line| next memo if onlyTops && /^0/ !~ line match = /^[0-9]+ ([^(\[]+)/.match(line) if match pair = match[1].strip # Shouldn't capture the line number here, since it doesn't indicate the # line of the function definition but rather the line within the # function that led to the next frame. # pair << ' ' << /\[(".+?":[0-9]+)\]/.match(line)[1] pair << ' ' << /\["(.+?)"/.match(line)[1] memo << pair end memo end paraFuncs.uniq.each do |func| funcs[func] ||= 0 funcs[func] += 1 end end end funcs = funcs.to_a.sort_by { |func, cnt| -cnt } maxCntLen = funcs[0][1].to_s.size funcs.each { |func, cnt| puts "%*d %s" % [maxCntLen, cnt, func] }