Skip to content

Instantly share code, notes, and snippets.

@ntalbott
Created October 14, 2013 04:53
Show Gist options
  • Save ntalbott/6970938 to your computer and use it in GitHub Desktop.
Save ntalbott/6970938 to your computer and use it in GitHub Desktop.
A little script to take memory profiling output from rdbtool and do some key prefix totalling
#!/usr/bin/env ruby
hash = Hash.new{|h,k| h[k] = [0,0]}
aggregate_n = (ARGV[0] || 1).to_i
STDIN.each_line do |line|
parts = line.split(",")
key = parts[2][1..-2]
prefix = key.split(":")[0..(-1-aggregate_n)].join(":")
size = parts[3]
hash[prefix][0] += (size.to_i + key.size)
hash[prefix][1] += 1
end
hash.entries.sort_by{|k,(size,count)| size}.reverse.each do |k,(size,count)|
puts "#{k}: #{size} (#{count})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment