Skip to content

Instantly share code, notes, and snippets.

@askldjd
Created January 11, 2017 18:44
Show Gist options
  • Save askldjd/4d105ddd341ee33e9a74a8111d175bf1 to your computer and use it in GitHub Desktop.
Save askldjd/4d105ddd341ee33e9a74a8111d175bf1 to your computer and use it in GitHub Desktop.
Look for a single generation of ruby heap and print out the allocation source.
require 'json'
class Analyzer
def initialize(filename)
@filename = filename
end
def analyze
data = []
File.open(@filename) do |f|
f.each_line do |line|
parsed=JSON.parse(line)
data << parsed if parsed["generation"] == ARGV[1].to_i
end
end
data.group_by{|row| "#{row["file"]}:#{row["line"]}"}
.sort{|a,b| b[1].count <=> a[1].count}
.each do |k,v|
puts "#{k} * #{v.count}"
end
end
end
Analyzer.new(ARGV[0]).analyze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment